Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix: avoid downleveled dynamic import closing over specifier expressi…
…on (#49663) * fix: evaluate dynamic import specifier expressions synchronously * refactor * Update src/compiler/transformers/module/module.ts Co-authored-by: Ron Buckton <ron.buckton@microsoft.com> * [Experiment] Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
- Loading branch information
Showing
14 changed files
with
180 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//// [dynamicImportEvaluateSpecifier.ts] | ||
// https://github.com/microsoft/TypeScript/issues/48285 | ||
let i = 0; | ||
|
||
import(String(i++)); | ||
import(String(i++)); | ||
|
||
const getPath = async () => { | ||
/* in reality this would do some async FS operation, or a web request */ | ||
return "/root/my/cool/path"; | ||
}; | ||
|
||
const someFunction = async () => { | ||
const result = await import(await getPath()); | ||
}; | ||
|
||
|
||
//// [dynamicImportEvaluateSpecifier.js] | ||
var _a, _b; | ||
// https://github.com/microsoft/TypeScript/issues/48285 | ||
let i = 0; | ||
_a = String(i++), Promise.resolve().then(() => require(_a)); | ||
_b = String(i++), Promise.resolve().then(() => require(_b)); | ||
const getPath = async () => { | ||
/* in reality this would do some async FS operation, or a web request */ | ||
return "/root/my/cool/path"; | ||
}; | ||
const someFunction = async () => { | ||
var _a; | ||
const result = await (_a = await getPath(), Promise.resolve().then(() => require(_a))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
=== tests/cases/compiler/dynamicImportEvaluateSpecifier.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48285 | ||
let i = 0; | ||
>i : Symbol(i, Decl(dynamicImportEvaluateSpecifier.ts, 1, 3)) | ||
|
||
import(String(i++)); | ||
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 3 more) | ||
>i : Symbol(i, Decl(dynamicImportEvaluateSpecifier.ts, 1, 3)) | ||
|
||
import(String(i++)); | ||
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 3 more) | ||
>i : Symbol(i, Decl(dynamicImportEvaluateSpecifier.ts, 1, 3)) | ||
|
||
const getPath = async () => { | ||
>getPath : Symbol(getPath, Decl(dynamicImportEvaluateSpecifier.ts, 6, 5)) | ||
|
||
/* in reality this would do some async FS operation, or a web request */ | ||
return "/root/my/cool/path"; | ||
}; | ||
|
||
const someFunction = async () => { | ||
>someFunction : Symbol(someFunction, Decl(dynamicImportEvaluateSpecifier.ts, 11, 5)) | ||
|
||
const result = await import(await getPath()); | ||
>result : Symbol(result, Decl(dynamicImportEvaluateSpecifier.ts, 12, 6)) | ||
>getPath : Symbol(getPath, Decl(dynamicImportEvaluateSpecifier.ts, 6, 5)) | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
=== tests/cases/compiler/dynamicImportEvaluateSpecifier.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48285 | ||
let i = 0; | ||
>i : number | ||
>0 : 0 | ||
|
||
import(String(i++)); | ||
>import(String(i++)) : Promise<any> | ||
>String(i++) : string | ||
>String : StringConstructor | ||
>i++ : number | ||
>i : number | ||
|
||
import(String(i++)); | ||
>import(String(i++)) : Promise<any> | ||
>String(i++) : string | ||
>String : StringConstructor | ||
>i++ : number | ||
>i : number | ||
|
||
const getPath = async () => { | ||
>getPath : () => Promise<string> | ||
>async () => { /* in reality this would do some async FS operation, or a web request */ return "/root/my/cool/path";} : () => Promise<string> | ||
|
||
/* in reality this would do some async FS operation, or a web request */ | ||
return "/root/my/cool/path"; | ||
>"/root/my/cool/path" : "/root/my/cool/path" | ||
|
||
}; | ||
|
||
const someFunction = async () => { | ||
>someFunction : () => Promise<void> | ||
>async () => { const result = await import(await getPath());} : () => Promise<void> | ||
|
||
const result = await import(await getPath()); | ||
>result : any | ||
>await import(await getPath()) : any | ||
>import(await getPath()) : Promise<any> | ||
>await getPath() : string | ||
>getPath() : Promise<string> | ||
>getPath : () => Promise<string> | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @lib: es2019 | ||
// @target: es2019 | ||
// @module: commonjs | ||
// https://github.com/microsoft/TypeScript/issues/48285 | ||
let i = 0; | ||
|
||
import(String(i++)); | ||
import(String(i++)); | ||
|
||
const getPath = async () => { | ||
/* in reality this would do some async FS operation, or a web request */ | ||
return "/root/my/cool/path"; | ||
}; | ||
|
||
const someFunction = async () => { | ||
const result = await import(await getPath()); | ||
}; |