mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #39025 from microsoft/isDynamicName-skip-parens
isDynamicName skips parentheses for element access
This commit is contained in:
@@ -3061,7 +3061,7 @@ namespace ts {
|
||||
if (!(name.kind === SyntaxKind.ComputedPropertyName || name.kind === SyntaxKind.ElementAccessExpression)) {
|
||||
return false;
|
||||
}
|
||||
const expr = isElementAccessExpression(name) ? name.argumentExpression : name.expression;
|
||||
const expr = isElementAccessExpression(name) ? skipParentheses(name.argumentExpression) : name.expression;
|
||||
return !isStringOrNumericLiteralLike(expr) &&
|
||||
!isSignedNumericLiteral(expr) &&
|
||||
!isWellKnownSymbolSyntactically(expr);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/salsa/bug38934.js ===
|
||||
var x = {};
|
||||
>x : Symbol(x, Decl(bug38934.js, 0, 3))
|
||||
|
||||
// should not crash and also should not result in a property '0' on x.
|
||||
x[(0)] = 1;
|
||||
>x : Symbol(x, Decl(bug38934.js, 0, 3))
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/salsa/bug38934.js ===
|
||||
var x = {};
|
||||
>x : {}
|
||||
>{} : {}
|
||||
|
||||
// should not crash and also should not result in a property '0' on x.
|
||||
x[(0)] = 1;
|
||||
>x[(0)] = 1 : 1
|
||||
>x[(0)] : any
|
||||
>x : {}
|
||||
>(0) : 0
|
||||
>0 : 0
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @Filename: bug38934.js
|
||||
|
||||
var x = {};
|
||||
// should not crash and also should not result in a property '0' on x.
|
||||
x[(0)] = 1;
|
||||
Reference in New Issue
Block a user