|
|
@@ -2215,7 +2215,6 @@ void Parser::AddToNodeList(ParseNode ** ppnodeList, ParseNode *** pppnodeLast,
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //
|
|
|
Assert(*ppnodeList);
|
|
|
Assert(**pppnodeLast);
|
|
|
|
|
|
@@ -2398,7 +2397,7 @@ void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* impor
|
|
|
|
|
|
if (!(m_token.IsIdentifier() || m_token.IsReservedWord()))
|
|
|
{
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRTokenAfter, GetTokenString(m_token.tk), GetTokenString(GetScanner()->GetPrevious()));
|
|
|
}
|
|
|
|
|
|
IdentPtr identifierName = m_token.GetIdentifier(this->GetHashTbl());
|
|
|
@@ -2412,7 +2411,7 @@ void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* impor
|
|
|
// We have the pattern "IdentifierName as"
|
|
|
if (!CheckContextualKeyword(wellKnownPropertyPids.as))
|
|
|
{
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRInvalidIdentifier, m_token.GetIdentifier(this->GetHashTbl())->Psz(), identifierName->Psz());
|
|
|
}
|
|
|
|
|
|
this->GetScanner()->Scan();
|
|
|
@@ -2437,7 +2436,7 @@ void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* impor
|
|
|
{
|
|
|
// If we are parsing an import statement and this ImportSpecifier clause did not have
|
|
|
// 'as ImportedBinding' at the end of it, identifierName must be a BindingIdentifier.
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRnoIdent);
|
|
|
}
|
|
|
|
|
|
if (m_token.tk == tkComma)
|
|
|
@@ -2460,7 +2459,7 @@ void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* impor
|
|
|
}
|
|
|
|
|
|
// Final token in a named import or export clause must be a '}'
|
|
|
- ChkCurTokNoScan(tkRCurly, ERRsyntax);
|
|
|
+ ChkCurTokNoScan(tkRCurly, ERRnoRcurly);
|
|
|
}
|
|
|
|
|
|
IdentPtrList* Parser::GetRequestedModulesList()
|
|
|
@@ -2668,12 +2667,12 @@ void Parser::ParseImportClause(ModuleImportOrExportEntryList* importEntryList, b
|
|
|
this->GetScanner()->Scan();
|
|
|
if (!CheckContextualKeyword(wellKnownPropertyPids.as))
|
|
|
{
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRValidIfFollowedBy, _u("import *"), _u("as"));
|
|
|
}
|
|
|
|
|
|
// Token following 'as' must be a binding identifier.
|
|
|
this->GetScanner()->Scan();
|
|
|
- ChkCurTokNoScan(tkID, ERRsyntax);
|
|
|
+ ChkCurTokNoScan(tkID, ERRnoIdent);
|
|
|
|
|
|
if (buildAST)
|
|
|
{
|
|
|
@@ -2688,7 +2687,7 @@ void Parser::ParseImportClause(ModuleImportOrExportEntryList* importEntryList, b
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRTokenAfter, GetTokenString(m_token.tk), GetTokenString(this->GetScanner()->GetPrevious()));
|
|
|
}
|
|
|
|
|
|
this->GetScanner()->Scan();
|
|
|
@@ -2708,17 +2707,22 @@ void Parser::ParseImportClause(ModuleImportOrExportEntryList* importEntryList, b
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool Parser::IsImportOrExportStatementValidHere()
|
|
|
+void Parser::CheckIfImportOrExportStatementValidHere()
|
|
|
{
|
|
|
ParseNodeFnc * curFunc = GetCurrentFunctionNode();
|
|
|
|
|
|
- // Import must be located in the top scope of the module body.
|
|
|
- return curFunc->nop == knopFncDecl
|
|
|
- && curFunc->IsModule()
|
|
|
- && this->m_currentBlockInfo->pnodeBlock == curFunc->pnodeBodyScope
|
|
|
- && (this->m_grfscr & fscrEvalCode) != fscrEvalCode
|
|
|
- && this->m_tryCatchOrFinallyDepth == 0
|
|
|
- && !this->m_disallowImportExportStmt;
|
|
|
+ if (curFunc->nop != knopFncDecl || !curFunc->IsModule())
|
|
|
+ {
|
|
|
+ Error(ERRModuleImportOrExportInScript);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this->m_currentBlockInfo->pnodeBlock != curFunc->pnodeBodyScope
|
|
|
+ || (this->m_grfscr & fscrEvalCode) == fscrEvalCode
|
|
|
+ || this->m_tryCatchOrFinallyDepth != 0
|
|
|
+ || this->m_disallowImportExportStmt)
|
|
|
+ {
|
|
|
+ Error(ERRInvalidModuleImportOrExport);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool Parser::IsTopLevelModuleFunc()
|
|
|
@@ -2774,10 +2778,7 @@ ParseNodePtr Parser::ParseImport()
|
|
|
|
|
|
this->GetScanner()->SeekTo(parsedImport);
|
|
|
|
|
|
- if (!IsImportOrExportStatementValidHere())
|
|
|
- {
|
|
|
- Error(ERRInvalidModuleImportOrExport);
|
|
|
- }
|
|
|
+ CheckIfImportOrExportStatementValidHere();
|
|
|
|
|
|
// We just parsed an import token. Next valid token is *, {, string constant, or binding identifier.
|
|
|
this->GetScanner()->Scan();
|
|
|
@@ -2833,7 +2834,7 @@ IdentPtr Parser::ParseImportOrExportFromClause(bool throwIfNotFound)
|
|
|
this->GetScanner()->Scan();
|
|
|
|
|
|
// Token following the 'from' token must be a string constant - the module specifier.
|
|
|
- ChkCurTokNoScan(tkStrCon, ERRsyntax);
|
|
|
+ ChkCurTokNoScan(tkStrCon, ERRValidIfFollowedBy, _u("'from'"), _u("a module specifier."));
|
|
|
|
|
|
if (buildAST)
|
|
|
{
|
|
|
@@ -2844,7 +2845,7 @@ IdentPtr Parser::ParseImportOrExportFromClause(bool throwIfNotFound)
|
|
|
}
|
|
|
else if (throwIfNotFound)
|
|
|
{
|
|
|
- Error(ERRsyntax);
|
|
|
+ Error(ERRMissingFrom);
|
|
|
}
|
|
|
|
|
|
return moduleSpecifier;
|
|
|
@@ -2997,10 +2998,7 @@ ParseNodePtr Parser::ParseExportDeclaration(bool *needTerminator)
|
|
|
Assert(m_scriptContext->GetConfig()->IsES6ModuleEnabled());
|
|
|
Assert(m_token.tk == tkEXPORT);
|
|
|
|
|
|
- if (!IsImportOrExportStatementValidHere())
|
|
|
- {
|
|
|
- Error(ERRInvalidModuleImportOrExport);
|
|
|
- }
|
|
|
+ CheckIfImportOrExportStatementValidHere();
|
|
|
|
|
|
ParseNodePtr pnode = nullptr;
|
|
|
IdentPtr moduleIdentifier = nullptr;
|
|
|
@@ -8938,7 +8936,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
|
|
|
? !PHASE_OFF_RAW(Js::EarlyReferenceErrorsPhase, m_sourceContextInfo->sourceContextId, GetCurrentFunctionNode()->functionId)
|
|
|
: !PHASE_OFF1(Js::EarlyReferenceErrorsPhase)))
|
|
|
{
|
|
|
- Error(JSERR_CantAssignTo);
|
|
|
+ Error(ERRInvalidAsgTarget);
|
|
|
}
|
|
|
TrackAssignment<buildAST>(pnodeT, &operandToken);
|
|
|
if (buildAST)
|
|
|
@@ -9118,7 +9116,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
|
|
|
? !PHASE_OFF_RAW(Js::EarlyReferenceErrorsPhase, m_sourceContextInfo->sourceContextId, GetCurrentFunctionNode()->functionId)
|
|
|
: !PHASE_OFF1(Js::EarlyReferenceErrorsPhase)))
|
|
|
{
|
|
|
- Error(JSERR_CantAssignTo);
|
|
|
+ Error(ERRInvalidAsgTarget);
|
|
|
}
|
|
|
TrackAssignment<buildAST>(pnode, &term);
|
|
|
fCanAssign = FALSE;
|
|
|
@@ -9205,7 +9203,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
|
|
|
? !PHASE_OFF_RAW(Js::EarlyReferenceErrorsPhase, m_sourceContextInfo->sourceContextId, GetCurrentFunctionNode()->functionId)
|
|
|
: !PHASE_OFF1(Js::EarlyReferenceErrorsPhase)))
|
|
|
{
|
|
|
- Error(JSERR_CantAssignTo);
|
|
|
+ Error(ERRInvalidAsgTarget);
|
|
|
// No recovery necessary since this is a semantic, not structural, error.
|
|
|
}
|
|
|
}
|