diff --git a/compiler_test.go b/compiler_test.go index fd47617a..39eec0f0 100644 --- a/compiler_test.go +++ b/compiler_test.go @@ -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") diff --git a/parser/expression.go b/parser/expression.go index 305bed49..7576310a 100644 --- a/parser/expression.go +++ b/parser/expression.go @@ -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{