aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-15 15:05:06 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-15 18:56:10 +0000
commitc17caaf7a604e3110048c9fa2be23345dcc1ad66 (patch)
tree43a5699c75f7d2c43f81a0b68b8c4970faaac09b /src
parentd4ca7f779d85b01a7e650abefeb8cd6502eff8e2 (diff)
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 <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/parser/qqmljs.g17
1 files changed, 12 insertions, 5 deletions
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<AST::FunctionDeclaration*>(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: {