From c17caaf7a604e3110048c9fa2be23345dcc1ad66 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 15 Aug 2018 15:05:06 +0200 Subject: Fix the name of anonymous generators and function declarations The spec says in 14.4.12 that an anonymous generator declaration can only occur as part of the export declaration. The same applies to anonymous function declarations in 14.1.20. It is only in the default export declaration rule that we can detect that we have an anonymous declaration/generator, so that is where we implement the step of setting "default" as the function name. It is safe to use an empty string in GeneratorDeclaration_Default and FunctionDeclaration_Default because that rule is only referenced from HoistableDeclaration_Default, which in turn is only referenced from ExportDeclaration. Change-Id: Ibd341b941f67cbcc727da4df23af04af313b6251 Reviewed-by: Lars Knoll --- src/qml/parser/qqmljs.g | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index e5ab6e5c5c..e4c103938b 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -3483,9 +3483,8 @@ FunctionDeclaration_Default: FunctionDeclaration; FunctionDeclaration_Default: Function T_LPAREN FormalParameters T_RPAREN FunctionLBrace FunctionBody FunctionRBrace; /. case $rule_number: { - AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(stringRef(1), sym(3).FormalParameterList, sym(6).StatementList); + AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList); node->functionToken = loc(1); - node->identifierToken = loc(1); node->lparenToken = loc(2); node->rparenToken = loc(4); node->lbraceToken = loc(5); @@ -3766,9 +3765,8 @@ GeneratorDeclaration_Default: GeneratorDeclaration; GeneratorDeclaration_Default: Function T_STAR GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace; /. case $rule_number: { - AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(stringRef(1), sym(4).FormalParameterList, sym(7).StatementList); + AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(4).FormalParameterList, sym(7).StatementList); node->functionToken = loc(1); - node->identifierToken = loc(1); node->lparenToken = loc(3); node->rparenToken = loc(5); node->lbraceToken = loc(6); @@ -4226,7 +4224,16 @@ ExportDeclaration: T_EXPORT Declaration; } break; ./ ExportDeclaration: T_EXPORT T_DEFAULT ExportDeclarationLookahead T_FORCE_DECLARATION HoistableDeclaration_Default; -/. case $rule_number: Q_FALLTHROUGH(); ./ +/. + case $rule_number: { + if (auto *f = AST::cast(sym(5).Node)) { + if (f->name.isEmpty()) { + f->name = stringRef(2); + f->identifierToken = loc(2); + } + } + } Q_FALLTHROUGH(); +./ ExportDeclaration: T_EXPORT T_DEFAULT ExportDeclarationLookahead T_FORCE_DECLARATION ClassDeclaration_Default; /. case $rule_number: { -- cgit v1.2.3