summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscodeformatter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/qmljs/qmljscodeformatter.cpp')
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index eb7e61642d..b02075e4f8 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -252,6 +252,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: enter(expression); continue; // really? identifier and more tokens might already be gone
} break;
+ case expression_or_label:
+ switch (kind) {
+ case Colon: turnInto(labelled_statement); break;
+ default: enter(expression); continue;
+ } break;
+
case expression:
if (tryInsideExpression())
break;
@@ -346,6 +352,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightBrace: leave(true); break;
} break;
+ case labelled_statement:
+ if (tryStatement())
+ break;
+ leave(true); // error recovery
+ break;
+
case substatement:
// prefer substatement_open over block_open
if (kind != LeftBrace) {
@@ -426,7 +438,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightParenthesis: leave(); leave(true); break;
} break;
- break;
+ case breakcontinue_statement:
+ switch (kind) {
+ case Identifier: leave(true); break;
+ default: leave(true); continue; // try again
+ } break;
case case_start:
switch (kind) {
@@ -466,11 +482,22 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
int topState = m_currentState.top().type;
+ // if there's no colon on the same line, it's not a label
+ if (topState == expression_or_label)
+ enter(expression);
+ // if not followed by an identifier on the same line, it's done
+ else if (topState == breakcontinue_statement)
+ leave(true);
+
+ topState = m_currentState.top().type;
+
+ // some states might be continued on the next line
if (topState == expression
|| topState == expression_or_objectdefinition
|| topState == objectliteral_assignment) {
enter(expression_maybe_continuation);
}
+ // multi-line comment start?
if (topState != multiline_comment_start
&& topState != multiline_comment_cont
&& (lexerState & Scanner::MultiLineMask) == Scanner::MultiLineComment) {
@@ -680,7 +707,6 @@ bool CodeFormatter::tryStatement()
case Break:
case Continue:
enter(breakcontinue_statement);
- leave(true);
return true;
case Throw:
enter(throw_statement);
@@ -717,7 +743,10 @@ bool CodeFormatter::tryStatement()
enter(jsblock_open);
return true;
case Identifier:
+ enter(expression_or_label);
+ return true;
case Delimiter:
+ case Var:
case PlusPlus:
case MinusMinus:
case Import:
@@ -755,7 +784,6 @@ bool CodeFormatter::isExpressionEndState(int type) const
type == objectdefinition_open ||
type == if_statement ||
type == else_clause ||
- type == do_statement ||
type == jsblock_open ||
type == substatement_open ||
type == bracket_open ||