From 09986212eee4868d75d46d8038f154f448fb3035 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Sat, 29 Oct 2022 10:51:18 +0000 Subject: [PATCH] Fix incorrect error thrown of reserved word in class Issue:I5YELB Signed-off-by: ctw-ian Change-Id: Ice2fecc1e9d30b08963c3dbec0bcba4cb5d8576d --- es2panda/parser/parserImpl.cpp | 4 +- .../js/class-declaration-is-expected.txt | 139 ++++++++++++++++++ .../test/parser/js/class-declaration-is.js | 1 + 3 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 es2panda/test/parser/js/class-declaration-is-expected.txt create mode 100644 es2panda/test/parser/js/class-declaration-is.js diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 212fc8f3e3..4c44ee5f1e 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -2650,9 +2650,7 @@ bool ParserImpl::IsMethodDefinitionsAreSame(const ir::MethodDefinition *property ir::Identifier *ParserImpl::SetIdentNodeInClassDefinition() { lexer::TokenType keywType = lexer_->GetToken().KeywordType(); - if (keywType >= lexer::TokenType::KEYW_STATIC) { - ThrowSyntaxError("Unexpected reserved word"); - } + CheckStrictReservedWord(); if (keywType == lexer::TokenType::KEYW_AWAIT && context_.IsModule()) { ThrowSyntaxError("Unexpected reserved word"); diff --git a/es2panda/test/parser/js/class-declaration-is-expected.txt b/es2panda/test/parser/js/class-declaration-is-expected.txt new file mode 100644 index 0000000000..f83f21df96 --- /dev/null +++ b/es2panda/test/parser/js/class-declaration-is-expected.txt @@ -0,0 +1,139 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "is", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + } +} diff --git a/es2panda/test/parser/js/class-declaration-is.js b/es2panda/test/parser/js/class-declaration-is.js new file mode 100644 index 0000000000..2e8c0c369b --- /dev/null +++ b/es2panda/test/parser/js/class-declaration-is.js @@ -0,0 +1 @@ +class is {} \ No newline at end of file -- Gitee