mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
feat(48702): Emit for dynamic import (import()) when target >= ES2020 and module == None (#50942)
This commit is contained in:
parent
76c23e43da
commit
cdeb1e3660
@ -850,6 +850,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, isExpression);
|
||||
// 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.
|
||||
|
||||
@ -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"));
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
@ -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;
|
||||
|
||||
@ -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
tests/cases/compiler/moduleNoneDynamicImport.ts
Normal file
9
tests/cases/compiler/moduleNoneDynamicImport.ts
Normal file
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user