Skip to content

Commit

Permalink
Add test for nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe committed Sep 16, 2024
1 parent f249481 commit e2537dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rhino/src/main/java/org/mozilla/javascript/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4313,7 +4313,6 @@ private void processDestructuringDefaults(
// : $1[0])
// : x

/* TODO(satish): should transform other nodes; move this to IRFactory */
if ((n.getRight() instanceof FunctionNode
|| n.getRight() instanceof UpdateExpression
|| n.getRight() instanceof ParenthesizedExpression)
Expand All @@ -4332,7 +4331,9 @@ private void processDestructuringDefaults(

// if right is a function/update expression, it should be processed later
// store it in the node to be processed
if ((right instanceof FunctionNode || right instanceof UpdateExpression)
if ((right instanceof FunctionNode
|| right instanceof UpdateExpression
|| right instanceof ParenthesizedExpression)
&& transformer == null) {
currentScriptOrFn.putDestructuringRvalues(cond_inner, right);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public void letExprUnresolvableRefDestructuring() throws Exception {
assertThrows("ReferenceError: \"unresolvableReference\" is not defined.", script);
}

@Test
public void destructuringNestedArray() throws Exception {
// JavaScript
final String script = "let [[y], x] = [[4], 3]; x + y";
assertIntEvaluates(7, script);
}

@Test
public void letExprUnresolvableRefObjDestructuring() throws Exception {
// JavaScript
Expand Down

0 comments on commit e2537dc

Please sign in to comment.