diff --git a/es2panda/lexer/token/token.cpp b/es2panda/lexer/token/token.cpp index 12521b9dada193b33275e445a53d6700fe3a9e84..ba04e5d974b6ad3ba5311ee9f045d729d15fb55f 100644 --- a/es2panda/lexer/token/token.cpp +++ b/es2panda/lexer/token/token.cpp @@ -92,6 +92,27 @@ bool Token::IsReservedTypeName() const } } +bool Token::IsJsStrictReservedWord() const +{ + switch (keywordType_) + { + case TokenType::KEYW_ARGUMENTS: + case TokenType::KEYW_EVAL: + case TokenType::KEYW_STATIC: + case TokenType::KEYW_PRIVATE: + case TokenType::KEYW_PROTECTED: + case TokenType::KEYW_PUBLIC: + case TokenType::KEYW_IMPLEMENTS: + case TokenType::KEYW_INTERFACE: + case TokenType::KEYW_PACKAGE: + case TokenType::KEYW_LET: + case TokenType::KEYW_YIELD: + return true; + default: + return false; + } +} + bool Token::IsBinaryToken(TokenType type) { return (type >= TokenType::PUNCTUATOR_NULLISH_COALESCING && type <= TokenType::PUNCTUATOR_EXPONENTIATION); diff --git a/es2panda/lexer/token/token.h b/es2panda/lexer/token/token.h index 46a87d432cc1ff7cf96671e75e9391c196b298ae..26edb60d38c145034069ad58cb977c668d3cdd0b 100644 --- a/es2panda/lexer/token/token.h +++ b/es2panda/lexer/token/token.h @@ -116,6 +116,7 @@ public: bool IsPropNameLiteral() const; bool IsKeyword() const; bool IsReservedTypeName() const; + bool IsJsStrictReservedWord() const; static bool IsBinaryToken(TokenType type); static bool IsBinaryLvalueToken(TokenType type); diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index b772127022a3471c8b77aa53c0caf72430813be3..50374fb3663b359970817d847f20cec3f1be50f1 100644 --- a/es2panda/parser/expressionParser.cpp +++ b/es2panda/parser/expressionParser.cpp @@ -2344,8 +2344,14 @@ ir::FunctionExpression *ParserImpl::ParseFunctionExpression(ParserStatus newStat ThrowSyntaxError("Expected an identifier."); } - if (lexer_->GetToken().KeywordType() >= lexer::TokenType::KEYW_ARGUMENTS) { - ThrowSyntaxError("Unexpected reserved word in strict mode."); + if (Extension() == ScriptExtension::JS) { + if (lexer_->GetToken().IsJsStrictReservedWord()) { + ThrowSyntaxError("Unexpected reserved word in strict mode."); + } + } else { + if (lexer_->GetToken().KeywordType() >= lexer::TokenType::KEYW_ARGUMENTS) { + ThrowSyntaxError("Unexpected reserved word in strict mode."); + } } ident = AllocNode(lexer_->GetToken().Ident(), Allocator()); diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index b70db8649291733bf7bdd9b356e39df931bd7184..82b8a7a34a6eeca3f0ebb2c5d976ced90c46d574 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -1060,8 +1060,16 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou ThrowSyntaxError("Unexpected token, expected identifier after 'function' keyword"); } - if (!isDeclare && lexer_->GetToken().KeywordType() >= lexer::TokenType::KEYW_ARGUMENTS) { - ThrowSyntaxError("Unexpected reserved word in strict mode."); + if (!isDeclare) { + if (Extension() == ScriptExtension::JS) { + if (lexer_->GetToken().IsJsStrictReservedWord()) { + ThrowSyntaxError("Unexpected reserved word in strict mode."); + } + } else { + if (lexer_->GetToken().KeywordType() >= lexer::TokenType::KEYW_ARGUMENTS) { + ThrowSyntaxError("Unexpected reserved word in strict mode."); + } + } } util::StringView ident = lexer_->GetToken().Ident();