Skip to content

Commit 8fa1d2e

Browse files
authored
Merge pull request #17141 from Microsoft/master-17060
Fix 17060 : incorrect emit for dynamic import inside elements of export class declaration
2 parents 7cb8ce4 + 605bd1c commit 8fa1d2e

File tree

79 files changed

+2184
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2184
-73
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ namespace ts {
924924
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
925925
/*typeParameters*/ undefined,
926926
visitNodes(node.heritageClauses, importCallExpressionVisitor),
927-
node.members
927+
visitNodes(node.members, importCallExpressionVisitor)
928928
),
929929
node
930930
),

tests/baselines/reference/importCallExpression1ESNext.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ p1.then(zero => {
1010
return zero.foo();
1111
})
1212

13+
export var p2 = import("./0");
14+
1315
function foo() {
1416
const p2 = import("./0");
1517
}
@@ -22,6 +24,7 @@ var p1 = import("./0");
2224
p1.then(zero => {
2325
return zero.foo();
2426
});
27+
export var p2 = import("./0");
2528
function foo() {
2629
const p2 = import("./0");
2730
}

tests/baselines/reference/importCallExpression1ESNext.symbols

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ p1.then(zero => {
2323

2424
})
2525

26+
export var p2 = import("./0");
27+
>p2 : Symbol(p2, Decl(1.ts, 6, 10))
28+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
29+
2630
function foo() {
27-
>foo : Symbol(foo, Decl(1.ts, 4, 2))
31+
>foo : Symbol(foo, Decl(1.ts, 6, 30))
2832

2933
const p2 = import("./0");
30-
>p2 : Symbol(p2, Decl(1.ts, 7, 9))
34+
>p2 : Symbol(p2, Decl(1.ts, 9, 9))
3135
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
3236
}

tests/baselines/reference/importCallExpression1ESNext.types

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ p1.then(zero => {
2929

3030
})
3131

32+
export var p2 = import("./0");
33+
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
34+
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
35+
>"./0" : "./0"
36+
3237
function foo() {
3338
>foo : () => void
3439

tests/baselines/reference/importCallExpression4ESNext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare var console: any;
1515
class C {
1616
private myModule = import("./0");
1717
method() {
18+
const loadAsync = import ("./0");
1819
this.myModule.then(Zero => {
1920
console.log(Zero.foo());
2021
}, async err => {
@@ -38,6 +39,7 @@ class C {
3839
this.myModule = import("./0");
3940
}
4041
method() {
42+
const loadAsync = import("./0");
4143
this.myModule.then(Zero => {
4244
console.log(Zero.foo());
4345
}, async (err) => {

tests/baselines/reference/importCallExpression4ESNext.symbols

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,39 @@ class C {
2727
method() {
2828
>method : Symbol(C.method, Decl(2.ts, 2, 37))
2929

30+
const loadAsync = import ("./0");
31+
>loadAsync : Symbol(loadAsync, Decl(2.ts, 4, 13))
32+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
33+
3034
this.myModule.then(Zero => {
3135
>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
3236
>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9))
3337
>this : Symbol(C, Decl(2.ts, 0, 25))
3438
>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9))
3539
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
36-
>Zero : Symbol(Zero, Decl(2.ts, 4, 27))
40+
>Zero : Symbol(Zero, Decl(2.ts, 5, 27))
3741

3842
console.log(Zero.foo());
3943
>console : Symbol(console, Decl(2.ts, 0, 11))
4044
>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1))
41-
>Zero : Symbol(Zero, Decl(2.ts, 4, 27))
45+
>Zero : Symbol(Zero, Decl(2.ts, 5, 27))
4246
>foo : Symbol(foo, Decl(0.ts, 2, 1))
4347

4448
}, async err => {
45-
>err : Symbol(err, Decl(2.ts, 6, 16))
49+
>err : Symbol(err, Decl(2.ts, 7, 16))
4650

4751
console.log(err);
4852
>console : Symbol(console, Decl(2.ts, 0, 11))
49-
>err : Symbol(err, Decl(2.ts, 6, 16))
53+
>err : Symbol(err, Decl(2.ts, 7, 16))
5054

5155
let one = await import("./1");
52-
>one : Symbol(one, Decl(2.ts, 8, 15))
56+
>one : Symbol(one, Decl(2.ts, 9, 15))
5357
>"./1" : Symbol("tests/cases/conformance/dynamicImport/1", Decl(1.ts, 0, 0))
5458

5559
console.log(one.backup());
5660
>console : Symbol(console, Decl(2.ts, 0, 11))
5761
>one.backup : Symbol(backup, Decl(1.ts, 0, 0))
58-
>one : Symbol(one, Decl(2.ts, 8, 15))
62+
>one : Symbol(one, Decl(2.ts, 9, 15))
5963
>backup : Symbol(backup, Decl(1.ts, 0, 0))
6064

6165
});

tests/baselines/reference/importCallExpression4ESNext.types

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class C {
3131
method() {
3232
>method : () => void
3333

34+
const loadAsync = import ("./0");
35+
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
36+
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
37+
>"./0" : "./0"
38+
3439
this.myModule.then(Zero => {
3540
>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise<void>
3641
>this.myModule.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>

tests/baselines/reference/importCallExpressionES5AMD.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@ p1.then(zero => {
1010
return zero.foo();
1111
});
1212

13+
export var p2 = import("./0");
14+
1315
function foo() {
1416
const p2 = import("./0");
17+
}
18+
19+
class C {
20+
method() {
21+
const loadAsync = import ("./0");
22+
}
23+
}
24+
25+
export class D {
26+
method() {
27+
const loadAsync = import ("./0");
28+
}
1529
}
1630

1731
//// [0.js]
@@ -24,12 +38,31 @@ define(["require", "exports"], function (require, exports) {
2438
//// [1.js]
2539
define(["require", "exports"], function (require, exports) {
2640
"use strict";
41+
Object.defineProperty(exports, "__esModule", { value: true });
2742
new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); });
2843
var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); });
2944
p1.then(function (zero) {
3045
return zero.foo();
3146
});
47+
exports.p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); });
3248
function foo() {
33-
var p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); });
49+
var p2 = new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); });
3450
}
51+
var C = (function () {
52+
function C() {
53+
}
54+
C.prototype.method = function () {
55+
var loadAsync = new Promise(function (resolve_5, reject_5) { require(["./0"], resolve_5, reject_5); });
56+
};
57+
return C;
58+
}());
59+
var D = (function () {
60+
function D() {
61+
}
62+
D.prototype.method = function () {
63+
var loadAsync = new Promise(function (resolve_6, reject_6) { require(["./0"], resolve_6, reject_6); });
64+
};
65+
return D;
66+
}());
67+
exports.D = D;
3568
});

tests/baselines/reference/importCallExpressionES5AMD.symbols

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,38 @@ p1.then(zero => {
2323

2424
});
2525

26+
export var p2 = import("./0");
27+
>p2 : Symbol(p2, Decl(1.ts, 6, 10))
28+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
29+
2630
function foo() {
27-
>foo : Symbol(foo, Decl(1.ts, 4, 3))
31+
>foo : Symbol(foo, Decl(1.ts, 6, 30))
2832

2933
const p2 = import("./0");
30-
>p2 : Symbol(p2, Decl(1.ts, 7, 9))
34+
>p2 : Symbol(p2, Decl(1.ts, 9, 9))
35+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
36+
}
37+
38+
class C {
39+
>C : Symbol(C, Decl(1.ts, 10, 1))
40+
41+
method() {
42+
>method : Symbol(C.method, Decl(1.ts, 12, 9))
43+
44+
const loadAsync = import ("./0");
45+
>loadAsync : Symbol(loadAsync, Decl(1.ts, 14, 13))
46+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
47+
}
48+
}
49+
50+
export class D {
51+
>D : Symbol(D, Decl(1.ts, 16, 1))
52+
53+
method() {
54+
>method : Symbol(D.method, Decl(1.ts, 18, 16))
55+
56+
const loadAsync = import ("./0");
57+
>loadAsync : Symbol(loadAsync, Decl(1.ts, 20, 13))
3158
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
59+
}
3260
}

tests/baselines/reference/importCallExpressionES5AMD.types

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ p1.then(zero => {
2929

3030
});
3131

32+
export var p2 = import("./0");
33+
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
34+
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
35+
>"./0" : "./0"
36+
3237
function foo() {
3338
>foo : () => void
3439

@@ -37,3 +42,29 @@ function foo() {
3742
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
3843
>"./0" : "./0"
3944
}
45+
46+
class C {
47+
>C : C
48+
49+
method() {
50+
>method : () => void
51+
52+
const loadAsync = import ("./0");
53+
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
54+
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
55+
>"./0" : "./0"
56+
}
57+
}
58+
59+
export class D {
60+
>D : D
61+
62+
method() {
63+
>method : () => void
64+
65+
const loadAsync = import ("./0");
66+
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
67+
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
68+
>"./0" : "./0"
69+
}
70+
}

tests/baselines/reference/importCallExpressionES5CJS.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@ p1.then(zero => {
1010
return zero.foo();
1111
});
1212

13+
export var p2 = import("./0");
14+
1315
function foo() {
1416
const p2 = import("./0");
17+
}
18+
19+
class C {
20+
method() {
21+
const loadAsync = import ("./0");
22+
}
23+
}
24+
25+
export class D {
26+
method() {
27+
const loadAsync = import ("./0");
28+
}
1529
}
1630

1731
//// [0.js]
@@ -20,11 +34,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
2034
function foo() { return "foo"; }
2135
exports.foo = foo;
2236
//// [1.js]
37+
"use strict";
38+
Object.defineProperty(exports, "__esModule", { value: true });
2339
Promise.resolve().then(function () { return require("./0"); });
2440
var p1 = Promise.resolve().then(function () { return require("./0"); });
2541
p1.then(function (zero) {
2642
return zero.foo();
2743
});
44+
exports.p2 = Promise.resolve().then(function () { return require("./0"); });
2845
function foo() {
2946
var p2 = Promise.resolve().then(function () { return require("./0"); });
3047
}
48+
var C = (function () {
49+
function C() {
50+
}
51+
C.prototype.method = function () {
52+
var loadAsync = Promise.resolve().then(function () { return require("./0"); });
53+
};
54+
return C;
55+
}());
56+
var D = (function () {
57+
function D() {
58+
}
59+
D.prototype.method = function () {
60+
var loadAsync = Promise.resolve().then(function () { return require("./0"); });
61+
};
62+
return D;
63+
}());
64+
exports.D = D;

tests/baselines/reference/importCallExpressionES5CJS.symbols

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,38 @@ p1.then(zero => {
2323

2424
});
2525

26+
export var p2 = import("./0");
27+
>p2 : Symbol(p2, Decl(1.ts, 6, 10))
28+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
29+
2630
function foo() {
27-
>foo : Symbol(foo, Decl(1.ts, 4, 3))
31+
>foo : Symbol(foo, Decl(1.ts, 6, 30))
2832

2933
const p2 = import("./0");
30-
>p2 : Symbol(p2, Decl(1.ts, 7, 9))
34+
>p2 : Symbol(p2, Decl(1.ts, 9, 9))
35+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
36+
}
37+
38+
class C {
39+
>C : Symbol(C, Decl(1.ts, 10, 1))
40+
41+
method() {
42+
>method : Symbol(C.method, Decl(1.ts, 12, 9))
43+
44+
const loadAsync = import ("./0");
45+
>loadAsync : Symbol(loadAsync, Decl(1.ts, 14, 13))
46+
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
47+
}
48+
}
49+
50+
export class D {
51+
>D : Symbol(D, Decl(1.ts, 16, 1))
52+
53+
method() {
54+
>method : Symbol(D.method, Decl(1.ts, 18, 16))
55+
56+
const loadAsync = import ("./0");
57+
>loadAsync : Symbol(loadAsync, Decl(1.ts, 20, 13))
3158
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
59+
}
3260
}

0 commit comments

Comments
 (0)