diff options
author | Uladzislau Paulovich <selatnick@gmail.com> | 2019-06-09 01:22:17 +0300 |
---|---|---|
committer | selatnick <selatnick@gmail.com> | 2019-06-11 15:23:42 +0000 |
commit | 70fecd518eb198fa5038efa03f450bcf6ab2cba8 (patch) | |
tree | c672533fcde143c2d3e4b1ac2c7e0a9e5625c11f /src | |
parent | 8f7cbd6416debf2214977a43edeb5f90b5cee702 (diff) | |
download | qt-creator-70fecd518eb198fa5038efa03f450bcf6ab2cba8.tar.gz |
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 <tim.jenssen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/qmljs/qmljsreformatter.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index 6ac55b2cce..5a5254fe26 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; } |