diff --git a/es2panda/lexer/lexer.cpp b/es2panda/lexer/lexer.cpp index 529ddea26aacbabb680c8d6389fcdec4e56e3ba3..3a83fb4d2572361168d64168005f96cdf795fb1e 100644 --- a/es2panda/lexer/lexer.cpp +++ b/es2panda/lexer/lexer.cpp @@ -489,7 +489,7 @@ LexerTemplateString Lexer::ScanTemplateString() Iterator().Backward(1); } - if (nextCp == LEX_CHAR_BACK_TICK || nextCp == LEX_CHAR_BACKSLASH) { + if (nextCp == LEX_CHAR_BACK_TICK || nextCp == LEX_CHAR_BACKSLASH || nextCp == LEX_CHAR_DOLLAR_SIGN) { templateStr.str.Append(cp); templateStr.str.Append(nextCp); Iterator().Forward(1); diff --git a/es2panda/lexer/regexp/regexp.cpp b/es2panda/lexer/regexp/regexp.cpp index 630555df5459a7a886401b3ee56acbd6fb425acd..ea4356ce4d3197899d12b86c0fa13d20f48cd5b9 100644 --- a/es2panda/lexer/regexp/regexp.cpp +++ b/es2panda/lexer/regexp/regexp.cpp @@ -680,7 +680,7 @@ void RegExpParser::ParseUnicodePropertyEscape() } char32_t ch = Next(); - if (ch == LEX_CHAR_LEFT_BRACE) { + if (ch == LEX_CHAR_RIGHT_BRACE) { break; } diff --git a/es2panda/test/parser/js/test-regexp-p-expected.txt b/es2panda/test/parser/js/test-regexp-p-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..31af86465ca9f37f87c9659110f843fa4337db07 --- /dev/null +++ b/es2panda/test/parser/js/test-regexp-p-expected.txt @@ -0,0 +1,71 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "RegularExpressionLiteral", + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "right": { + "type": "RegExpLiteral", + "source": "\u200C\u200D\p{ID_Continue}", + "flags": "u", + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 59 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 16, + "column": 59 + } + } +} diff --git a/es2panda/test/parser/js/test-regexp-p.js b/es2panda/test/parser/js/test-regexp-p.js new file mode 100644 index 0000000000000000000000000000000000000000..d2e67d9dd0590f1198921d2f5c61c8bf0a10b370 --- /dev/null +++ b/es2panda/test/parser/js/test-regexp-p.js @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +RegularExpressionLiteral = /\u200C\u200D\p{ID_Continue}/u; \ No newline at end of file