Skip to content

Commit 70d8ec2

Browse files
authored
Fix name generation scoping (#58418)
1 parent e154d47 commit 70d8ec2

11 files changed

+178
-153
lines changed

src/compiler/emitter.ts

Lines changed: 103 additions & 103 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/evaluation/asyncArrow.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,29 @@ describe("unittests:: evaluation:: asyncArrowEvaluation", () => {
1717
await result.main();
1818
assert.instanceOf(result.output[0].a(), result.A);
1919
});
20+
21+
// https://github.com/microsoft/TypeScript/issues/57897
22+
it("Class alias (es5)", async () => {
23+
const result = evaluator.evaluateTypeScript(`
24+
class X {
25+
public static a = async (someVar: boolean = true) => {
26+
return await X.b();
27+
};
28+
29+
public static b = async () => {
30+
return "GOOD";
31+
};
32+
}
33+
34+
export async function main() {
35+
try {
36+
return await X.a();
37+
}
38+
catch (e) {
39+
return "BAD";
40+
}
41+
}`);
42+
const output = await result.main();
43+
assert.equal(output, "GOOD");
44+
});
2045
});

tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ function f12() { return (...args_1) => {
7979
function f() {
8080
const a1 = (x_1, ...args_1) => __awaiter(this, [x_1, ...args_1], void 0, function* (x, y = z) { });
8181
const a2 = (_a) => __awaiter(this, [_a], void 0, function* ({ [z]: x }) { });
82-
const a3 = (...args_2) => {
82+
const a3 = (...args_1) => {
8383
var arguments_10 = arguments;
84-
return __awaiter(this, [...args_2], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); });
84+
return __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); });
8585
};
86-
const a4 = (...args_2) => __awaiter(this, [...args_2], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
87-
const a5 = (...args_3) => __awaiter(this, [...args_3], void 0, function* (x = z, ...args) { });
88-
const a6 = (...args_4) => __awaiter(this, [...args_4], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); });
89-
const a7 = (...args_5) => __awaiter(this, [...args_5], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
90-
const a8 = () => __awaiter(this, void 0, void 0, function* () { return (...args_6) => __awaiter(this, [...args_6], void 0, function* (x = z) { return arguments_10; }); });
91-
const a9 = () => __awaiter(this, void 0, void 0, function* () { return (...args_7) => __awaiter(this, [...args_7], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
92-
const a10 = (...args_8) => __awaiter(this, [...args_8], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return function () {
86+
const a4 = (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
87+
const a5 = (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z, ...args) { });
88+
const a6 = (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); });
89+
const a7 = (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
90+
const a8 = () => __awaiter(this, void 0, void 0, function* () { return (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return arguments_10; }); });
91+
const a9 = () => __awaiter(this, void 0, void 0, function* () { return (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); });
92+
const a10 = (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return function () {
9393
var arguments_11 = arguments;
9494
return __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_11; }); });
9595
}; }); });

tests/baselines/reference/autoAccessor5(target=es2022).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class C1 {
3030
static set ["z"](value) { C1.#_d_accessor_storage = value; }
3131
}
3232
class C2 {
33-
#_e_accessor_storage = 1;
34-
get [_a = f()]() { return this.#_e_accessor_storage; }
35-
set [_a](value) { this.#_e_accessor_storage = value; }
33+
#_a_accessor_storage = 1;
34+
get [_a = f()]() { return this.#_a_accessor_storage; }
35+
set [_a](value) { this.#_a_accessor_storage = value; }
3636
}

tests/baselines/reference/esDecorators-classDeclaration-commentPreservation(module=commonjs,target=es2022).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ let C = (() => {
189189
set x(value) { }
190190
/*13*/
191191
y = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _y_initializers, 1));
192-
#z_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
192+
#z_1_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
193193
/*16*/
194-
get z() { return this.#z_accessor_storage; }
195-
set z(value) { this.#z_accessor_storage = value; }
194+
get z() { return this.#z_1_accessor_storage; }
195+
set z(value) { this.#z_1_accessor_storage = value; }
196196
static {
197197
/*28*/
198198
_C_y = { value: (__runInitializers(_classThis, _staticExtraInitializers), __runInitializers(_classThis, _static_private_y_initializers, 1)) };

tests/baselines/reference/esDecorators-classDeclaration-commentPreservation(module=esnext,target=es2022).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ let C = (() => {
189189
set x(value) { }
190190
/*13*/
191191
y = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _y_initializers, 1));
192-
#z_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
192+
#z_1_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
193193
/*16*/
194-
get z() { return this.#z_accessor_storage; }
195-
set z(value) { this.#z_accessor_storage = value; }
194+
get z() { return this.#z_1_accessor_storage; }
195+
set z(value) { this.#z_1_accessor_storage = value; }
196196
static {
197197
/*28*/
198198
_C_y = { value: (__runInitializers(_classThis, _staticExtraInitializers), __runInitializers(_classThis, _static_private_y_initializers, 1)) };

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/esDecorators-classDeclaration-sourceMap(target=es2022).sourcemap.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ sourceFile:esDecorators-classDeclaration-sourceMap.ts
707707
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
708708
6 > ^
709709
7 > ^^^
710-
8 > ^^^^^^^^^^^^^->
710+
8 > ^^^^^^^^^^^^^^^->
711711
1->
712712
>
713713
> @dec
@@ -742,52 +742,52 @@ sourceFile:esDecorators-classDeclaration-sourceMap.ts
742742
6 >Emitted(117, 109) Source(20, 10) + SourceIndex(0)
743743
7 >Emitted(117, 112) Source(20, 11) + SourceIndex(0)
744744
---
745-
>>> #z_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
745+
>>> #z_1_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
746746
1->^^^^^^^^
747-
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
748-
3 > ^
749-
4 > ^^^
747+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
748+
3 > ^
749+
4 > ^^^
750750
1->
751751
>
752752
> @dec
753753
> @dec
754754
>
755755
2 > accessor z =
756-
3 > 1
757-
4 > ;
756+
3 > 1
757+
4 > ;
758758
1->Emitted(118, 9) Source(24, 5) + SourceIndex(0)
759-
2 >Emitted(118, 120) Source(24, 18) + SourceIndex(0)
760-
3 >Emitted(118, 121) Source(24, 19) + SourceIndex(0)
761-
4 >Emitted(118, 124) Source(24, 20) + SourceIndex(0)
759+
2 >Emitted(118, 122) Source(24, 18) + SourceIndex(0)
760+
3 >Emitted(118, 123) Source(24, 19) + SourceIndex(0)
761+
4 >Emitted(118, 126) Source(24, 20) + SourceIndex(0)
762762
---
763-
>>> get z() { return this.#z_accessor_storage; }
763+
>>> get z() { return this.#z_1_accessor_storage; }
764764
1 >^^^^^^^^
765765
2 > ^^^^
766766
3 > ^
767-
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
768-
5 > ^^^^^^^->
767+
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
768+
5 > ^^^^^^^->
769769
1 >
770770
2 > accessor
771771
3 > z
772772
4 > = 1;
773773
1 >Emitted(119, 9) Source(24, 5) + SourceIndex(0)
774774
2 >Emitted(119, 13) Source(24, 14) + SourceIndex(0)
775775
3 >Emitted(119, 14) Source(24, 15) + SourceIndex(0)
776-
4 >Emitted(119, 53) Source(24, 20) + SourceIndex(0)
776+
4 >Emitted(119, 55) Source(24, 20) + SourceIndex(0)
777777
---
778-
>>> set z(value) { this.#z_accessor_storage = value; }
778+
>>> set z(value) { this.#z_1_accessor_storage = value; }
779779
1->^^^^^^^^
780780
2 > ^^^^
781781
3 > ^
782-
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
782+
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
783783
1->
784784
2 > accessor
785785
3 > z
786786
4 > = 1;
787787
1->Emitted(120, 9) Source(24, 5) + SourceIndex(0)
788788
2 >Emitted(120, 13) Source(24, 14) + SourceIndex(0)
789789
3 >Emitted(120, 14) Source(24, 15) + SourceIndex(0)
790-
4 >Emitted(120, 59) Source(24, 20) + SourceIndex(0)
790+
4 >Emitted(120, 61) Source(24, 20) + SourceIndex(0)
791791
---
792792
>>> static {
793793
>>> _C_y = { value: (__runInitializers(_classThis, _staticExtraInitializers), __runInitializers(_classThis, _static_private_y_initializers, 1)) };

tests/baselines/reference/esDecorators-classExpression-commentPreservation(target=es2022).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ class C {
154154
set x(value) { }
155155
/*14*/
156156
y = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _y_initializers, 1));
157-
#z_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
157+
#z_1_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _z_initializers, 1));
158158
/*17*/
159-
get z() { return this.#z_accessor_storage; }
160-
set z(value) { this.#z_accessor_storage = value; }
159+
get z() { return this.#z_1_accessor_storage; }
160+
set z(value) { this.#z_1_accessor_storage = value; }
161161
static {
162162
/*29*/
163163
_C_y = { value: (__runInitializers(_classThis, _staticExtraInitializers), __runInitializers(_classThis, _static_private_y_initializers, 1)) };

tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ class A {
4545
var _c;
4646
this.otherClass = _b;
4747
let y;
48-
({ x: ({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value, y } = this.testObject());
49-
([({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value, y] = this.testArray());
50-
({ a: ({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value, b: [({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value] } = { a: 1, b: [2] });
51-
[({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value, [({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value]] = [1, [2]];
52-
({ a: ({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value = 1, b: [({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value = 1] } = { b: [] });
53-
[({ set value(_b) { __classPrivateFieldSet(_b, _b, _b, "f", _A_field); } }).value = 2] = [];
54-
_c = this.otherClass, [({ set value(_b) { __classPrivateFieldSet(_c, _b, _b, "f", _A_field); } }).value = 2] = [];
48+
({ x: ({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value, y } = this.testObject());
49+
([({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value, y] = this.testArray());
50+
({ a: ({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value, b: [({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value] } = { a: 1, b: [2] });
51+
[({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value, [({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value]] = [1, [2]];
52+
({ a: ({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value = 1, b: [({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value = 1] } = { b: [] });
53+
[({ set value(_d) { __classPrivateFieldSet(_b, _b, _d, "f", _A_field); } }).value = 2] = [];
54+
_c = this.otherClass, [({ set value(_d) { __classPrivateFieldSet(_c, _b, _d, "f", _A_field); } }).value = 2] = [];
5555
}
5656
static test(_a) {
5757
[({ set value(_c) { __classPrivateFieldSet(_a, _b, _c, "f", _A_field); } }).value] = [2];

0 commit comments

Comments
 (0)