From 77cb60e0c071f9762f565f1f38859421c928dd4a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 6 Jun 2018 09:02:53 +0200 Subject: Fix const expressions containing destructuring patterns Don't throw a syntax error when encountering a destructuring pattern. Change-Id: I93250a2963d2d50ff61d725229e1b51be17689e9 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compilerscanfunctions.cpp | 2 +- src/qml/parser/qqmljs.g | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 639728df52..68cb58da46 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -177,7 +177,7 @@ bool ScanFunctions::visit(PatternElement *ast) checkName(QStringRef(&name), ast->identifierToken); if (name == QLatin1String("arguments")) _context->usesArgumentsObject = Context::ArgumentsObjectNotUsed; - if (ast->scope == VariableScope::Const && !ast->initializer) { + if (ast->scope == VariableScope::Const && !ast->initializer && !ast->destructuringPattern()) { _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Missing initializer in const declaration")); return false; } diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index f927473e53..7928881d8c 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -3209,7 +3209,6 @@ ForDeclaration: Var BindingPattern; /. case $rule_number: { auto *node = new (pool) AST::PatternElement(sym(2).Pattern, nullptr); - node->identifierToken = loc(2); node->scope = sym(1).scope; sym(1).Node = node; } break; -- cgit v1.2.3