Fix crash when private id in array assignment (#53665)

This commit is contained in:
Jake Bailey 2023-04-05 13:04:13 -07:00 committed by GitHub
parent e83d61398e
commit a720ba921f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 4 deletions

View File

@ -2981,11 +2981,11 @@ export function transformClassFields(context: TransformationContext): (x: Source
}
function visitArrayAssignmentElement(node: Expression): Expression {
Debug.assertNode(node, isArrayBindingOrAssignmentElement);
if (isSpreadElement(node)) return visitAssignmentRestElement(node);
if (!isOmittedExpression(node)) return visitAssignmentElement(node);
if (isArrayBindingOrAssignmentElement(node)) {
if (isSpreadElement(node)) return visitAssignmentRestElement(node);
if (!isOmittedExpression(node)) return visitAssignmentElement(node);
}
return visitEachChild(node, visitor, context);
}
function visitAssignmentProperty(node: PropertyAssignment) {

View File

@ -0,0 +1,11 @@
tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts(1,2): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts(1,8): error TS1109: Expression expected.
==== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts (2 errors) ====
[#abc]=
~~~~
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
!!! error TS1109: Expression expected.

View File

@ -0,0 +1,6 @@
//// [parserPrivateIdentifierInArrayAssignment.ts]
[#abc]=
//// [parserPrivateIdentifierInArrayAssignment.js]
#abc = [0];

View File

@ -0,0 +1,4 @@
=== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts ===
[#abc]=

View File

@ -0,0 +1,7 @@
=== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts ===
[#abc]=
>[#abc]= : any
>[#abc] : [any]
> : any

View File

@ -0,0 +1 @@
[#abc]=