Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ export function transformModule(context: TransformationContext): (x: SourceFile
}

function visitImportCallExpression(node: ImportCall): Expression {
if (moduleKind === ModuleKind.None && languageVersion >= ScriptTarget.ES2020) {
return visitEachChild(node, visitor, context);
}
const externalModuleName = getExternalModuleNameLiteral(factory, node, currentSourceFile, host, resolver, compilerOptions);
const firstArgument = visitNode(firstOrUndefined(node.arguments), visitor);
// Only use the external module name if it differs from the first argument. This allows us to preserve the quote style of the argument on output.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/moduleNoneDynamicImport.ts] ////

//// [a.ts]
const foo = import("./b");

//// [b.js]
export default 1;


//// [a.js]
const foo = Promise.resolve().then(() => require("b"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== /a.ts ===
const foo = import("./b");
>foo : Symbol(foo, Decl(a.ts, 0, 5))
>"./b" : Symbol("/b", Decl(b.js, 0, 0))

=== /b.js ===

export default 1;

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== /a.ts ===
const foo = import("./b");
>foo : Promise<typeof import("/b")>
>import("./b") : Promise<typeof import("/b")>
>"./b" : "./b"

=== /b.js ===

export default 1;

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/moduleNoneDynamicImport.ts] ////

//// [a.ts]
const foo = import("./b");

//// [b.js]
export default 1;


//// [a.js]
const foo = import("./b");
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== /a.ts ===
const foo = import("./b");
>foo : Symbol(foo, Decl(a.ts, 0, 5))
>"./b" : Symbol("/b", Decl(b.js, 0, 0))

=== /b.js ===

export default 1;

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== /a.ts ===
const foo = import("./b");
>foo : Promise<typeof import("/b")>
>import("./b") : Promise<typeof import("/b")>
>"./b" : "./b"

=== /b.js ===

export default 1;

9 changes: 9 additions & 0 deletions tests/cases/compiler/moduleNoneDynamicImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @allowJs: true
// @target: es2015,es2020
// @module: none
// @outFile: /a.js
// @filename: /a.ts
const foo = import("./b");

// @filename: /b.js
export default 1;