Skip to content

Commit 8240244

Browse files
author
Kenji Fukuda
committed
Modifying UnitTestFramework to give more useful messages and in an easier to understand way.
Adding more coverage for strict mode and extra label test cases. Condensing preexisting label tests into the new test file which all follow the unit test framework now.
1 parent 9a9cf89 commit 8240244

21 files changed

+407
-281
lines changed

lib/Parser/Parse.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8508,6 +8508,10 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
85088508
}
85098509
}
85108510
}
8511+
else if (nop == knopAwait && m_token.tk == tkColon)
8512+
{
8513+
Error(ERRAwaitAsLabelInAsync);
8514+
}
85118515
else
85128516
{
85138517
// Disallow spread after a unary operator.
@@ -9684,6 +9688,10 @@ ParseNodePtr Parser::ParseStatement()
96849688
switch (tok)
96859689
{
96869690
case tkEOF:
9691+
if (labelledStatement)
9692+
{
9693+
Error(ERRLabelFollowedByEOF);
9694+
}
96879695
if (buildAST)
96889696
{
96899697
pnode = nullptr;
@@ -9710,7 +9718,11 @@ ParseNodePtr Parser::ParseStatement()
97109718
ParseNodeFnc* pNodeFnc = (ParseNodeFnc*)pnode;
97119719
if (labelledStatement)
97129720
{
9713-
if (pNodeFnc->IsAsync())
9721+
if (IsStrictMode())
9722+
{
9723+
Error(ERRFunctionAfterLabelInStrict);
9724+
}
9725+
else if (pNodeFnc->IsAsync())
97149726
{
97159727
Error(ERRLabelBeforeAsyncFncDeclaration);
97169728
}

lib/Parser/perrors.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ LSC_ERROR_MSG(1089, ERRInvalidLHSInFor, "Invalid left-hand side in for loop")
105105
LSC_ERROR_MSG(1090, ERRLabelBeforeLexicalDeclaration, "Labels not allowed before lexical declaration")
106106
LSC_ERROR_MSG(1091, ERRLabelBeforeGeneratorDeclaration, "Labels not allowed before generator declaration")
107107
LSC_ERROR_MSG(1092, ERRLabelBeforeAsyncFncDeclaration, "Labels not allowed before async function declaration")
108-
LSC_ERROR_MSG(1093, ERRLabelBeforeClassDeclaration, "Labels not allowed before class declaration")
108+
LSC_ERROR_MSG(1093, ERRLabelBeforeClassDeclaration, "Labels not allowed before class declaration")
109+
LSC_ERROR_MSG(1094, ERRLabelFollowedByEOF, "Unexpected end of script after a label.")
110+
LSC_ERROR_MSG(1095, ERRFunctionAfterLabelInStrict, "Function declarations not allowed after a label in strict mode.")
111+
LSC_ERROR_MSG(1096, ERRAwaitAsLabelInAsync, "Use of 'await' as label in async function is not allowed.")

0 commit comments

Comments
 (0)