diff --git a/es2panda/lexer/token/sourceLocation.cpp b/es2panda/lexer/token/sourceLocation.cpp index 8cb80a458b57af428afa223140b1145cf7b6ec38..bf4ff240f3201c1c0d2e1634838e4bc63d6f8fd1 100644 --- a/es2panda/lexer/token/sourceLocation.cpp +++ b/es2panda/lexer/token/sourceLocation.cpp @@ -47,14 +47,15 @@ LineIndex::LineIndex(const util::StringView &source) noexcept bool nextEntry = false; while (true) { - switch (iter.Next()) { - case util::StringView::Iterator::INVALID_CP: { - if (!nextEntry) { - // Add the last entry if the ending character is not LEX_CHAR_LF / LEX_CHAR_PS / LEX_CHAR_LS - entrys_.emplace_back(iter.Index()); - } - return; + if (!iter.HasNext()) { + if (!nextEntry) { + // Add the last entry if the ending character is not LEX_CHAR_LF / LEX_CHAR_PS / LEX_CHAR_LS + entrys_.emplace_back(iter.Index()); } + return; + } + + switch (iter.Next()) { case LEX_CHAR_CR: { if (iter.HasNext() && iter.Peek() == LEX_CHAR_LF) { iter.Forward(1); diff --git a/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property-expected.txt b/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property.js b/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property.js new file mode 100644 index 0000000000000000000000000000000000000000..569ef355652f5fad2e9ab74f9250414e265ebcec --- /dev/null +++ b/es2panda/test/compiler/js/language/expressions/optional-chain/optional-chain-accessing-private-property.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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. + */ + +class A { + static #a = 1; + static { + print(this?.#a); + } +} \ No newline at end of file diff --git a/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file-expected.txt b/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ed2c53ad9f964e5875f287b4959f6eb7a67b391 --- /dev/null +++ b/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file-expected.txt @@ -0,0 +1 @@ +SyntaxError: Primary expression expected [syntax-error-in-non-utf8-file.js:18:1] diff --git a/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file.js b/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file.js new file mode 100644 index 0000000000000000000000000000000000000000..38cbe81bf4794fc0f3aba60f585d9055da3fc5c7 --- /dev/null +++ b/es2panda/test/parser/unicode/syntax-error-in-non-utf8-file.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 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. + */ + +b = {n:"Šo"}; +function a() { \ No newline at end of file diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 81c2a6441942c02845efd2d30b27cf75235fcb82..7782cf91fb655ef4b14d608aa78fe06a67ed2cff 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1523,6 +1523,7 @@ def main(): runner.add_directory("parser/js/language/statements/for-statement", "js", ["--parse-only", "--dump-ast"]) runner.add_directory("parser/js/language/expressions/optional-chain", "js", ["--parse-only", "--dump-ast"]) runner.add_directory("parser/sendable_class", "ts", ["--dump-assembly", "--dump-literal-buffer", "--module"]) + runner.add_directory("parser/unicode", "js", ["--parse-only"]) runners.append(runner)