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:
Leander Schulten
2020-12-09 16:12:36 +01:00
parent 1ae893de26
commit 7e526d9b05
4 changed files with 45 additions and 17 deletions

View File

@@ -4019,14 +4019,16 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress
/.
case $rule_number: {
AST::ReturnStatement *ret = new (pool) AST::ReturnStatement(sym(4).Expression);
ret->returnToken = sym(4).Node->firstSourceLocation();
ret->semicolonToken = sym(4).Node->lastSourceLocation();
const auto zeroLength = [](SourceLocation l){ l.length = 0; return l; };
ret->returnToken = zeroLength(sym(4).Node->firstSourceLocation());
ret->semicolonToken = zeroLength(sym(4).Node->lastSourceLocation());
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
AST::FunctionExpression *f = new (pool)
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = sym(4).Node->firstSourceLocation();
f->rbraceToken = sym(4).Node->lastSourceLocation();
f->lbraceToken = zeroLength(sym(4).Node->firstSourceLocation());
f->rbraceToken = zeroLength(sym(4).Node->lastSourceLocation());
sym(1).Node = f;
} break;
./
@@ -4039,7 +4041,7 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Fun
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = loc(6);
f->lbraceToken = loc(5);
f->rbraceToken = loc(7);
sym(1).Node = f;
} break;