forked from qt-creator/qt-creator
QmlJs: Fix reformatter for arrow functions
Fixes: QTCREATORBUG-23019 Change-Id: I6c6bee7092cb12f225ad744df2b3834dfd4bbc8f Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
This commit is contained in:
@@ -1097,7 +1097,8 @@ protected:
|
||||
{
|
||||
out(ast->returnToken);
|
||||
if (ast->expression) {
|
||||
out(" ");
|
||||
if (ast->returnToken.isValid())
|
||||
out(" ");
|
||||
accept(ast->expression);
|
||||
}
|
||||
return false;
|
||||
@@ -1218,17 +1219,32 @@ protected:
|
||||
|
||||
bool visit(FunctionExpression *ast) override
|
||||
{
|
||||
out("function ", ast->functionToken);
|
||||
if (!ast->name.isNull())
|
||||
out(ast->identifierToken);
|
||||
if (!ast->isArrowFunction) {
|
||||
out("function ", ast->functionToken);
|
||||
if (!ast->name.isNull())
|
||||
out(ast->identifierToken);
|
||||
}
|
||||
out(ast->lparenToken);
|
||||
if (ast->isArrowFunction && ast->formals && ast->formals->next)
|
||||
out("(");
|
||||
accept(ast->formals);
|
||||
if (ast->isArrowFunction && ast->formals && ast->formals->next)
|
||||
out(")");
|
||||
out(ast->rparenToken);
|
||||
if (ast->isArrowFunction && !ast->formals)
|
||||
out("()");
|
||||
out(" ");
|
||||
if (ast->isArrowFunction)
|
||||
out("=> ");
|
||||
out(ast->lbraceToken);
|
||||
if (ast->body) {
|
||||
lnAcceptIndented(ast->body);
|
||||
newLine();
|
||||
if (ast->body->next || ast->lbraceToken.isValid()) {
|
||||
lnAcceptIndented(ast->body);
|
||||
newLine();
|
||||
} else {
|
||||
// print a single statement in one line. E.g. x => x * 2
|
||||
accept(ast->body);
|
||||
}
|
||||
}
|
||||
out(ast->rbraceToken);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user