From 38c941bc55ee3356c5fe7c446f7698c76e22a3fb Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Tue, 5 Sep 2023 16:56:39 +0200 Subject: qml: fix parser grammar for argument deconstruction Previously, it was hardcoding a StringLiteralPropertyName for a BindingIdentifier. This does not make sense because BindingIdentifier cannot be string literals, they have to be identifiers. Also, this is problematic for deconstruction, e.g.: ``` function f(something) { let { x = 'x' } = something; // (1) return x; } ``` In (1), you cannot differentiate between the property name x and the string literal x, because the parser creates a string literal with value 'x' for both. Notably, qmlls cannot differentiate between a 'find usages' on the first x that is supposed to find the x in the return statement, and the second "x" that is supposed to find no usages because it is a string literal. Same happens also for deconstruction in method parameters. Add tests for qmlls for deconstruction in let-statements, and method parameters. Make sure qmlformat ignores this qmlfile as it cannot format deconstruction yet. Task-number: QTBUG-100084 Change-Id: Ib7df974437e442dc0bfca75381c773c4d30b11bb Reviewed-by: Ulf Hermann Reviewed-by: Qt CI Bot --- src/qml/parser/qqmljs.g | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qml/parser/qqmljs.g') diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 902e8290b4..5b8c5d0eaa 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -3330,7 +3330,7 @@ BindingElisionElement: ElisionOpt BindingElement; BindingProperty: BindingIdentifier InitializerOpt_In; /. case $rule_number: { - AST::StringLiteralPropertyName *name = new (pool) AST::StringLiteralPropertyName(stringRef(1)); + AST::IdentifierPropertyName *name = new (pool) AST::IdentifierPropertyName(stringRef(1)); name->propertyNameToken = loc(1); // if initializer is an anonymous function expression, we need to assign identifierref as it's name if (auto *f = asAnonymousFunctionDefinition(sym(2).Expression)) -- cgit v1.2.3