aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2023-07-31 15:12:01 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2023-08-01 14:06:18 +0200
commit115916f217b0dc299b8df298f5c9c30369f561f8 (patch)
tree532480f530550042c2aa3ee1ce8022af564a7346 /src/qml/parser
parent26bc3ab5b0c0b3d43a3d8e43fb84e248b25401f2 (diff)
qmlformat: fix formatting of object destructuring
The following issues are fixed: - [1]Incorrect detection of the property name as a string literal and thus writing out them with quotation marks - [2] Duplication of property name when a scoped variable is used as property key - [3] Writing out additional brackets during deconstruction - [4] Incorrect formatting when a default is assigned to a lhs variable like [a = 24, b] = array - [5] Automatic addition of "" characters into the object keys - [6] Automatic addition of assignment operator, instead only add it when there is a pending initializer Also, add the colon token location which was missing in the pattern property rules. Remove it from a couple of rules that was giving incorrect result. We require the location information of the colon token to be correct when formatting. A few of tst_qmlformat and tst_reformatter tests are adapted to the above mentioned changes [1], [2], [5]. [ChangeLog][qmlformat][Important Behavior Changes] qmlformat will no longer add "" characters automatically in the object keys unless the object key is actually a string literal. Also, using a scoped variable as the property key will no longer result in the duplication of the property name. Pick-to: 6.6 Fixes: QTBUG-108275 Fixes: QTBUG-114839 Change-Id: I272d41d13df34ff5877f3efebe43c80255dd7c2b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r--src/qml/parser/qqmljs.g10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index bcede595a2..9a10015cbc 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -2005,7 +2005,6 @@ PropertyDefinition: IdentifierReference;
AST::IdentifierExpression *expr = new (pool) AST::IdentifierExpression(stringRef(1));
expr->identifierToken = loc(1);
AST::PatternProperty *node = new (pool) AST::PatternProperty(name, expr);
- node->colonToken = loc(2);
sym(1).Node = node;
} break;
./
@@ -2028,7 +2027,6 @@ CoverInitializedName: IdentifierReference Initializer_In;
AST::BinaryExpression *assignment = new (pool) AST::BinaryExpression(left, QSOperator::Assign, sym(2).Expression);
assignment->operatorToken = loc(2);
AST::PatternProperty *node = new (pool) AST::PatternProperty(name, assignment);
- node->colonToken = loc(1);
sym(1).Node = node;
} break;
@@ -3338,7 +3336,8 @@ BindingProperty: BindingIdentifier InitializerOpt_In;
f->name = stringRef(1);
if (auto *c = asAnonymousClassDefinition(sym(2).Expression))
c->name = stringRef(1);
- sym(1).Node = new (pool) AST::PatternProperty(name, stringRef(1), sym(2).Expression);
+ AST::PatternProperty *node = new (pool) AST::PatternProperty(name, stringRef(1), sym(2).Expression);
+ sym(1).Node = node;
} break;
./
@@ -3346,6 +3345,7 @@ BindingProperty: PropertyName T_COLON BindingIdentifier InitializerOpt_In;
/.
case $rule_number: {
AST::PatternProperty *node = new (pool) AST::PatternProperty(sym(1).PropertyName, stringRef(3), sym(4).Expression);
+ node->colonToken = loc(2);
sym(1).Node = node;
} break;
./
@@ -3354,6 +3354,7 @@ BindingProperty: PropertyName T_COLON BindingPattern InitializerOpt_In;
/.
case $rule_number: {
AST::PatternProperty *node = new (pool) AST::PatternProperty(sym(1).PropertyName, sym(3).Pattern, sym(4).Expression);
+ node->colonToken = loc(2);
sym(1).Node = node;
} break;
./
@@ -4112,7 +4113,6 @@ MethodDefinition: T_STAR PropertyName GeneratorLParen StrictFormalParameters T_R
f->rbraceToken = loc(9);
f->isGenerator = true;
AST::PatternProperty *node = new (pool) AST::PatternProperty(sym(2).PropertyName, f, AST::PatternProperty::Method);
- node->colonToken = loc(2);
sym(1).Node = node;
} break;
./
@@ -4130,7 +4130,6 @@ MethodDefinition: T_GET PropertyName T_LPAREN T_RPAREN TypeAnnotationOpt Functio
f->lbraceToken = loc(6);
f->rbraceToken = loc(8);
AST::PatternProperty *node = new (pool) AST::PatternProperty(sym(2).PropertyName, f, AST::PatternProperty::Getter);
- node->colonToken = loc(2);
sym(1).Node = node;
} break;
./
@@ -4147,7 +4146,6 @@ MethodDefinition: T_SET PropertyName T_LPAREN PropertySetParameterList T_RPAREN
f->lbraceToken = loc(7);
f->rbraceToken = loc(9);
AST::PatternProperty *node = new (pool) AST::PatternProperty(sym(2).PropertyName, f, AST::PatternProperty::Setter);
- node->colonToken = loc(2);
sym(1).Node = node;
} break;
./