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