Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Rewrite relative import extensions with flag#59767
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
24395772b06e62a398ad1921f9aeac8a2fa6e62350c8ba95dfce0a2d1558c7f0d95ce2b88dddc486700162dab48d87beef3a5237084fa9ff32b3be0094c03cb1974e0a125bfd5a1d78555066555548868b43ea23d7b7e624f01fc135c64384c9557cd2a78419f677d1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,6 +23,7 @@ import { | ||
| isCallExpression, | ||
| isComputedPropertyName, | ||
| isIdentifier, | ||
| JsxEmit, | ||
| memoize, | ||
| ObjectLiteralElementLike, | ||
| ParameterDeclaration, | ||
| @@ -139,6 +140,8 @@ export interface EmitHelperFactory { | ||
| // 'using' helpers | ||
| createAddDisposableResourceHelper(envBinding: Expression, value: Expression, async: boolean): Expression; | ||
| createDisposeResourcesHelper(envBinding: Expression): Expression; | ||
| // --rewriteRelativeImportExtensions helpers | ||
| createRewriteRelativeImportExtensionsHelper(expression: Expression): Expression; | ||
| } | ||
| /** @internal */ | ||
| @@ -189,6 +192,8 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel | ||
| // 'using' helpers | ||
| createAddDisposableResourceHelper, | ||
| createDisposeResourcesHelper, | ||
| // --rewriteRelativeImportExtensions helpers | ||
| createRewriteRelativeImportExtensionsHelper, | ||
| }; | ||
| /** | ||
| @@ -682,6 +687,17 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel | ||
| context.requestEmitHelper(disposeResourcesHelper); | ||
| return factory.createCallExpression(getUnscopedHelperName("__disposeResources"), /*typeArguments*/ undefined, [envBinding]); | ||
| } | ||
| function createRewriteRelativeImportExtensionsHelper(expression: Expression) { | ||
| context.requestEmitHelper(rewriteRelativeImportExtensionsHelper); | ||
| return factory.createCallExpression( | ||
| getUnscopedHelperName("__rewriteRelativeImportExtension"), | ||
| /*typeArguments*/ undefined, | ||
| context.getCompilerOptions().jsx === JsxEmit.Preserve | ||
| ? [expression, factory.createTrue()] | ||
| : [expression], | ||
| ); | ||
| } | ||
| } | ||
| /** @internal */ | ||
| @@ -1422,6 +1438,21 @@ const disposeResourcesHelper: UnscopedEmitHelper = { | ||
| });`, | ||
| }; | ||
| const rewriteRelativeImportExtensionsHelper: UnscopedEmitHelper = { | ||
| name: "typescript:rewriteRelativeImportExtensions", | ||
| importName: "__rewriteRelativeImportExtension", | ||
| scoped: false, | ||
| text: ` | ||
| var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { | ||
| if (typeof path === "string" && /^\\.\\.?\\//.test(path)) { | ||
| return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { | ||
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. If a path contains Should the regex be This now works: console.log(rewriteRelativeImportExtension("./main.tsx"));console.log(rewriteRelativeImportExtension("./main.ts"));console.log(rewriteRelativeImportExtension("./main.jsx"));console.log(rewriteRelativeImportExtension("./main.jsx",true));console.log(rewriteRelativeImportExtension("./main.js"));MemberAuthor 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. Can you clarify your actual behavior and expected behavior? 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. Nevermind, I'm writing a plugin that is based on | ||
| return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); | ||
| }); | ||
| } | ||
| return path; | ||
| };`, | ||
| }; | ||
| /** @internal */ | ||
| export const asyncSuperHelper: EmitHelper = { | ||
| name: "typescript:async-super", | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.