diff --git a/es2panda/lexer/lexer.cpp b/es2panda/lexer/lexer.cpp index 5e80b9718eeaf3a3db4c7b6a1272ced26a9c2c7e..20466c273c169ad8e22119b94f9bec6cf8a57657 100644 --- a/es2panda/lexer/lexer.cpp +++ b/es2panda/lexer/lexer.cpp @@ -487,7 +487,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 diff --git a/es2panda/test/parser/js/test-special-character-processing-in-template-string-expected.txt b/es2panda/test/parser/js/test-special-character-processing-in-template-string-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..978a429353ec5341616f999caeaef673f05e3bb2 --- /dev/null +++ b/es2panda/test/parser/js/test-special-character-processing-in-template-string-expected.txt @@ -0,0 +1,178 @@ +{ + "type": "Program", + "statements": [ + { + "type": "LabelledStatement", + "label": { + "type": "Identifier", + "name": "iflnlf", + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 7 + } + } + }, + "body": { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "string", + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "TemplateLiteral", + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "value": { + "raw": " +if( + \`\${ + (()=>{ + if(true) /r/i + return Math.random() + })() + }\` > 0.5 +) /a/g +", + "cooked": " +if( + `${ + (()=>{ + if(true) /r/i + return Math.random() + })() + }` > 0.5 +) /a/g +" + }, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 25, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "property": { + "type": "Identifier", + "name": "trim", + "loc": { + "start": { + "line": 25, + "column": 3 + }, + "end": { + "line": 25, + "column": 7 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 25, + "column": 7 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 25, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 25, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 25, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 10 + } + } +} diff --git a/es2panda/test/parser/js/test-special-character-processing-in-template-string.js b/es2panda/test/parser/js/test-special-character-processing-in-template-string.js new file mode 100644 index 0000000000000000000000000000000000000000..9374109bdbd6e31c4f963ea2451d7b1bbdb35e51 --- /dev/null +++ b/es2panda/test/parser/js/test-special-character-processing-in-template-string.js @@ -0,0 +1,25 @@ +/* + * 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. + */ + +iflnlf: string = ` +if( + \`\${ + (()=>{ + if(true) /r/i + return Math.random() + })() + }\` > 0.5 +) /a/g +`.trim(); \ No newline at end of file