Commit ab64c1ae authored by Christian Kamm's avatar Christian Kamm Committed by Fawzi Mohamed

QmlJS indenter: Improve indentation of function expressions.

As discussed with Tor Arne and Fawzi in
http://codereview.qt-project.org/#change,18080

Change-Id: Ia0482d2ed3ddd61fa002e2c76b948301af52a795
Reviewed-by: default avatarTor Arne Vestbø <tor.arne.vestbo@nokia.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 97050014
......@@ -1124,27 +1124,10 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
}
break;
case function_start: {
// in these states, align to the 'function' keyword
const int parentType = parentState.type;
if (parentType == objectdefinition_open
|| parentType == paren_open
|| parentType == bracket_open) {
*indentDepth = tokenPosition;
*savedIndentDepth = *indentDepth;
break;
}
// otherwise find the enclosing expression end state and align to that
for (int i = 1; state(i).type != topmost_intro; ++i) {
const int type = state(i).type;
if (isExpressionEndState(type)) {
*indentDepth = state(i - 1).savedIndentDepth;
break;
}
}
case function_start:
// align to the beginning of the line
*savedIndentDepth = *indentDepth = column(tokenAt(0).begin());
break;
}
case do_statement_while_paren_open:
case statement_with_condition_paren_open:
......
......@@ -59,6 +59,7 @@ private Q_SLOTS:
void functionExpression3();
void functionExpression4();
void functionExpression5();
void functionExpression6();
void propertyDeclarations();
void signalDeclarations();
void ifBinding1();
......@@ -398,12 +399,12 @@ void tst_QMLCodeFormatter::functionExpression2()
data << Line("Rectangle {")
<< Line(" function foo(a, b, c) {")
<< Line(" foo(1, 123456, function() {")
<< Line(" b;")
<< Line(" })")
<< Line(" b;")
<< Line(" })")
<< Line(" foo(1, 123456, function()")
<< Line(" {")
<< Line(" b;")
<< Line(" })")
<< Line(" {")
<< Line(" b;")
<< Line(" })")
<< Line(" foobar(1, 123456,")
<< Line(" function () {")
<< Line(" b;")
......@@ -488,6 +489,30 @@ void tst_QMLCodeFormatter::functionExpression5()
checkIndent(data);
}
void tst_QMLCodeFormatter::functionExpression6()
{
QList<Line> data;
data << Line("Rectangle {")
<< Line(" property var foo: {")
<< Line(" functioncall(1, 2, function() {")
<< Line(" a()")
<< Line(" }, function() {")
<< Line(" a()")
<< Line(" }, 6,")
<< Line(" 7)")
<< Line(" functioncall(1, 2,")
<< Line(" function() {")
<< Line(" a()")
<< Line(" }, 3, function() {")
<< Line(" a()")
<< Line(" }, 6,")
<< Line(" 7)")
<< Line(" }")
<< Line("}")
;
checkIndent(data);
}
void tst_QMLCodeFormatter::propertyDeclarations()
{
QList<Line> data;
......
......@@ -4,8 +4,8 @@ var x = {
x: 12,
y: "abc",
z: function (x) {
return a
},
return a
},
abc: 15
},
z: 12
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment