Skip to content

Commit 000a720

Browse files
Tagged template in optional chain is syntax error
1 parent ff7bb29 commit 000a720

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/Parser/Parse.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,11 +4203,20 @@ ParseNodePtr Parser::ParsePostfixOperators(
42034203
this->GetScanner()->Scan();
42044204
if (!m_token.IsIdentifier())
42054205
{
4206-
if (isNullPropagating && (tkLParen == m_token.tk || tkLBrack == m_token.tk))
4206+
if (isNullPropagating)
42074207
{
4208-
// Continue to parse function or index (loop)
4209-
// Check previous token to check for null-propagation
4210-
continue;
4208+
switch (m_token.tk)
4209+
{
4210+
case tkLParen:
4211+
case tkLBrack:
4212+
// Continue to parse function or index (loop)
4213+
// Check previous token to check for null-propagation
4214+
continue;
4215+
4216+
case tkStrTmplBasic:
4217+
case tkStrTmplBegin:
4218+
Error(ERRInvalidOptChainWithTaggedTemplate);
4219+
}
42114220
}
42124221
else if (!(m_token.IsReservedWord())) //allow reserved words in ES5 mode
42134222
{
@@ -4272,6 +4281,11 @@ ParseNodePtr Parser::ParsePostfixOperators(
42724281
case tkStrTmplBasic:
42734282
case tkStrTmplBegin:
42744283
{
4284+
if (isOptionalChain)
4285+
{
4286+
Error(ERRInvalidOptChainWithTaggedTemplate);
4287+
}
4288+
42754289
ParseNode* templateNode = nullptr;
42764290
if (pnode != nullptr)
42774291
{

lib/Parser/perrors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ LSC_ERROR_MSG(1103, ERRMissingFrom, "Expected 'from' after import or export clau
123123

124124
LSC_ERROR_MSG(1105, ERRInvalidOptChainInNew, "Invalid optional chain in new expression.")
125125
LSC_ERROR_MSG(1106, ERRInvalidOptChainInSuper, "Invalid optional chain in call to 'super'.")
126-
// 1107-1199 available for future use
126+
LSC_ERROR_MSG(1107, ERRInvalidOptChainWithTaggedTemplate, "Invalid tagged template in optional chain.")
127+
// 1108-1199 available for future use
127128

128129
// Generic errors intended to be re-usable
129130
LSC_ERROR_MSG(1200, ERRKeywordAfter, "Unexpected keyword '%s' after '%s'")

0 commit comments

Comments
 (0)