From 9e4e44d180a2bf1bad05010d754cd821d112d519 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Tue, 23 Feb 2021 08:45:09 +0100 Subject: [PATCH] qmljs: preserve default arguments when reformatting QML Fixes: QTCREATORBUG-23009 Change-Id: I9949fe26a91a063c4804fddcca4e26d14bc5cd61 Reviewed-by: Fabian Kosmale --- src/libs/qmljs/qmljsreformatter.cpp | 4 ++-- tests/auto/qml/reformatter/jssyntax.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index bb2a0520721..c83ee11a357 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -1023,7 +1023,7 @@ protected: } out(ast->identifierToken); if (ast->initializer) { - if (ast->isVariableDeclaration()) + if (ast->isVariableDeclaration() || ast->type == PatternElement::Binding) out(" = "); accept(ast->initializer); } @@ -1394,7 +1394,7 @@ protected: bool visit(FormalParameterList *ast) override { for (FormalParameterList *it = ast; it; it = it->next) { - out(it->element->bindingIdentifier.toString()); // TODO + accept(it->element); if (it->next) out(", "); } diff --git a/tests/auto/qml/reformatter/jssyntax.js b/tests/auto/qml/reformatter/jssyntax.js index 2d46f597c80..34166825aaf 100644 --- a/tests/auto/qml/reformatter/jssyntax.js +++ b/tests/auto/qml/reformatter/jssyntax.js @@ -15,7 +15,7 @@ function foo(a, b) { x += 4 } -var foo = function (a, b) {} +var foo = function (a, b = 0) {} function spread() { iterableObj = [1, 2]