Skip to content

Commit caebbe6

Browse files
authored
Dont check computed name visibility results when the computed name representation is not in use (#41806)
1 parent 5cdb2e8 commit caebbe6

8 files changed

+300
-7
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4996,7 +4996,7 @@ namespace ts {
49964996
anyType : getTypeOfSymbol(propertySymbol);
49974997
const saveEnclosingDeclaration = context.enclosingDeclaration;
49984998
context.enclosingDeclaration = undefined;
4999-
if (context.tracker.trackSymbol && getCheckFlags(propertySymbol) & CheckFlags.Late) {
4999+
if (context.tracker.trackSymbol && getCheckFlags(propertySymbol) & CheckFlags.Late && isLateBoundName(propertySymbol.escapedName)) {
50005000
const decl = first(propertySymbol.declarations);
50015001
if (hasLateBindableName(decl)) {
50025002
if (isBinaryExpression(decl)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//// [tests/cases/compiler/declarationEmitStringEnumUsedInNonlocalSpread.ts] ////
2+
3+
//// [class.ts]
4+
export const enum TestEnum {
5+
Test1 = '123123',
6+
Test2 = '12312312312',
7+
}
8+
9+
export interface ITest {
10+
[TestEnum.Test1]: string;
11+
[TestEnum.Test2]: string;
12+
}
13+
14+
export class A {
15+
getA(): ITest {
16+
return {
17+
[TestEnum.Test1]: '123',
18+
[TestEnum.Test2]: '123',
19+
};
20+
}
21+
}
22+
//// [index.ts]
23+
import { A } from './class';
24+
25+
export class B extends A {
26+
getA() { // TS4053 error
27+
return {
28+
...super.getA(),
29+
a: '123',
30+
};
31+
}
32+
}
33+
34+
//// [class.js]
35+
"use strict";
36+
exports.__esModule = true;
37+
exports.A = void 0;
38+
var A = /** @class */ (function () {
39+
function A() {
40+
}
41+
A.prototype.getA = function () {
42+
var _a;
43+
return _a = {},
44+
_a["123123" /* Test1 */] = '123',
45+
_a["12312312312" /* Test2 */] = '123',
46+
_a;
47+
};
48+
return A;
49+
}());
50+
exports.A = A;
51+
//// [index.js]
52+
"use strict";
53+
var __extends = (this && this.__extends) || (function () {
54+
var extendStatics = function (d, b) {
55+
extendStatics = Object.setPrototypeOf ||
56+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
57+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
58+
return extendStatics(d, b);
59+
};
60+
return function (d, b) {
61+
if (typeof b !== "function" && b !== null)
62+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
63+
extendStatics(d, b);
64+
function __() { this.constructor = d; }
65+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
66+
};
67+
})();
68+
var __assign = (this && this.__assign) || function () {
69+
__assign = Object.assign || function(t) {
70+
for (var s, i = 1, n = arguments.length; i < n; i++) {
71+
s = arguments[i];
72+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
73+
t[p] = s[p];
74+
}
75+
return t;
76+
};
77+
return __assign.apply(this, arguments);
78+
};
79+
exports.__esModule = true;
80+
exports.B = void 0;
81+
var class_1 = require("./class");
82+
var B = /** @class */ (function (_super) {
83+
__extends(B, _super);
84+
function B() {
85+
return _super !== null && _super.apply(this, arguments) || this;
86+
}
87+
B.prototype.getA = function () {
88+
return __assign(__assign({}, _super.prototype.getA.call(this)), { a: '123' });
89+
};
90+
return B;
91+
}(class_1.A));
92+
exports.B = B;
93+
94+
95+
//// [class.d.ts]
96+
export declare const enum TestEnum {
97+
Test1 = "123123",
98+
Test2 = "12312312312"
99+
}
100+
export interface ITest {
101+
[TestEnum.Test1]: string;
102+
[TestEnum.Test2]: string;
103+
}
104+
export declare class A {
105+
getA(): ITest;
106+
}
107+
//// [index.d.ts]
108+
import { A } from './class';
109+
export declare class B extends A {
110+
getA(): {
111+
a: string;
112+
123123: string;
113+
12312312312: string;
114+
};
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
=== tests/cases/compiler/class.ts ===
2+
export const enum TestEnum {
3+
>TestEnum : Symbol(TestEnum, Decl(class.ts, 0, 0))
4+
5+
Test1 = '123123',
6+
>Test1 : Symbol(TestEnum.Test1, Decl(class.ts, 0, 28))
7+
8+
Test2 = '12312312312',
9+
>Test2 : Symbol(TestEnum.Test2, Decl(class.ts, 1, 21))
10+
}
11+
12+
export interface ITest {
13+
>ITest : Symbol(ITest, Decl(class.ts, 3, 1))
14+
15+
[TestEnum.Test1]: string;
16+
>[TestEnum.Test1] : Symbol(ITest[TestEnum.Test1], Decl(class.ts, 5, 24))
17+
>TestEnum.Test1 : Symbol(TestEnum.Test1, Decl(class.ts, 0, 28))
18+
>TestEnum : Symbol(TestEnum, Decl(class.ts, 0, 0))
19+
>Test1 : Symbol(TestEnum.Test1, Decl(class.ts, 0, 28))
20+
21+
[TestEnum.Test2]: string;
22+
>[TestEnum.Test2] : Symbol(ITest[TestEnum.Test2], Decl(class.ts, 6, 29))
23+
>TestEnum.Test2 : Symbol(TestEnum.Test2, Decl(class.ts, 1, 21))
24+
>TestEnum : Symbol(TestEnum, Decl(class.ts, 0, 0))
25+
>Test2 : Symbol(TestEnum.Test2, Decl(class.ts, 1, 21))
26+
}
27+
28+
export class A {
29+
>A : Symbol(A, Decl(class.ts, 8, 1))
30+
31+
getA(): ITest {
32+
>getA : Symbol(A.getA, Decl(class.ts, 10, 16))
33+
>ITest : Symbol(ITest, Decl(class.ts, 3, 1))
34+
35+
return {
36+
[TestEnum.Test1]: '123',
37+
>[TestEnum.Test1] : Symbol([TestEnum.Test1], Decl(class.ts, 12, 16))
38+
>TestEnum.Test1 : Symbol(TestEnum.Test1, Decl(class.ts, 0, 28))
39+
>TestEnum : Symbol(TestEnum, Decl(class.ts, 0, 0))
40+
>Test1 : Symbol(TestEnum.Test1, Decl(class.ts, 0, 28))
41+
42+
[TestEnum.Test2]: '123',
43+
>[TestEnum.Test2] : Symbol([TestEnum.Test2], Decl(class.ts, 13, 36))
44+
>TestEnum.Test2 : Symbol(TestEnum.Test2, Decl(class.ts, 1, 21))
45+
>TestEnum : Symbol(TestEnum, Decl(class.ts, 0, 0))
46+
>Test2 : Symbol(TestEnum.Test2, Decl(class.ts, 1, 21))
47+
48+
};
49+
}
50+
}
51+
=== tests/cases/compiler/index.ts ===
52+
import { A } from './class';
53+
>A : Symbol(A, Decl(index.ts, 0, 8))
54+
55+
export class B extends A {
56+
>B : Symbol(B, Decl(index.ts, 0, 28))
57+
>A : Symbol(A, Decl(index.ts, 0, 8))
58+
59+
getA() { // TS4053 error
60+
>getA : Symbol(B.getA, Decl(index.ts, 2, 26))
61+
62+
return {
63+
...super.getA(),
64+
>super.getA : Symbol(A.getA, Decl(class.ts, 10, 16))
65+
>super : Symbol(A, Decl(class.ts, 8, 1))
66+
>getA : Symbol(A.getA, Decl(class.ts, 10, 16))
67+
68+
a: '123',
69+
>a : Symbol(a, Decl(index.ts, 5, 28))
70+
71+
};
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=== tests/cases/compiler/class.ts ===
2+
export const enum TestEnum {
3+
>TestEnum : TestEnum
4+
5+
Test1 = '123123',
6+
>Test1 : TestEnum.Test1
7+
>'123123' : "123123"
8+
9+
Test2 = '12312312312',
10+
>Test2 : TestEnum.Test2
11+
>'12312312312' : "12312312312"
12+
}
13+
14+
export interface ITest {
15+
[TestEnum.Test1]: string;
16+
>[TestEnum.Test1] : string
17+
>TestEnum.Test1 : TestEnum.Test1
18+
>TestEnum : typeof TestEnum
19+
>Test1 : TestEnum.Test1
20+
21+
[TestEnum.Test2]: string;
22+
>[TestEnum.Test2] : string
23+
>TestEnum.Test2 : TestEnum.Test2
24+
>TestEnum : typeof TestEnum
25+
>Test2 : TestEnum.Test2
26+
}
27+
28+
export class A {
29+
>A : A
30+
31+
getA(): ITest {
32+
>getA : () => ITest
33+
34+
return {
35+
>{ [TestEnum.Test1]: '123', [TestEnum.Test2]: '123', } : { 123123: string; 12312312312: string; }
36+
37+
[TestEnum.Test1]: '123',
38+
>[TestEnum.Test1] : string
39+
>TestEnum.Test1 : TestEnum.Test1
40+
>TestEnum : typeof TestEnum
41+
>Test1 : TestEnum.Test1
42+
>'123' : "123"
43+
44+
[TestEnum.Test2]: '123',
45+
>[TestEnum.Test2] : string
46+
>TestEnum.Test2 : TestEnum.Test2
47+
>TestEnum : typeof TestEnum
48+
>Test2 : TestEnum.Test2
49+
>'123' : "123"
50+
51+
};
52+
}
53+
}
54+
=== tests/cases/compiler/index.ts ===
55+
import { A } from './class';
56+
>A : typeof A
57+
58+
export class B extends A {
59+
>B : B
60+
>A : A
61+
62+
getA() { // TS4053 error
63+
>getA : () => { a: string; 123123: string; 12312312312: string; }
64+
65+
return {
66+
>{ ...super.getA(), a: '123', } : { a: string; 123123: string; 12312312312: string; }
67+
68+
...super.getA(),
69+
>super.getA() : import("tests/cases/compiler/class").ITest
70+
>super.getA : () => import("tests/cases/compiler/class").ITest
71+
>super : A
72+
>getA : () => import("tests/cases/compiler/class").ITest
73+
74+
a: '123',
75+
>a : string
76+
>'123' : "123"
77+
78+
};
79+
}
80+
}

tests/baselines/reference/declarationEmitWithDefaultAsComputedName.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ declare type Experiment<Name> = {
4141
declare const _default: Experiment<"foo">;
4242
export default _default;
4343
//// [main.d.ts]
44-
import other from "./other";
4544
export declare const obj: {
4645
foo: number;
4746
};

tests/baselines/reference/declarationEmitWithDefaultAsComputedName2.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ declare type Experiment<Name> = {
4141
declare const _default: Experiment<"foo">;
4242
export default _default;
4343
//// [main.d.ts]
44-
import * as other2 from "./other";
4544
export declare const obj: {
4645
foo: number;
4746
};

tests/baselines/reference/objectLiteralComputedNameNoDeclarationError.js

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ exports.Baa = (_a = {},
2121

2222

2323
//// [objectLiteralComputedNameNoDeclarationError.d.ts]
24-
declare const Foo: {
25-
BANANA: "banana";
26-
};
2724
export declare const Baa: {
2825
banana: number;
2926
};
30-
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @declaration: true
2+
// @filename: class.ts
3+
export const enum TestEnum {
4+
Test1 = '123123',
5+
Test2 = '12312312312',
6+
}
7+
8+
export interface ITest {
9+
[TestEnum.Test1]: string;
10+
[TestEnum.Test2]: string;
11+
}
12+
13+
export class A {
14+
getA(): ITest {
15+
return {
16+
[TestEnum.Test1]: '123',
17+
[TestEnum.Test2]: '123',
18+
};
19+
}
20+
}
21+
// @filename: index.ts
22+
import { A } from './class';
23+
24+
export class B extends A {
25+
getA() { // TS4053 error
26+
return {
27+
...super.getA(),
28+
a: '123',
29+
};
30+
}
31+
}

0 commit comments

Comments
 (0)