-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support import()
in rewriteImportExtensions
#16794
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* @minVersion 7.25.7 */ | ||
|
||
export default function replaceTsImportExt(source: string) { | ||
return /[\\/]/.test(source) | ||
? source.replace(/(\.[mc]?)ts$/, "$1js").replace(/\.tsx$/, ".js") | ||
: source; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could probably be shorter: return String(source).replace(/([\\/].*\.[mc]?)tsx?$/, "$1js"); and it becomes short enough that we could even just inline it in the code without a helper, so we don't have the problem of it not being available. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import("./a.ts"); | ||
import(a); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sourceType": "module", | ||
"presets": [["typescript", { "rewriteImportExtensions": true }]], | ||
"parserOpts": { | ||
"createImportExpressions": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import("./a.js"); | ||
import(babelHelpers.replaceTsImportExt(a)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, it is not sufficient to detect the bare import; consider
@foo/bar.ts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might need to be rewritten, if for example you are remapping
We added the exception for "it needs to have a slash" because:
.ts
So far nobody ever reported a problem with the
@foo/bar.ts
handling, but if there is a package out there needing it the only way forward is to provide a function option in the config once somebody needs it.