From 70fecd518eb198fa5038efa03f450bcf6ab2cba8 Mon Sep 17 00:00:00 2001 From: Uladzislau Paulovich Date: Sun, 9 Jun 2019 01:22:17 +0300 Subject: [PATCH] qml | Fix functions and loops formatting Bugs fixed in this change: 1. Incorrect function arguments formatting: function(a, b, c) -> function(abc) 2. Incorrect foreach loop formatting: for (var a in b) -> for (a in b) 3. Incorrect for loop formatting: for (var a = 1; a < 100; ++a) -> for(; a < 100; ++a) Change-Id: I8afef6e5f2485a2225931b7ecb7210506e06dc6c Reviewed-by: Tim Jenssen --- src/libs/qmljs/qmljsreformatter.cpp | 20 ++++++++++++++++++-- tests/auto/qml/reformatter/jssyntax.js | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index 6ac55b2ccec..5a5254fe264 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -962,7 +962,15 @@ protected: bool visit(PatternElement *ast) override { - + if (ast->isForDeclaration) { + if (ast->scope == VariableScope::Var) { + out("var "); + } else if (ast->scope == VariableScope::Let) { + out("let "); + } else if (ast->scope == VariableScope::Const) { + out("const "); + } + } out(ast->identifierToken); if (ast->initializer) { if (ast->isVariableDeclaration()) @@ -1026,7 +1034,12 @@ protected: out(ast->forToken); out(" "); out(ast->lparenToken); - accept(ast->initialiser); + if (ast->initialiser) { + accept(ast->initialiser); + } else if (ast->declarations) { + out("var "); + accept(ast->declarations); + } out("; ", ast->firstSemicolonToken); accept(ast->condition); out("; ", ast->secondSemicolonToken); @@ -1314,6 +1327,9 @@ protected: { for (FormalParameterList *it = ast; it; it = it->next) { out(it->element->bindingIdentifier.toString()); // TODO + if (it->next) { + out(", "); + } } return false; } diff --git a/tests/auto/qml/reformatter/jssyntax.js b/tests/auto/qml/reformatter/jssyntax.js index 9fd8b38a563..d651cd7822c 100644 --- a/tests/auto/qml/reformatter/jssyntax.js +++ b/tests/auto/qml/reformatter/jssyntax.js @@ -32,6 +32,12 @@ while (true) { for (var x in a) { print(a[x]) } + for (let x in a) { + print(a[x]) + } + for (const x in a) { + print(a[x]) + } do { a = x