From a24c49720a0068826ad1c2d160cf644efabfa20b Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Tue, 29 Nov 2011 14:37:36 +0100
Subject: [PATCH] QmlJS reformatter: Fix object literals.

The comma token seems to be invalid.

Change-Id: I859fa58ba0ba1e975e0cf1105c2b53aac848fb0d
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
---
 src/libs/qmljs/qmljsreformatter.cpp            |  4 +---
 tests/auto/qml/reformatter/jssyntax.js         |  3 +--
 tests/auto/qml/reformatter/objectliteral.js    | 12 ++++++++++++
 tests/auto/qml/reformatter/tst_reformatter.cpp |  2 +-
 4 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 tests/auto/qml/reformatter/objectliteral.js

diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp
index 884922c6984..33b945c8054 100644
--- a/src/libs/qmljs/qmljsreformatter.cpp
+++ b/src/libs/qmljs/qmljsreformatter.cpp
@@ -667,7 +667,7 @@ protected:
             out(": ", ast->colonToken);
             accept(it->value);
             if (it->next) {
-                out(ast->commaToken);
+                out(",", ast->commaToken); // always invalid?
                 newLine();
             }
         }
@@ -1117,8 +1117,6 @@ protected:
 
     virtual bool visit(FunctionExpression *ast)
     {
-        if (!firstOnLine())
-            newLine();
         out("function ", ast->functionToken);
         if (!ast->name.isNull())
             out(ast->identifierToken);
diff --git a/tests/auto/qml/reformatter/jssyntax.js b/tests/auto/qml/reformatter/jssyntax.js
index 17be1401c93..5ef1a2adcd6 100644
--- a/tests/auto/qml/reformatter/jssyntax.js
+++ b/tests/auto/qml/reformatter/jssyntax.js
@@ -6,8 +6,7 @@ function foo(a, b) {
     x += 4
 }
 
-var foo =
-        function (a, b) {}
+var foo = function (a, b) {}
 
 while (true) {
     for (var a = 1; a < 5; ++a) {
diff --git a/tests/auto/qml/reformatter/objectliteral.js b/tests/auto/qml/reformatter/objectliteral.js
new file mode 100644
index 00000000000..478d550573c
--- /dev/null
+++ b/tests/auto/qml/reformatter/objectliteral.js
@@ -0,0 +1,12 @@
+var x = {
+    x: 12,
+    y: {
+        x: 12,
+        y: "abc",
+        z: function (x) {
+               return a
+           },
+        abc: 15
+    },
+    z: 12
+}
diff --git a/tests/auto/qml/reformatter/tst_reformatter.cpp b/tests/auto/qml/reformatter/tst_reformatter.cpp
index 91fba3d1063..6422995cde5 100644
--- a/tests/auto/qml/reformatter/tst_reformatter.cpp
+++ b/tests/auto/qml/reformatter/tst_reformatter.cpp
@@ -81,7 +81,7 @@ void tst_Reformatter::test()
 {
     QFETCH(QString, path);
 
-    Document::Ptr doc = Document::create(path, Document::guessLanguageFromSuffix(path));
+    Document::MutablePtr doc = Document::create(path, Document::guessLanguageFromSuffix(path));
     QFile file(doc->fileName());
     file.open(QFile::ReadOnly | QFile::Text);
     QString source = QString::fromUtf8(file.readAll());
-- 
GitLab