Qml/js reformatter: use quotes in objects literals

The reformatter used to remove the quotes that wraps the property name
in object literals.  This causes problem when the name is not a
valid identifier, resulting in that valid code become invalid after
reformatting.
This patch forces wrapping of property's name in quotes: in this way,
the reformatted code is consistent and it never get invalidated.

However the resulting formatted code is not consisted with the one
formatted by previous versions.

Task-number: QTCREATORBUG-17455
Change-Id: I1e361102819055de210d6c81020f204c08aaa253
Reviewed-by: Markus Maier <markus.maier.sw@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Marco Benelli
2017-11-21 10:00:44 +01:00
parent bf285af007
commit a874cf581d
2 changed files with 9 additions and 7 deletions

View File

@@ -687,7 +687,9 @@ protected:
for (PropertyAssignmentList *it = ast; it; it = it->next) { for (PropertyAssignmentList *it = ast; it; it = it->next) {
PropertyNameAndValue *assignment = AST::cast<PropertyNameAndValue *>(it->assignment); PropertyNameAndValue *assignment = AST::cast<PropertyNameAndValue *>(it->assignment);
if (assignment) { if (assignment) {
out("\"");
accept(assignment->name); accept(assignment->name);
out("\"");
out(": ", assignment->colonToken); out(": ", assignment->colonToken);
accept(assignment->value); accept(assignment->value);
if (it->next) { if (it->next) {

View File

@@ -1,12 +1,12 @@
var x = { var x = {
x: 12, "x": 12,
y: { "y": {
x: 12, "x": 12,
y: "abc", "y": "abc",
z: function (x) { "z": function (x) {
return a return a
}, },
abc: 15 "abc": 15
}, },
z: 12 "z": 12
} }