diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-06-06 08:42:40 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-06-21 13:30:48 +0000 |
commit | 45d39a1685e72975dd9bd4d3e4a67aab59eeae48 (patch) | |
tree | 61e55f0f733e11c144c2c82ce1725cce28aeab88 | |
parent | ce18e987d4ea623c0db6d10f2a97a16b639a234e (diff) |
Fix array destructuring nested in a rest element
Change-Id: I3a8c15fe221bff04a3b9b21ed8c0b06c04770a3d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 11 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 36 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 43 |
3 files changed, 23 insertions, 67 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index d71d36845b..b3b522e661 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -484,6 +484,7 @@ Codegen::Reference Codegen::targetForPatternElement(AST::PatternElement *p) void Codegen::initializeAndDestructureBindingElement(AST::PatternElement *e, const Reference &base) { + Q_ASSERT(e->type == AST::PatternElement::Binding || e->type == AST::PatternElement::RestElement); RegisterScope scope(this); Reference baseRef = (base.isAccumulator()) ? base.storeOnStack() : base; Reference varToStore = targetForPatternElement(e); @@ -619,12 +620,10 @@ void Codegen::destructureElementList(const Codegen::Reference &array, PatternEle bool last = !p->next || (!p->next->elision && !p->next->element); if (last) iteratorDone.storeConsumeAccumulator(); - if (e->type != PatternElement::RestElement) { - initializeAndDestructureBindingElement(e, iteratorValue); - if (hasError) { - end.link(); - return; - } + initializeAndDestructureBindingElement(e, iteratorValue); + if (hasError) { + end.link(); + return; } } } diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index e9e33f7561..b338c5bbfe 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -399,28 +399,28 @@ bool PatternElement::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceL *errorMessage = QString::fromLatin1("Invalid lhs expression after '...' in destructuring expression."); return false; } - bindingTarget = lhs; - return true; - } - type = PatternElement::Binding; + } else { + type = PatternElement::Binding; - if (BinaryExpression *b = init->binaryExpressionCast()) { - if (b->op != QSOperator::Assign) { - *errorLocation = b->operatorToken; - *errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression"); + if (BinaryExpression *b = init->binaryExpressionCast()) { + if (b->op != QSOperator::Assign) { + *errorLocation = b->operatorToken; + *errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression"); + return false; + } + lhs = b->left->leftHandSideExpressionCast(); + initializer = b->right; + Q_ASSERT(lhs); + } else { + lhs = init->leftHandSideExpressionCast(); + } + if (!lhs) { + *errorLocation = init->firstSourceLocation(); + *errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression."); return false; } - lhs = b->left->leftHandSideExpressionCast(); - initializer = b->right; - Q_ASSERT(lhs); - } else { - lhs = init->leftHandSideExpressionCast(); - } - if (!lhs) { - *errorLocation = init->firstSourceLocation(); - *errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression."); - return false; } + if (auto *i = cast<IdentifierExpression *>(lhs)) { bindingIdentifier = i->name.toString(); identifierToken = i->identifierToken; diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index ead465917b..d37459d353 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -2477,26 +2477,8 @@ language/expressions/array/spread-sngl-literal.js fails language/expressions/arrow-function/cannot-override-this-with-thisArg.js fails language/expressions/arrow-function/dflt-params-ref-later.js fails language/expressions/arrow-function/dflt-params-ref-self.js fails -language/expressions/arrow-function/dstr-ary-ptrn-elem-ary-rest-init.js strictFails -language/expressions/arrow-function/dstr-ary-ptrn-elem-ary-rest-iter.js strictFails language/expressions/arrow-function/dstr-ary-ptrn-elem-id-init-fn-name-class.js fails -language/expressions/arrow-function/dstr-ary-ptrn-rest-ary-elem.js fails -language/expressions/arrow-function/dstr-ary-ptrn-rest-ary-rest.js fails -language/expressions/arrow-function/dstr-ary-ptrn-rest-id-elision.js strictFails -language/expressions/arrow-function/dstr-ary-ptrn-rest-id-exhausted.js strictFails -language/expressions/arrow-function/dstr-ary-ptrn-rest-id.js strictFails -language/expressions/arrow-function/dstr-ary-ptrn-rest-obj-id.js fails -language/expressions/arrow-function/dstr-ary-ptrn-rest-obj-prop-id.js fails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-elem-ary-rest-init.js strictFails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-elem-ary-rest-iter.js strictFails language/expressions/arrow-function/dstr-dflt-ary-ptrn-elem-id-init-fn-name-class.js fails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-ary-elem.js fails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-ary-rest.js fails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-id-elision.js strictFails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-id-exhausted.js strictFails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-id.js strictFails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-obj-id.js fails -language/expressions/arrow-function/dstr-dflt-ary-ptrn-rest-obj-prop-id.js fails language/expressions/arrow-function/dstr-dflt-obj-ptrn-id-init-fn-name-class.js fails language/expressions/arrow-function/dstr-obj-ptrn-id-init-fn-name-class.js fails language/expressions/arrow-function/lexical-arguments.js fails @@ -2553,18 +2535,6 @@ language/expressions/assignment/dstr-array-rest-iter-rtrn-close.js fails language/expressions/assignment/dstr-array-rest-iter-thrw-close-err.js fails language/expressions/assignment/dstr-array-rest-iter-thrw-close.js fails language/expressions/assignment/dstr-array-rest-lref-err.js fails -language/expressions/assignment/dstr-array-rest-nested-array-null.js fails -language/expressions/assignment/dstr-array-rest-nested-array-undefined-hole.js fails -language/expressions/assignment/dstr-array-rest-nested-array-undefined-own.js fails -language/expressions/assignment/dstr-array-rest-nested-array-undefined.js fails -language/expressions/assignment/dstr-array-rest-nested-array-yield-expr.js fails -language/expressions/assignment/dstr-array-rest-nested-array-yield-ident-valid.js sloppyFails -language/expressions/assignment/dstr-array-rest-nested-array.js fails -language/expressions/assignment/dstr-array-rest-nested-obj-null.js fails -language/expressions/assignment/dstr-array-rest-nested-obj-undefined-hole.js fails -language/expressions/assignment/dstr-array-rest-nested-obj-undefined-own.js fails -language/expressions/assignment/dstr-array-rest-nested-obj-undefined.js fails -language/expressions/assignment/dstr-array-rest-nested-obj.js fails language/expressions/assignment/dstr-array-rest-put-const.js fails language/expressions/assignment/dstr-array-rest-put-let.js fails language/expressions/assignment/dstr-obj-empty-null.js fails @@ -4845,19 +4815,6 @@ language/statements/for-of/dstr-array-rest-iter-rtrn-close.js fails language/statements/for-of/dstr-array-rest-iter-thrw-close-err.js fails language/statements/for-of/dstr-array-rest-iter-thrw-close.js fails language/statements/for-of/dstr-array-rest-lref-err.js fails -language/statements/for-of/dstr-array-rest-nested-array-iter-thrw-close-skip.js fails -language/statements/for-of/dstr-array-rest-nested-array-null.js fails -language/statements/for-of/dstr-array-rest-nested-array-undefined-hole.js fails -language/statements/for-of/dstr-array-rest-nested-array-undefined-own.js fails -language/statements/for-of/dstr-array-rest-nested-array-undefined.js fails -language/statements/for-of/dstr-array-rest-nested-array-yield-expr.js fails -language/statements/for-of/dstr-array-rest-nested-array-yield-ident-valid.js sloppyFails -language/statements/for-of/dstr-array-rest-nested-array.js fails -language/statements/for-of/dstr-array-rest-nested-obj-null.js fails -language/statements/for-of/dstr-array-rest-nested-obj-undefined-hole.js fails -language/statements/for-of/dstr-array-rest-nested-obj-undefined-own.js fails -language/statements/for-of/dstr-array-rest-nested-obj-undefined.js fails -language/statements/for-of/dstr-array-rest-nested-obj.js fails language/statements/for-of/dstr-array-rest-put-const.js fails language/statements/for-of/dstr-array-rest-put-let.js fails language/statements/for-of/dstr-const-ary-init-iter-close.js fails |