@@ -8442,6 +8442,10 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
8442
8442
}
8443
8443
}
8444
8444
}
8445
+ else if (nop == knopAwait && m_token.tk == tkColon)
8446
+ {
8447
+ Error(ERRAwaitAsLabelInAsync);
8448
+ }
8445
8449
else
8446
8450
{
8447
8451
// Disallow spread after a unary operator.
@@ -9573,6 +9577,7 @@ ParseNodePtr Parser::ParseStatement()
9573
9577
uint fnop;
9574
9578
bool expressionStmt = false;
9575
9579
bool isAsyncMethod = false;
9580
+ bool labelledStatement = false;
9576
9581
tokens tok;
9577
9582
#if EXCEPTION_RECOVERY
9578
9583
ParseNodeTryCatch * pParentTryCatch = nullptr;
@@ -9625,6 +9630,10 @@ ParseNodePtr Parser::ParseStatement()
9625
9630
switch (tok)
9626
9631
{
9627
9632
case tkEOF:
9633
+ if (labelledStatement)
9634
+ {
9635
+ Error(ERRLabelFollowedByEOF);
9636
+ }
9628
9637
if (buildAST)
9629
9638
{
9630
9639
pnode = nullptr;
@@ -9646,6 +9655,25 @@ ParseNodePtr Parser::ParseStatement()
9646
9655
{
9647
9656
pnode = ParseFncDeclCheckScope<buildAST>(fFncDeclaration | (isAsyncMethod ? fFncAsync : fFncNoFlgs));
9648
9657
}
9658
+
9659
+ Assert(pnode != nullptr);
9660
+ ParseNodeFnc* pNodeFnc = (ParseNodeFnc*)pnode;
9661
+ if (labelledStatement)
9662
+ {
9663
+ if (IsStrictMode())
9664
+ {
9665
+ Error(ERRFunctionAfterLabelInStrict);
9666
+ }
9667
+ else if (pNodeFnc->IsAsync())
9668
+ {
9669
+ Error(ERRLabelBeforeAsyncFncDeclaration);
9670
+ }
9671
+ else if (pNodeFnc->IsGenerator())
9672
+ {
9673
+ Error(ERRLabelBeforeGeneratorDeclaration);
9674
+ }
9675
+ }
9676
+
9649
9677
if (isAsyncMethod)
9650
9678
{
9651
9679
pnode->AsParseNodeFnc()->cbMin = iecpMin;
@@ -9655,7 +9683,11 @@ ParseNodePtr Parser::ParseStatement()
9655
9683
}
9656
9684
9657
9685
case tkCLASS:
9658
- if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
9686
+ if (labelledStatement)
9687
+ {
9688
+ Error(ERRLabelBeforeClassDeclaration);
9689
+ }
9690
+ else if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
9659
9691
{
9660
9692
pnode = ParseClassDecl<buildAST>(TRUE, nullptr, nullptr, nullptr);
9661
9693
}
@@ -9668,6 +9700,10 @@ ParseNodePtr Parser::ParseStatement()
9668
9700
case tkID:
9669
9701
if (m_token.GetIdentifier(this->GetHashTbl()) == wellKnownPropertyPids.let)
9670
9702
{
9703
+ if (labelledStatement)
9704
+ {
9705
+ Error(ERRLabelBeforeLexicalDeclaration);
9706
+ }
9671
9707
// We see "let" at the start of a statement. This could either be a declaration or an identifier
9672
9708
// reference. The next token determines which.
9673
9709
RestorePoint parsedLet;
@@ -9701,6 +9737,10 @@ ParseNodePtr Parser::ParseStatement()
9701
9737
9702
9738
case tkCONST:
9703
9739
case tkLET:
9740
+ if (labelledStatement)
9741
+ {
9742
+ Error(ERRLabelBeforeLexicalDeclaration);
9743
+ }
9704
9744
ichMin = this->GetScanner()->IchMinTok();
9705
9745
9706
9746
this->GetScanner()->Scan();
@@ -10570,6 +10610,7 @@ ParseNodePtr Parser::ParseStatement()
10570
10610
pLabelId->next = pLabelIdList;
10571
10611
pLabelIdList = pLabelId;
10572
10612
this->GetScanner()->Scan();
10613
+ labelledStatement = true;
10573
10614
goto LRestart;
10574
10615
}
10575
10616
0 commit comments