Skip to content

Commit 8adc6ca

Browse files
committed
Fix crash when private id in array assignment
1 parent e83d613 commit 8adc6ca

6 files changed

+33
-4
lines changed

src/compiler/transformers/classFields.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2981,11 +2981,11 @@ export function transformClassFields(context: TransformationContext): (x: Source
29812981
}
29822982

29832983
function visitArrayAssignmentElement(node: Expression): Expression {
2984-
Debug.assertNode(node, isArrayBindingOrAssignmentElement);
2985-
if (isSpreadElement(node)) return visitAssignmentRestElement(node);
2986-
if (!isOmittedExpression(node)) return visitAssignmentElement(node);
2984+
if (isArrayBindingOrAssignmentElement(node)) {
2985+
if (isSpreadElement(node)) return visitAssignmentRestElement(node);
2986+
if (!isOmittedExpression(node)) return visitAssignmentElement(node);
2987+
}
29872988
return visitEachChild(node, visitor, context);
2988-
29892989
}
29902990

29912991
function visitAssignmentProperty(node: PropertyAssignment) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
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.
2+
tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts(1,8): error TS1109: Expression expected.
3+
4+
5+
==== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts (2 errors) ====
6+
[#abc]=
7+
~~~~
8+
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
9+
10+
!!! error TS1109: Expression expected.
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [parserPrivateIdentifierInArrayAssignment.ts]
2+
[#abc]=
3+
4+
5+
//// [parserPrivateIdentifierInArrayAssignment.js]
6+
#abc = [0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts ===
2+
3+
[#abc]=
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/parserPrivateIdentifierInArrayAssignment.ts ===
2+
[#abc]=
3+
>[#abc]= : any
4+
>[#abc] : [any]
5+
6+
> : any
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[#abc]=

0 commit comments

Comments
 (0)