qmljs: fix arrow function reformatting

This is mainly just making sure that token that are "empty" are really
empty (to avoid writing them out in the reformatter), but still
contain the correct location (for error messages using for example
firstSourceLocation()).

Introduce a SourceLocation::zeroLength() method to make this change
simpler to do.

QtCreator does not run qlalr automatically, so it is "polluted" by the
updated generated files.

Fixes: QTCREATORBUG-25198
Change-Id: I0ab19fb380ee3d9a7d9e05d104fe313468f52703
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed
2021-01-15 14:05:18 +01:00
parent 002db1fa42
commit b8d99af6fd
5 changed files with 144 additions and 116 deletions

View File

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

View File

@@ -2893,11 +2893,8 @@ case 241: {
case 512: { case 512: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList)) if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false; return false;
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionDeclaration(QStringView(), /*type annotation*/nullptr);
sym(3).FormalParameterList,
sym(7).StatementList,
/*type annotation*/ nullptr);
node->functionToken = loc(1); node->functionToken = loc(1);
node->lparenToken = loc(2); node->lparenToken = loc(2);
node->rparenToken = loc(4); node->rparenToken = loc(4);
@@ -2928,11 +2925,8 @@ case 241: {
case 514: { case 514: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList)) if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false; return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionExpression(QStringView(), /*type annotation*/nullptr);
sym(3).FormalParameterList,
sym(7).StatementList,
/*type annotation*/ nullptr);
node->functionToken = loc(1); node->functionToken = loc(1);
node->lparenToken = loc(2); node->lparenToken = loc(2);
node->rparenToken = loc(4); node->rparenToken = loc(4);
@@ -3001,34 +2995,32 @@ case 241: {
case 528: { case 528: {
AST::ReturnStatement *ret = new (pool) AST::ReturnStatement(sym(4).Expression); AST::ReturnStatement *ret = new (pool) AST::ReturnStatement(sym(4).Expression);
const auto zeroLength = [](SourceLocation l){ l.length = 0; return l; }; ret->returnToken = sym(4).Node->firstSourceLocation().zeroLength();
ret->returnToken = zeroLength(sym(4).Node->firstSourceLocation()); ret->semicolonToken = sym(4).Node->lastSourceLocation().zeroLengthEnd(driver->code());
ret->semicolonToken = zeroLength(sym(4).Node->lastSourceLocation());
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish(); AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
AST::FunctionExpression *f = new (pool) AST::FunctionExpression *f = new (pool)
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements); AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
f->isArrowFunction = true; f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1); f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().zeroLength() : loc(1).zeroLength();
f->lbraceToken = zeroLength(sym(4).Node->firstSourceLocation()); f->lbraceToken = sym(4).Node->firstSourceLocation().zeroLength();
f->rbraceToken = zeroLength(sym(4).Node->lastSourceLocation()); f->rbraceToken = sym(4).Node->lastSourceLocation().zeroLengthEnd(driver->code());
sym(1).Node = f; sym(1).Node = f;
} break; } break;
#line 4035 "qmljs.g" #line 4036 "qmljs.g"
case 529: Q_FALLTHROUGH(); case 529: Q_FALLTHROUGH();
#line 4037 "qmljs.g" #line 4038 "qmljs.g"
case 530: { case 530: {
AST::FunctionExpression *f = new (pool) AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
f->isArrowFunction = true; f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1); f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().zeroLength() : loc(1).zeroLength();
f->lbraceToken = loc(5); f->lbraceToken = loc(5);
f->rbraceToken = loc(7); f->rbraceToken = loc(7);
sym(1).Node = f; sym(1).Node = f;
} break; } break;
#line 4049 "qmljs.g" #line 4050 "qmljs.g"
case 531: { case 531: {
AST::PatternElement *e = new (pool) AST::PatternElement(stringRef(1), /*type annotation*/nullptr, nullptr, AST::PatternElement::Binding); AST::PatternElement *e = new (pool) AST::PatternElement(stringRef(1), /*type annotation*/nullptr, nullptr, AST::PatternElement::Binding);
@@ -3036,7 +3028,7 @@ case 241: {
sym(1).FormalParameterList = (new (pool) AST::FormalParameterList(nullptr, e))->finish(pool); sym(1).FormalParameterList = (new (pool) AST::FormalParameterList(nullptr, e))->finish(pool);
} break; } break;
#line 4060 "qmljs.g" #line 4061 "qmljs.g"
case 532: { case 532: {
if (coverExpressionType != CE_FormalParameterList) { if (coverExpressionType != CE_FormalParameterList) {
@@ -3050,14 +3042,14 @@ case 241: {
} }
} break; } break;
#line 4078 "qmljs.g" #line 4079 "qmljs.g"
case 533: { case 533: {
if (lookaheadToken(lexer) == T_LBRACE) if (lookaheadToken(lexer) == T_LBRACE)
pushToken(T_FORCE_BLOCK); pushToken(T_FORCE_BLOCK);
} break; } break;
#line 4086 "qmljs.g" #line 4087 "qmljs.g"
case 534: { case 534: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList)) if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
@@ -3073,7 +3065,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4103 "qmljs.g" #line 4104 "qmljs.g"
case 535: { case 535: {
if (!ensureNoFunctionTypeAnnotations(sym(6).TypeAnnotation, sym(4).FormalParameterList)) if (!ensureNoFunctionTypeAnnotations(sym(6).TypeAnnotation, sym(4).FormalParameterList))
@@ -3090,7 +3082,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4122 "qmljs.g" #line 4123 "qmljs.g"
case 536: { case 536: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, /*formals*/nullptr)) if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, /*formals*/nullptr))
@@ -3106,7 +3098,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4139 "qmljs.g" #line 4140 "qmljs.g"
case 537: { case 537: {
if (!ensureNoFunctionTypeAnnotations(sym(6).TypeAnnotation, sym(4).FormalParameterList)) if (!ensureNoFunctionTypeAnnotations(sym(6).TypeAnnotation, sym(4).FormalParameterList))
@@ -3122,27 +3114,27 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4157 "qmljs.g" #line 4158 "qmljs.g"
case 538: { case 538: {
AST::FormalParameterList *node = (new (pool) AST::FormalParameterList(nullptr, sym(1).PatternElement))->finish(pool); AST::FormalParameterList *node = (new (pool) AST::FormalParameterList(nullptr, sym(1).PatternElement))->finish(pool);
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4165 "qmljs.g" #line 4166 "qmljs.g"
case 539: { case 539: {
lexer->enterGeneratorBody(); lexer->enterGeneratorBody();
} break; } break;
#line 4172 "qmljs.g" #line 4173 "qmljs.g"
case 540: { case 540: {
--functionNestingLevel; --functionNestingLevel;
lexer->leaveGeneratorBody(); lexer->leaveGeneratorBody();
} break; } break;
#line 4182 "qmljs.g" #line 4183 "qmljs.g"
case 542: { case 542: {
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(stringRef(2), sym(4).FormalParameterList, sym(7).StatementList); AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(stringRef(2), sym(4).FormalParameterList, sym(7).StatementList);
@@ -3156,11 +3148,10 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4198 "qmljs.g" #line 4199 "qmljs.g"
case 544: { case 544: {
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1); node->functionToken = loc(1);
node->lparenToken = loc(2); node->lparenToken = loc(2);
node->rparenToken = loc(4); node->rparenToken = loc(4);
@@ -3170,7 +3161,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4212 "qmljs.g" #line 4213 "qmljs.g"
case 545: { case 545: {
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(stringRef(2), sym(4).FormalParameterList, sym(7).StatementList); AST::FunctionExpression *node = new (pool) AST::FunctionExpression(stringRef(2), sym(4).FormalParameterList, sym(7).StatementList);
@@ -3185,11 +3176,10 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4228 "qmljs.g" #line 4229 "qmljs.g"
case 546: { case 546: {
AST::FunctionExpression *node = new (pool) AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1); node->functionToken = loc(1);
node->lparenToken = loc(2); node->lparenToken = loc(2);
node->rparenToken = loc(4); node->rparenToken = loc(4);
@@ -3199,9 +3189,9 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4244 "qmljs.g" #line 4245 "qmljs.g"
case 548: Q_FALLTHROUGH(); case 548: Q_FALLTHROUGH();
#line 4246 "qmljs.g" #line 4247 "qmljs.g"
case 549: { case 549: {
AST::YieldExpression *node = new (pool) AST::YieldExpression(); AST::YieldExpression *node = new (pool) AST::YieldExpression();
@@ -3209,9 +3199,9 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4255 "qmljs.g" #line 4256 "qmljs.g"
case 550: Q_FALLTHROUGH(); case 550: Q_FALLTHROUGH();
#line 4257 "qmljs.g" #line 4258 "qmljs.g"
case 551: { case 551: {
AST::YieldExpression *node = new (pool) AST::YieldExpression(sym(3).Expression); AST::YieldExpression *node = new (pool) AST::YieldExpression(sym(3).Expression);
@@ -3220,9 +3210,9 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4267 "qmljs.g" #line 4268 "qmljs.g"
case 552: Q_FALLTHROUGH(); case 552: Q_FALLTHROUGH();
#line 4269 "qmljs.g" #line 4270 "qmljs.g"
case 553: { case 553: {
AST::YieldExpression *node = new (pool) AST::YieldExpression(sym(2).Expression); AST::YieldExpression *node = new (pool) AST::YieldExpression(sym(2).Expression);
@@ -3230,7 +3220,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4279 "qmljs.g" #line 4280 "qmljs.g"
case 554: { case 554: {
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(stringRef(2), sym(3).Expression, sym(5).ClassElementList); AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(stringRef(2), sym(3).Expression, sym(5).ClassElementList);
@@ -3241,7 +3231,7 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4291 "qmljs.g" #line 4292 "qmljs.g"
case 555: { case 555: {
AST::ClassExpression *node = new (pool) AST::ClassExpression(stringRef(2), sym(3).Expression, sym(5).ClassElementList); AST::ClassExpression *node = new (pool) AST::ClassExpression(stringRef(2), sym(3).Expression, sym(5).ClassElementList);
@@ -3252,68 +3242,66 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4303 "qmljs.g" #line 4304 "qmljs.g"
case 556: { case 556: {
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1); node->classToken = loc(1);
node->lbraceToken = loc(3); node->lbraceToken = loc(3);
node->rbraceToken = loc(5); node->rbraceToken = loc(5);
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4314 "qmljs.g" #line 4315 "qmljs.g"
case 557: { case 557: {
AST::ClassExpression *node = new (pool) AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1); node->classToken = loc(1);
node->lbraceToken = loc(3); node->lbraceToken = loc(3);
node->rbraceToken = loc(5); node->rbraceToken = loc(5);
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4327 "qmljs.g" #line 4328 "qmljs.g"
case 559: { case 559: {
lexer->setStaticIsKeyword(true); lexer->setStaticIsKeyword(true);
} break; } break;
#line 4334 "qmljs.g" #line 4335 "qmljs.g"
case 560: case 560:
#line 4336 "qmljs.g" #line 4337 "qmljs.g"
case 561: { case 561: {
lexer->setStaticIsKeyword(false); lexer->setStaticIsKeyword(false);
} break; } break;
#line 4343 "qmljs.g" #line 4344 "qmljs.g"
case 562: { case 562: {
sym(1).Node = nullptr; sym(1).Node = nullptr;
} break; } break;
#line 4350 "qmljs.g" #line 4351 "qmljs.g"
case 563: { case 563: {
sym(1).Node = sym(2).Node; sym(1).Node = sym(2).Node;
} break; } break;
#line 4357 "qmljs.g" #line 4358 "qmljs.g"
case 564: { case 564: {
sym(1).Node = nullptr; sym(1).Node = nullptr;
} break; } break;
#line 4364 "qmljs.g" #line 4365 "qmljs.g"
case 565: { case 565: {
if (sym(1).Node) if (sym(1).Node)
sym(1).Node = sym(1).ClassElementList->finish(); sym(1).Node = sym(1).ClassElementList->finish();
} break; } break;
#line 4374 "qmljs.g" #line 4375 "qmljs.g"
case 567: { case 567: {
if (sym(1).Node) { if (sym(1).Node) {
@@ -3324,14 +3312,14 @@ case 241: {
} }
} break; } break;
#line 4386 "qmljs.g" #line 4387 "qmljs.g"
case 568: { case 568: {
AST::ClassElementList *node = new (pool) AST::ClassElementList(sym(1).PatternProperty, false); AST::ClassElementList *node = new (pool) AST::ClassElementList(sym(1).PatternProperty, false);
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4394 "qmljs.g" #line 4395 "qmljs.g"
case 569: { case 569: {
lexer->setStaticIsKeyword(true); lexer->setStaticIsKeyword(true);
@@ -3339,56 +3327,56 @@ case 241: {
sym(1).Node = node; sym(1).Node = node;
} break; } break;
#line 4403 "qmljs.g" #line 4404 "qmljs.g"
case 570: { case 570: {
sym(1).Node = nullptr; sym(1).Node = nullptr;
} break; } break;
#line 4412 "qmljs.g" #line 4413 "qmljs.g"
case 571: { case 571: {
sym(1).Node = nullptr; sym(1).Node = nullptr;
} break; } break;
#line 4421 "qmljs.g" #line 4422 "qmljs.g"
case 573: { case 573: {
sym(1).Node = new (pool) AST::Program(sym(1).StatementList->finish()); sym(1).Node = new (pool) AST::Program(sym(1).StatementList->finish());
} break; } break;
#line 4428 "qmljs.g" #line 4429 "qmljs.g"
case 574: { case 574: {
sym(1).Node = new (pool) AST::ESModule(sym(1).StatementList); sym(1).Node = new (pool) AST::ESModule(sym(1).StatementList);
} break; } break;
#line 4434 "qmljs.g" #line 4435 "qmljs.g"
case 575: { case 575: {
sym(1).StatementList = sym(1).StatementList->finish(); sym(1).StatementList = sym(1).StatementList->finish();
} break; } break;
#line 4441 "qmljs.g" #line 4442 "qmljs.g"
case 576: { case 576: {
sym(1).StatementList = nullptr; sym(1).StatementList = nullptr;
} break; } break;
#line 4451 "qmljs.g" #line 4452 "qmljs.g"
case 579: { case 579: {
sym(1).StatementList = sym(1).StatementList->append(sym(2).StatementList); sym(1).StatementList = sym(1).StatementList->append(sym(2).StatementList);
} break; } break;
#line 4459 "qmljs.g" #line 4460 "qmljs.g"
case 580: Q_FALLTHROUGH(); case 580: Q_FALLTHROUGH();
#line 4461 "qmljs.g" #line 4462 "qmljs.g"
case 581: { case 581: {
sym(1).StatementList = new (pool) AST::StatementList(sym(1).Node); sym(1).StatementList = new (pool) AST::StatementList(sym(1).Node);
} break; } break;
#line 4470 "qmljs.g" #line 4471 "qmljs.g"
case 583: { case 583: {
auto decl = new (pool) AST::ImportDeclaration(sym(2).ImportClause, sym(3).FromClause); auto decl = new (pool) AST::ImportDeclaration(sym(2).ImportClause, sym(3).FromClause);
@@ -3396,7 +3384,7 @@ case 241: {
sym(1).Node = decl; sym(1).Node = decl;
} break; } break;
#line 4478 "qmljs.g" #line 4479 "qmljs.g"
case 584: { case 584: {
auto decl = new (pool) AST::ImportDeclaration(stringRef(2)); auto decl = new (pool) AST::ImportDeclaration(stringRef(2));
@@ -3405,7 +3393,7 @@ case 241: {
sym(1).Node = decl; sym(1).Node = decl;
} break; } break;
#line 4488 "qmljs.g" #line 4489 "qmljs.g"
case 585: { case 585: {
auto clause = new (pool) AST::ImportClause(stringRef(1)); auto clause = new (pool) AST::ImportClause(stringRef(1));
@@ -3413,19 +3401,19 @@ case 241: {
sym(1).ImportClause = clause; sym(1).ImportClause = clause;
} break; } break;
#line 4496 "qmljs.g" #line 4497 "qmljs.g"
case 586: { case 586: {
sym(1).ImportClause = new (pool) AST::ImportClause(sym(1).NameSpaceImport); sym(1).ImportClause = new (pool) AST::ImportClause(sym(1).NameSpaceImport);
} break; } break;
#line 4502 "qmljs.g" #line 4503 "qmljs.g"
case 587: { case 587: {
sym(1).ImportClause = new (pool) AST::ImportClause(sym(1).NamedImports); sym(1).ImportClause = new (pool) AST::ImportClause(sym(1).NamedImports);
} break; } break;
#line 4508 "qmljs.g" #line 4509 "qmljs.g"
case 588: { case 588: {
auto importClause = new (pool) AST::ImportClause(stringRef(1), sym(3).NameSpaceImport); auto importClause = new (pool) AST::ImportClause(stringRef(1), sym(3).NameSpaceImport);
@@ -3433,7 +3421,7 @@ case 241: {
sym(1).ImportClause = importClause; sym(1).ImportClause = importClause;
} break; } break;
#line 4516 "qmljs.g" #line 4517 "qmljs.g"
case 589: { case 589: {
auto importClause = new (pool) AST::ImportClause(stringRef(1), sym(3).NamedImports); auto importClause = new (pool) AST::ImportClause(stringRef(1), sym(3).NamedImports);
@@ -3441,7 +3429,7 @@ case 241: {
sym(1).ImportClause = importClause; sym(1).ImportClause = importClause;
} break; } break;
#line 4527 "qmljs.g" #line 4528 "qmljs.g"
case 591: { case 591: {
auto import = new (pool) AST::NameSpaceImport(stringRef(3)); auto import = new (pool) AST::NameSpaceImport(stringRef(3));
@@ -3450,7 +3438,7 @@ case 241: {
sym(1).NameSpaceImport = import; sym(1).NameSpaceImport = import;
} break; } break;
#line 4537 "qmljs.g" #line 4538 "qmljs.g"
case 592: { case 592: {
auto namedImports = new (pool) AST::NamedImports(); auto namedImports = new (pool) AST::NamedImports();
@@ -3459,7 +3447,7 @@ case 241: {
sym(1).NamedImports = namedImports; sym(1).NamedImports = namedImports;
} break; } break;
#line 4546 "qmljs.g" #line 4547 "qmljs.g"
case 593: { case 593: {
auto namedImports = new (pool) AST::NamedImports(sym(2).ImportsList->finish()); auto namedImports = new (pool) AST::NamedImports(sym(2).ImportsList->finish());
@@ -3468,7 +3456,7 @@ case 241: {
sym(1).NamedImports = namedImports; sym(1).NamedImports = namedImports;
} break; } break;
#line 4555 "qmljs.g" #line 4556 "qmljs.g"
case 594: { case 594: {
auto namedImports = new (pool) AST::NamedImports(sym(2).ImportsList->finish()); auto namedImports = new (pool) AST::NamedImports(sym(2).ImportsList->finish());
@@ -3477,7 +3465,7 @@ case 241: {
sym(1).NamedImports = namedImports; sym(1).NamedImports = namedImports;
} break; } break;
#line 4565 "qmljs.g" #line 4566 "qmljs.g"
case 595: { case 595: {
auto clause = new (pool) AST::FromClause(stringRef(2)); auto clause = new (pool) AST::FromClause(stringRef(2));
@@ -3486,7 +3474,7 @@ case 241: {
sym(1).FromClause = clause; sym(1).FromClause = clause;
} break; } break;
#line 4575 "qmljs.g" #line 4576 "qmljs.g"
case 596: { case 596: {
auto importsList = new (pool) AST::ImportsList(sym(1).ImportSpecifier); auto importsList = new (pool) AST::ImportsList(sym(1).ImportSpecifier);
@@ -3494,7 +3482,7 @@ case 241: {
sym(1).ImportsList = importsList; sym(1).ImportsList = importsList;
} break; } break;
#line 4583 "qmljs.g" #line 4584 "qmljs.g"
case 597: { case 597: {
auto importsList = new (pool) AST::ImportsList(sym(1).ImportsList, sym(3).ImportSpecifier); auto importsList = new (pool) AST::ImportsList(sym(1).ImportsList, sym(3).ImportSpecifier);
@@ -3502,7 +3490,7 @@ case 241: {
sym(1).ImportsList = importsList; sym(1).ImportsList = importsList;
} break; } break;
#line 4595 "qmljs.g" #line 4596 "qmljs.g"
case 598: { case 598: {
auto importSpecifier = new (pool) AST::ImportSpecifier(stringRef(1)); auto importSpecifier = new (pool) AST::ImportSpecifier(stringRef(1));
@@ -3510,7 +3498,7 @@ case 241: {
sym(1).ImportSpecifier = importSpecifier; sym(1).ImportSpecifier = importSpecifier;
} break; } break;
#line 4603 "qmljs.g" #line 4604 "qmljs.g"
case 599: { case 599: {
auto importSpecifier = new (pool) AST::ImportSpecifier(stringRef(1), stringRef(3)); auto importSpecifier = new (pool) AST::ImportSpecifier(stringRef(1), stringRef(3));
@@ -3519,7 +3507,7 @@ case 241: {
sym(1).ImportSpecifier = importSpecifier; sym(1).ImportSpecifier = importSpecifier;
} break; } break;
#line 4620 "qmljs.g" #line 4621 "qmljs.g"
case 602: { case 602: {
int token = lookaheadToken(lexer); int token = lookaheadToken(lexer);
@@ -3527,7 +3515,7 @@ case 241: {
pushToken(T_FORCE_DECLARATION); pushToken(T_FORCE_DECLARATION);
} break; } break;
#line 4629 "qmljs.g" #line 4630 "qmljs.g"
case 603: { case 603: {
auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(3).FromClause); auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(3).FromClause);
@@ -3535,7 +3523,7 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4637 "qmljs.g" #line 4638 "qmljs.g"
case 604: { case 604: {
auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(2).ExportClause, sym(3).FromClause); auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(2).ExportClause, sym(3).FromClause);
@@ -3543,7 +3531,7 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4645 "qmljs.g" #line 4646 "qmljs.g"
case 605: { case 605: {
auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(2).ExportClause); auto exportDeclaration = new (pool) AST::ExportDeclaration(sym(2).ExportClause);
@@ -3551,9 +3539,9 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4653 "qmljs.g" #line 4654 "qmljs.g"
case 606: Q_FALLTHROUGH(); case 606: Q_FALLTHROUGH();
#line 4655 "qmljs.g" #line 4656 "qmljs.g"
case 607: { case 607: {
auto exportDeclaration = new (pool) AST::ExportDeclaration(/*exportDefault=*/false, sym(2).Node); auto exportDeclaration = new (pool) AST::ExportDeclaration(/*exportDefault=*/false, sym(2).Node);
@@ -3561,7 +3549,7 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4663 "qmljs.g" #line 4664 "qmljs.g"
case 608: { case 608: {
if (auto *f = AST::cast<AST::FunctionDeclaration*>(sym(5).Node)) { if (auto *f = AST::cast<AST::FunctionDeclaration*>(sym(5).Node)) {
@@ -3572,7 +3560,7 @@ case 241: {
} }
} Q_FALLTHROUGH(); } Q_FALLTHROUGH();
#line 4674 "qmljs.g" #line 4675 "qmljs.g"
case 609: { case 609: {
// Emulate 15.2.3.11 // Emulate 15.2.3.11
@@ -3588,7 +3576,7 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4690 "qmljs.g" #line 4691 "qmljs.g"
case 610: { case 610: {
// if lhs is an identifier expression and rhs is an anonymous function expression, we need to assign the name of lhs to the function // if lhs is an identifier expression and rhs is an anonymous function expression, we need to assign the name of lhs to the function
@@ -3604,7 +3592,7 @@ case 241: {
sym(1).ExportDeclaration = exportDeclaration; sym(1).ExportDeclaration = exportDeclaration;
} break; } break;
#line 4707 "qmljs.g" #line 4708 "qmljs.g"
case 611: { case 611: {
auto exportClause = new (pool) AST::ExportClause(); auto exportClause = new (pool) AST::ExportClause();
@@ -3613,7 +3601,7 @@ case 241: {
sym(1).ExportClause = exportClause; sym(1).ExportClause = exportClause;
} break; } break;
#line 4716 "qmljs.g" #line 4717 "qmljs.g"
case 612: { case 612: {
auto exportClause = new (pool) AST::ExportClause(sym(2).ExportsList->finish()); auto exportClause = new (pool) AST::ExportClause(sym(2).ExportsList->finish());
@@ -3622,7 +3610,7 @@ case 241: {
sym(1).ExportClause = exportClause; sym(1).ExportClause = exportClause;
} break; } break;
#line 4725 "qmljs.g" #line 4726 "qmljs.g"
case 613: { case 613: {
auto exportClause = new (pool) AST::ExportClause(sym(2).ExportsList->finish()); auto exportClause = new (pool) AST::ExportClause(sym(2).ExportsList->finish());
@@ -3631,19 +3619,19 @@ case 241: {
sym(1).ExportClause = exportClause; sym(1).ExportClause = exportClause;
} break; } break;
#line 4735 "qmljs.g" #line 4736 "qmljs.g"
case 614: { case 614: {
sym(1).ExportsList = new (pool) AST::ExportsList(sym(1).ExportSpecifier); sym(1).ExportsList = new (pool) AST::ExportsList(sym(1).ExportSpecifier);
} break; } break;
#line 4741 "qmljs.g" #line 4742 "qmljs.g"
case 615: { case 615: {
sym(1).ExportsList = new (pool) AST::ExportsList(sym(1).ExportsList, sym(3).ExportSpecifier); sym(1).ExportsList = new (pool) AST::ExportsList(sym(1).ExportsList, sym(3).ExportSpecifier);
} break; } break;
#line 4748 "qmljs.g" #line 4749 "qmljs.g"
case 616: { case 616: {
auto exportSpecifier = new (pool) AST::ExportSpecifier(stringRef(1)); auto exportSpecifier = new (pool) AST::ExportSpecifier(stringRef(1));
@@ -3651,7 +3639,7 @@ case 241: {
sym(1).ExportSpecifier = exportSpecifier; sym(1).ExportSpecifier = exportSpecifier;
} break; } break;
#line 4756 "qmljs.g" #line 4757 "qmljs.g"
case 617: { case 617: {
auto exportSpecifier = new (pool) AST::ExportSpecifier(stringRef(1), stringRef(3)); auto exportSpecifier = new (pool) AST::ExportSpecifier(stringRef(1), stringRef(3));
@@ -3660,7 +3648,7 @@ case 241: {
sym(1).ExportSpecifier = exportSpecifier; sym(1).ExportSpecifier = exportSpecifier;
} break; } break;
#line 4767 "qmljs.g" #line 4768 "qmljs.g"
// ------------ end of switch statement // ------------ end of switch statement
} // switch } // switch

View File

@@ -304,15 +304,15 @@ protected:
#define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE 463 #define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE 463
#line 4075 "qmljs.g" #line 4076 "qmljs.g"
#define J_SCRIPT_CONCISEBODYLOOKAHEAD_RULE 533 #define J_SCRIPT_CONCISEBODYLOOKAHEAD_RULE 533
#line 4617 "qmljs.g" #line 4618 "qmljs.g"
#define J_SCRIPT_EXPORTDECLARATIONLOOKAHEAD_RULE 602 #define J_SCRIPT_EXPORTDECLARATIONLOOKAHEAD_RULE 602
#line 4901 "qmljs.g" #line 4902 "qmljs.g"
QT_QML_END_NAMESPACE QT_QML_END_NAMESPACE

View File

@@ -27,6 +27,8 @@
#include "qmljsglobal_p.h" #include "qmljsglobal_p.h"
#include <QtCore/QStringView>
// //
// W A R N I N G // W A R N I N G
// ------------- // -------------
@@ -55,6 +57,30 @@ public:
quint32 begin() const { return offset; } quint32 begin() const { return offset; }
quint32 end() const { return offset + length; } quint32 end() const { return offset + length; }
SourceLocation zeroLength() const { return SourceLocation(offset, 0, startLine, startColumn); }
SourceLocation zeroLengthEnd(QStringView text) const {
quint32 i = offset;
quint32 endLine = startLine;
quint32 endColumn = startColumn;
while (i < end()) {
QChar c = text.at(i);
switch (c.unicode()) {
case '\n':
if (i + 1 < end() && text.at(i + 1) == QLatin1Char('\r'))
++i;
Q_FALLTHROUGH();
case '\r':
++endLine;
++endColumn;
break;
default:
++endColumn;
}
++i;
}
return SourceLocation(offset + length, 0, endLine, endColumn);
}
// attributes // attributes
// ### encode // ### encode
quint32 offset; quint32 offset;
@@ -66,4 +92,3 @@ public:
} // namespace QmlJS } // namespace QmlJS
QT_QML_END_NAMESPACE QT_QML_END_NAMESPACE

View File

@@ -0,0 +1,16 @@
import QtQuick 2.15
Rectangle {
Component.onCompleted: {
const values = ["10", "20", "30", "40"]
const result = values.map(value => parseInt(value))
const result2 = values.map(value => parseInt(value))
const result3 = values.map(value => {
return parseInt(value)
})
const result4 = values.map((value, i) => parseInt(value) + i)
const result5 = values.map((value, i) => {
return parseInt(value) + i
})
}
}