aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlformat
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-06-18 14:36:37 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-06-25 09:02:10 +0200
commiteb90e8ee3313bee547e6721a2649bf9ba84e3e5c (patch)
tree2c578f90d6c2c267498cb7ab919d75c68751ad91 /tools/qmlformat
parent88b3d1fd26b6b566ef00ae728051bff29455eea5 (diff)
qmlformat: Fix nested functions
Fixes: QTBUG-85035 Change-Id: I5e1cb003b7b84547e3408a086eebf3be740e6860 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qmlformat')
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp17
-rw-r--r--tools/qmlformat/dumpastvisitor.h2
2 files changed, 15 insertions, 4 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index 6868a3e21b..859d399805 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -1220,8 +1220,14 @@ void DumpAstVisitor::endVisit(UiArrayBinding *) {
}
bool DumpAstVisitor::visit(FunctionDeclaration *node) {
+ if (scope().m_firstFunction) {
+ if (scope().m_firstOfAll)
+ scope().m_firstOfAll = false;
+ else
+ addNewLine();
- addNewLine();
+ scope().m_firstFunction = false;
+ }
addLine(getComment(node, Comment::Location::Front));
@@ -1239,13 +1245,16 @@ bool DumpAstVisitor::visit(FunctionDeclaration *node) {
addLine(head);
m_indentLevel++;
+
+ return true;
+}
+
+void DumpAstVisitor::endVisit(FunctionDeclaration *node)
+{
m_result += parseStatementList(node->body);
m_indentLevel--;
addLine("}");
-
addNewLine();
-
- return true;
}
bool DumpAstVisitor::visit(UiObjectBinding *node) {
diff --git a/tools/qmlformat/dumpastvisitor.h b/tools/qmlformat/dumpastvisitor.h
index 9b908dd101..f84c4859ae 100644
--- a/tools/qmlformat/dumpastvisitor.h
+++ b/tools/qmlformat/dumpastvisitor.h
@@ -58,6 +58,7 @@ public:
void endVisit(UiObjectBinding *node) override;
bool visit(FunctionDeclaration *node) override;
+ void endVisit(FunctionDeclaration *node) override;
bool visit(UiInlineComponent *node) override;
void endVisit(UiInlineComponent *node) override;
@@ -86,6 +87,7 @@ private:
bool m_firstProperty = true;
bool m_firstBinding = true;
bool m_firstObject = true;
+ bool m_firstFunction = true;
bool m_inArrayBinding = false;
bool m_pendingBinding = false;