diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-09-05 16:56:39 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-09-11 14:28:27 +0200 |
commit | 38c941bc55ee3356c5fe7c446f7698c76e22a3fb (patch) | |
tree | 553a5656b4f5715a57e7afb28fd5b3a311c8d97f /src/qml/parser | |
parent | 4128479a8176dfa7bf2a832ffad7711f585d0288 (diff) |
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 <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/parser')
-rw-r--r-- | src/qml/parser/qqmljs.g | 2 |
1 files changed, 1 insertions, 1 deletions
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)) |