Skip to content

Commit

Permalink
Support nested AssignmentElements in Array AssignmentPatterns. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Sep 27, 2024
1 parent e37b27f commit 241b342
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5866,6 +5866,26 @@ func TestFunctionBodyClassDecl(t *testing.T) {
}
}

func TestNestedDestructArray(t *testing.T) {
const SCRIPT = `
var [
[ h = 0 ] = [ 0 ]
] = [];
assert.sameValue(h, 0);
var [
[ h1 = 1 ] = []
] = [];
assert.sameValue(h1, 1);
var [
[ h2 = 1 ] = []
] = [ [ 2 ] ];
assert.sameValue(h2, 2);
`
testScriptWithTestLib(SCRIPT, _undefined, t)
}

/*
func TestBabel(t *testing.T) {
src, err := os.ReadFile("babel7.js")
Expand Down
2 changes: 1 addition & 1 deletion parser/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ func (self *_parser) reinterpretAsArrayBindingPattern(left *ast.ArrayLiteral) as
rest = self.reinterpretAsDestructBindingTarget(spread.Expression)
value = value[:len(value)-1]
} else {
value[i] = self.reinterpretAsBindingElement(item)
value[i] = self.reinterpretAsAssignmentElement(item)
}
}
return &ast.ArrayPattern{
Expand Down

0 comments on commit 241b342

Please sign in to comment.