Skip to content

Commit 1704b2f

Browse files
authored
Merge pull request #39025 from microsoft/isDynamicName-skip-parens
isDynamicName skips parentheses for element access
2 parents ffa35d3 + a64166d commit 1704b2f

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,7 +3061,7 @@ namespace ts {
30613061
if (!(name.kind === SyntaxKind.ComputedPropertyName || name.kind === SyntaxKind.ElementAccessExpression)) {
30623062
return false;
30633063
}
3064-
const expr = isElementAccessExpression(name) ? name.argumentExpression : name.expression;
3064+
const expr = isElementAccessExpression(name) ? skipParentheses(name.argumentExpression) : name.expression;
30653065
return !isStringOrNumericLiteralLike(expr) &&
30663066
!isSignedNumericLiteral(expr) &&
30673067
!isWellKnownSymbolSyntactically(expr);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/salsa/bug38934.js ===
2+
var x = {};
3+
>x : Symbol(x, Decl(bug38934.js, 0, 3))
4+
5+
// should not crash and also should not result in a property '0' on x.
6+
x[(0)] = 1;
7+
>x : Symbol(x, Decl(bug38934.js, 0, 3))
8+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/salsa/bug38934.js ===
2+
var x = {};
3+
>x : {}
4+
>{} : {}
5+
6+
// should not crash and also should not result in a property '0' on x.
7+
x[(0)] = 1;
8+
>x[(0)] = 1 : 1
9+
>x[(0)] : any
10+
>x : {}
11+
>(0) : 0
12+
>0 : 0
13+
>1 : 1
14+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @Filename: bug38934.js
5+
6+
var x = {};
7+
// should not crash and also should not result in a property '0' on x.
8+
x[(0)] = 1;

0 commit comments

Comments
 (0)