Skip to content

Commit 3d5199c

Browse files
committed
fix: add baselines and handle parentheses in getFirstIdentifier
- Add reference baselines for enumKeysExportScenario test - Fix getFirstIdentifier to skipParentheses when traversing access chains to handle cases like (obj.a)['b']
1 parent 1d0e474 commit 3d5199c

File tree

4 files changed

+135
-1
lines changed

4 files changed

+135
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7475,7 +7475,7 @@ export function getFirstIdentifier(node: EntityNameOrEntityNameExpression | Elem
74757475
case SyntaxKind.ElementAccessExpression:
74767476
let expr: Expression = node;
74777477
do {
7478-
expr = (expr as PropertyAccessExpression | ElementAccessExpression).expression;
7478+
expr = skipParentheses((expr as PropertyAccessExpression | ElementAccessExpression).expression);
74797479
}
74807480
while (expr.kind !== SyntaxKind.Identifier);
74817481
return expr as Identifier;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tests/cases/compiler/enumKeysExportScenario.ts] ////
2+
3+
//// [enumKeysExportScenario.ts]
4+
// Test that export scenario with enum bracket notation doesn't crash
5+
// This tests the trackComputedName -> getFirstIdentifier path
6+
7+
enum Type {
8+
Foo = 'foo',
9+
'3x14' = '3x14'
10+
}
11+
12+
// Export interface with bracket notation computed property
13+
// This should trigger the tracker path
14+
export interface TypeMap {
15+
[Type['3x14']]: number;
16+
}
17+
18+
export type TypeMap2 = {
19+
[Type['3x14']]: string;
20+
}
21+
22+
23+
//// [enumKeysExportScenario.js]
24+
"use strict";
25+
// Test that export scenario with enum bracket notation doesn't crash
26+
// This tests the trackComputedName -> getFirstIdentifier path
27+
Object.defineProperty(exports, "__esModule", { value: true });
28+
var Type;
29+
(function (Type) {
30+
Type["Foo"] = "foo";
31+
Type["3x14"] = "3x14";
32+
})(Type || (Type = {}));
33+
34+
35+
//// [enumKeysExportScenario.d.ts]
36+
declare enum Type {
37+
Foo = "foo",
38+
'3x14' = "3x14"
39+
}
40+
export interface TypeMap {
41+
[Type['3x14']]: number;
42+
}
43+
export type TypeMap2 = {
44+
[Type['3x14']]: string;
45+
};
46+
export {};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/compiler/enumKeysExportScenario.ts] ////
2+
3+
=== enumKeysExportScenario.ts ===
4+
// Test that export scenario with enum bracket notation doesn't crash
5+
// This tests the trackComputedName -> getFirstIdentifier path
6+
7+
enum Type {
8+
>Type : Symbol(Type, Decl(enumKeysExportScenario.ts, 0, 0))
9+
10+
Foo = 'foo',
11+
>Foo : Symbol(Type.Foo, Decl(enumKeysExportScenario.ts, 3, 11))
12+
13+
'3x14' = '3x14'
14+
>'3x14' : Symbol(Type['3x14'], Decl(enumKeysExportScenario.ts, 4, 16))
15+
}
16+
17+
// Export interface with bracket notation computed property
18+
// This should trigger the tracker path
19+
export interface TypeMap {
20+
>TypeMap : Symbol(TypeMap, Decl(enumKeysExportScenario.ts, 6, 1))
21+
22+
[Type['3x14']]: number;
23+
>[Type['3x14']] : Symbol(TypeMap[Type['3x14']], Decl(enumKeysExportScenario.ts, 10, 26))
24+
>Type : Symbol(Type, Decl(enumKeysExportScenario.ts, 0, 0))
25+
>'3x14' : Symbol(Type['3x14'], Decl(enumKeysExportScenario.ts, 4, 16))
26+
}
27+
28+
export type TypeMap2 = {
29+
>TypeMap2 : Symbol(TypeMap2, Decl(enumKeysExportScenario.ts, 12, 1))
30+
31+
[Type['3x14']]: string;
32+
>[Type['3x14']] : Symbol([Type['3x14']], Decl(enumKeysExportScenario.ts, 14, 24))
33+
>Type : Symbol(Type, Decl(enumKeysExportScenario.ts, 0, 0))
34+
>'3x14' : Symbol(Type['3x14'], Decl(enumKeysExportScenario.ts, 4, 16))
35+
}
36+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [tests/cases/compiler/enumKeysExportScenario.ts] ////
2+
3+
=== enumKeysExportScenario.ts ===
4+
// Test that export scenario with enum bracket notation doesn't crash
5+
// This tests the trackComputedName -> getFirstIdentifier path
6+
7+
enum Type {
8+
>Type : Type
9+
> : ^^^^
10+
11+
Foo = 'foo',
12+
>Foo : Type.Foo
13+
> : ^^^^^^^^
14+
>'foo' : "foo"
15+
> : ^^^^^
16+
17+
'3x14' = '3x14'
18+
>'3x14' : (typeof Type)["3x14"]
19+
> : ^^^^^^^^^^^^^^^^^^^^^
20+
>'3x14' : "3x14"
21+
> : ^^^^^^
22+
}
23+
24+
// Export interface with bracket notation computed property
25+
// This should trigger the tracker path
26+
export interface TypeMap {
27+
[Type['3x14']]: number;
28+
>[Type['3x14']] : number
29+
> : ^^^^^^
30+
>Type['3x14'] : (typeof Type)["3x14"]
31+
> : ^^^^^^^^^^^^^^^^^^^^^
32+
>Type : typeof Type
33+
> : ^^^^^^^^^^^
34+
>'3x14' : "3x14"
35+
> : ^^^^^^
36+
}
37+
38+
export type TypeMap2 = {
39+
>TypeMap2 : TypeMap2
40+
> : ^^^^^^^^
41+
42+
[Type['3x14']]: string;
43+
>[Type['3x14']] : string
44+
> : ^^^^^^
45+
>Type['3x14'] : (typeof Type)["3x14"]
46+
> : ^^^^^^^^^^^^^^^^^^^^^
47+
>Type : typeof Type
48+
> : ^^^^^^^^^^^
49+
>'3x14' : "3x14"
50+
> : ^^^^^^
51+
}
52+

0 commit comments

Comments
 (0)