From 09deead408e56b899dbc2161aff5b94c426ab276 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Wed, 29 Mar 2023 10:49:11 +0800 Subject: [PATCH] Fix the garbled code problem with stringview Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I6R7YB Test: parser tests, compiler tests, test262 Signed-off-by: xucheng46 Change-Id: Ie47e1a07f24d6c5d6e463859a7a5e0ff30d0bfcb --- es2panda/binder/scope.cpp | 4 +- es2panda/test/runner.py | 22 +- .../test-interface-type-test-1-expected.txt | 1301 +++++++++++++++++ .../test-interface-type-test-1.d.ts | 25 + 4 files changed, 1344 insertions(+), 8 deletions(-) create mode 100644 es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1-expected.txt create mode 100644 es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1.d.ts diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index cbf92a5038d..18355cf634b 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -68,9 +68,9 @@ FunctionScope *Scope::EnclosingFunctionVariableScope() Variable *Scope::FindLocal(const util::StringView &name, ResolveBindingOptions options) const { if (options & ResolveBindingOptions::INTERFACES) { - util::StringView interfaceNameView(binder::TSBinding::ToTSBinding(name)); + const std::string &interfaceName = binder::TSBinding::ToTSBinding(name); - auto res = bindings_.find(interfaceNameView); + auto res = bindings_.find(util::StringView{interfaceName}); if (res != bindings_.end()) { return res->second; } diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 21e539eb333..65128dcfe91 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1216,6 +1216,7 @@ class TypeExtractorRunner(Runner): self.add_tsc_directory("conformance", []) self.add_directory("testcases", []) + self.add_directory("dts-testcases", [], True) self.add_directory("testcases_with_assert", []) def add_tsc_directory(self, directory, flags): @@ -1233,11 +1234,13 @@ class TypeExtractorRunner(Runner): test = TypeExtractorTest(f, flags) self.tests.append(test) - def add_directory(self, directory, flags): + def add_directory(self, directory, flags, is_dts_test=False): ts_suite_dir = path.join(self.test_root, 'type_extractor') - glob_expression = path.join( - ts_suite_dir, directory, "**/*.ts") + if is_dts_test: + glob_expression = path.join(ts_suite_dir, directory, "**/*.d.ts") + else: + glob_expression = path.join(ts_suite_dir, directory, "**/*.ts") files = glob(glob_expression, recursive=True) files = fnmatch.filter(files, ts_suite_dir + '**' + self.args.filter) @@ -1246,7 +1249,7 @@ class TypeExtractorRunner(Runner): test = TypeExtractorWithAssertTest(f, flags) self.tests.append(test) else: - test = TypeExtractorTest(f, flags) + test = TypeExtractorTest(f, flags, is_dts_test) self.tests.append(test) def test_path(self, src): @@ -1254,13 +1257,16 @@ class TypeExtractorRunner(Runner): class TypeExtractorTest(Test): - def __init__(self, test_path, flags): + def __init__(self, test_path, flags, is_dts_test=False): Test.__init__(self, test_path, flags) + self.is_dts_test = is_dts_test def run(self, runner): test_abc_name = ("%s.abc" % (path.splitext(self.path)[0])).replace("/", "_") cmd = runner.cmd_prefix + [runner.es2panda, '--extension=ts', '--module', '--dump-literal-buffer', '--opt-level=2', '--type-extractor'] + if self.is_dts_test: + cmd.append("--type-dts-builtin") cmd.extend(self.flags) cmd.extend(["--output=" + test_abc_name]) cmd.append(self.path) @@ -1275,7 +1281,11 @@ class TypeExtractorTest(Test): if os.path.isfile(test_abc_name): os.remove(test_abc_name) - expected_path = "%s-expected.txt" % (path.splitext(self.path)[0]) + file_name = path.splitext(self.path)[0] + if self.is_dts_test: + expected_path = "%s-expected.txt" % (path.splitext(file_name)[0]) + else: + expected_path = "%s-expected.txt" % (file_name) if not os.path.isfile(expected_path): expected_path = path.dirname(path.abspath(__file__)) + "/type_extractor/tsc_expect/%s" % \ expected_path.split("tests/cases/")[-1] diff --git a/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1-expected.txt b/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1-expected.txt new file mode 100644 index 00000000000..13ee8e936fc --- /dev/null +++ b/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1-expected.txt @@ -0,0 +1,1301 @@ +======> literal array buffer <====== +------------------------------------ +slot _0 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: 83 +}, +{ + index: 2 + tag: 0 + val: 24 +}, +{ + index: 3 + tag: 24 + val: _1 +}, +{ + index: 4 + tag: 0 + val: 24 +}, +{ + index: 5 + tag: 24 + val: _2 +}, +{ + index: 6 + tag: 0 + val: 24 +}, +{ + index: 7 + tag: 24 + val: _3 +}, +{ + index: 8 + tag: 0 + val: 24 +}, +{ + index: 9 + tag: 24 + val: _4 +}, +{ + index: 10 + tag: 0 + val: 24 +}, +{ + index: 11 + tag: 24 + val: _5 +}, +{ + index: 12 + tag: 0 + val: 24 +}, +{ + index: 13 + tag: 24 + val: _6 +}, +{ + index: 14 + tag: 0 + val: 24 +}, +{ + index: 15 + tag: 24 + val: _7 +}, +{ + index: 16 + tag: 0 + val: 24 +}, +{ + index: 17 + tag: 24 + val: _8 +}, +{ + index: 18 + tag: 0 + val: 24 +}, +{ + index: 19 + tag: 24 + val: _9 +}, +{ + index: 20 + tag: 0 + val: 24 +}, +{ + index: 21 + tag: 24 + val: _10 +}, +{ + index: 22 + tag: 0 + val: 24 +}, +{ + index: 23 + tag: 24 + val: _11 +}, +{ + index: 24 + tag: 0 + val: 24 +}, +{ + index: 25 + tag: 24 + val: _12 +}, +{ + index: 26 + tag: 0 + val: 24 +}, +{ + index: 27 + tag: 24 + val: _13 +}, +{ + index: 28 + tag: 0 + val: 24 +}, +{ + index: 29 + tag: 24 + val: _14 +}, +{ + index: 30 + tag: 0 + val: 24 +}, +{ + index: 31 + tag: 24 + val: _15 +}, +{ + index: 32 + tag: 0 + val: 24 +}, +{ + index: 33 + tag: 24 + val: _16 +}, +{ + index: 34 + tag: 0 + val: 24 +}, +{ + index: 35 + tag: 24 + val: _17 +}, +{ + index: 36 + tag: 0 + val: 24 +}, +{ + index: 37 + tag: 24 + val: _18 +}, +{ + index: 38 + tag: 0 + val: 24 +}, +{ + index: 39 + tag: 24 + val: _19 +}, +{ + index: 40 + tag: 0 + val: 24 +}, +{ + index: 41 + tag: 24 + val: _20 +}, +{ + index: 42 + tag: 0 + val: 24 +}, +{ + index: 43 + tag: 24 + val: _21 +}, +{ + index: 44 + tag: 0 + val: 24 +}, +{ + index: 45 + tag: 24 + val: _22 +}, +{ + index: 46 + tag: 0 + val: 24 +}, +{ + index: 47 + tag: 24 + val: _23 +}, +{ + index: 48 + tag: 0 + val: 24 +}, +{ + index: 49 + tag: 24 + val: _24 +}, +{ + index: 50 + tag: 0 + val: 24 +}, +{ + index: 51 + tag: 24 + val: _25 +}, +{ + index: 52 + tag: 0 + val: 24 +}, +{ + index: 53 + tag: 24 + val: _26 +}, +{ + index: 54 + tag: 0 + val: 24 +}, +{ + index: 55 + tag: 24 + val: _27 +}, +{ + index: 56 + tag: 0 + val: 24 +}, +{ + index: 57 + tag: 24 + val: _28 +}, +{ + index: 58 + tag: 0 + val: 24 +}, +{ + index: 59 + tag: 24 + val: _29 +}, +{ + index: 60 + tag: 0 + val: 24 +}, +{ + index: 61 + tag: 24 + val: _30 +}, +{ + index: 62 + tag: 0 + val: 24 +}, +{ + index: 63 + tag: 24 + val: _31 +}, +{ + index: 64 + tag: 0 + val: 24 +}, +{ + index: 65 + tag: 24 + val: _32 +}, +{ + index: 66 + tag: 0 + val: 24 +}, +{ + index: 67 + tag: 24 + val: _33 +}, +{ + index: 68 + tag: 0 + val: 24 +}, +{ + index: 69 + tag: 24 + val: _34 +}, +{ + index: 70 + tag: 0 + val: 24 +}, +{ + index: 71 + tag: 24 + val: _35 +}, +{ + index: 72 + tag: 0 + val: 24 +}, +{ + index: 73 + tag: 24 + val: _36 +}, +{ + index: 74 + tag: 0 + val: 24 +}, +{ + index: 75 + tag: 24 + val: _37 +}, +{ + index: 76 + tag: 0 + val: 24 +}, +{ + index: 77 + tag: 24 + val: _38 +}, +{ + index: 78 + tag: 0 + val: 24 +}, +{ + index: 79 + tag: 24 + val: _39 +}, +{ + index: 80 + tag: 0 + val: 24 +}, +{ + index: 81 + tag: 24 + val: _40 +}, +{ + index: 82 + tag: 0 + val: 24 +}, +{ + index: 83 + tag: 24 + val: _41 +}, +{ + index: 84 + tag: 0 + val: 24 +}, +{ + index: 85 + tag: 24 + val: _42 +}, +{ + index: 86 + tag: 0 + val: 24 +}, +{ + index: 87 + tag: 24 + val: _43 +}, +{ + index: 88 + tag: 0 + val: 24 +}, +{ + index: 89 + tag: 24 + val: _44 +}, +{ + index: 90 + tag: 0 + val: 24 +}, +{ + index: 91 + tag: 24 + val: _45 +}, +{ + index: 92 + tag: 0 + val: 24 +}, +{ + index: 93 + tag: 24 + val: _46 +}, +{ + index: 94 + tag: 0 + val: 24 +}, +{ + index: 95 + tag: 24 + val: _47 +}, +{ + index: 96 + tag: 0 + val: 24 +}, +{ + index: 97 + tag: 24 + val: _48 +}, +{ + index: 98 + tag: 0 + val: 24 +}, +{ + index: 99 + tag: 24 + val: _49 +}, +{ + index: 100 + tag: 0 + val: 24 +}, +{ + index: 101 + tag: 24 + val: _50 +}, +{ + index: 102 + tag: 0 + val: 24 +}, +{ + index: 103 + tag: 24 + val: _51 +}, +{ + index: 104 + tag: 0 + val: 24 +}, +{ + index: 105 + tag: 24 + val: _52 +}, +{ + index: 106 + tag: 0 + val: 24 +}, +{ + index: 107 + tag: 24 + val: _53 +}, +{ + index: 108 + tag: 0 + val: 24 +}, +{ + index: 109 + tag: 24 + val: _54 +}, +{ + index: 110 + tag: 0 + val: 24 +}, +{ + index: 111 + tag: 24 + val: _55 +}, +{ + index: 112 + tag: 0 + val: 24 +}, +{ + index: 113 + tag: 24 + val: _56 +}, +{ + index: 114 + tag: 0 + val: 24 +}, +{ + index: 115 + tag: 24 + val: _57 +}, +{ + index: 116 + tag: 0 + val: 24 +}, +{ + index: 117 + tag: 24 + val: _58 +}, +{ + index: 118 + tag: 0 + val: 24 +}, +{ + index: 119 + tag: 24 + val: _59 +}, +{ + index: 120 + tag: 0 + val: 24 +}, +{ + index: 121 + tag: 24 + val: _60 +}, +{ + index: 122 + tag: 0 + val: 24 +}, +{ + index: 123 + tag: 24 + val: _61 +}, +{ + index: 124 + tag: 0 + val: 24 +}, +{ + index: 125 + tag: 24 + val: _62 +}, +{ + index: 126 + tag: 0 + val: 24 +}, +{ + index: 127 + tag: 24 + val: _63 +}, +{ + index: 128 + tag: 0 + val: 24 +}, +{ + index: 129 + tag: 24 + val: _64 +}, +{ + index: 130 + tag: 0 + val: 24 +}, +{ + index: 131 + tag: 24 + val: _65 +}, +{ + index: 132 + tag: 0 + val: 24 +}, +{ + index: 133 + tag: 24 + val: _66 +}, +{ + index: 134 + tag: 0 + val: 24 +}, +{ + index: 135 + tag: 24 + val: _67 +}, +{ + index: 136 + tag: 0 + val: 24 +}, +{ + index: 137 + tag: 24 + val: _68 +}, +{ + index: 138 + tag: 0 + val: 24 +}, +{ + index: 139 + tag: 24 + val: _69 +}, +{ + index: 140 + tag: 0 + val: 24 +}, +{ + index: 141 + tag: 24 + val: _70 +}, +{ + index: 142 + tag: 0 + val: 24 +}, +{ + index: 143 + tag: 24 + val: _71 +}, +{ + index: 144 + tag: 0 + val: 24 +}, +{ + index: 145 + tag: 24 + val: _72 +}, +{ + index: 146 + tag: 0 + val: 24 +}, +{ + index: 147 + tag: 24 + val: _73 +}, +{ + index: 148 + tag: 0 + val: 24 +}, +{ + index: 149 + tag: 24 + val: _74 +}, +{ + index: 150 + tag: 0 + val: 24 +}, +{ + index: 151 + tag: 24 + val: _75 +}, +{ + index: 152 + tag: 0 + val: 24 +}, +{ + index: 153 + tag: 24 + val: _76 +}, +{ + index: 154 + tag: 0 + val: 24 +}, +{ + index: 155 + tag: 24 + val: _77 +}, +{ + index: 156 + tag: 0 + val: 24 +}, +{ + index: 157 + tag: 24 + val: _78 +}, +{ + index: 158 + tag: 0 + val: 24 +}, +{ + index: 159 + tag: 24 + val: _79 +}, +{ + index: 160 + tag: 0 + val: 24 +}, +{ + index: 161 + tag: 24 + val: _80 +}, +{ + index: 162 + tag: 0 + val: 24 +}, +{ + index: 163 + tag: 24 + val: _81 +}, +{ + index: 164 + tag: 0 + val: 24 +}, +{ + index: 165 + tag: 24 + val: _82 +}, +{ + index: 166 + tag: 0 + val: 24 +}, +{ + index: 167 + tag: 24 + val: _83 +}, +{ + index: 168 + tag: 0 + val: 2 +}, +{ + index: 169 + tag: 2 + val: 0 +}, +------------------------------------ +slot _1 +------------------------------------ +slot _10 +------------------------------------ +slot _11 +------------------------------------ +slot _12 +------------------------------------ +slot _13 +------------------------------------ +slot _14 +------------------------------------ +slot _15 +------------------------------------ +slot _16 +------------------------------------ +slot _17 +------------------------------------ +slot _18 +------------------------------------ +slot _19 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: 1 +}, +{ + index: 2 + tag: 0 + val: 2 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 0 + val: 25 +}, +{ + index: 5 + tag: 25 + val: 0 +}, +{ + index: 6 + tag: 0 + val: 2 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +{ + index: 8 + tag: 0 + val: 2 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +{ + index: 10 + tag: 0 + val: 2 +}, +{ + index: 11 + tag: 2 + val: 1 +}, +{ + index: 12 + tag: 0 + val: 5 +}, +{ + index: 13 + tag: 5 + val: values +}, +{ + index: 14 + tag: 0 + val: 24 +}, +{ + index: 15 + tag: 24 + val: _83 +}, +{ + index: 16 + tag: 0 + val: 2 +}, +{ + index: 17 + tag: 2 + val: 0 +}, +{ + index: 18 + tag: 0 + val: 2 +}, +{ + index: 19 + tag: 2 + val: 0 +}, +------------------------------------ +slot _2 +------------------------------------ +slot _20 +------------------------------------ +slot _21 +------------------------------------ +slot _22 +------------------------------------ +slot _23 +------------------------------------ +slot _24 +------------------------------------ +slot _25 +------------------------------------ +slot _26 +------------------------------------ +slot _27 +------------------------------------ +slot _28 +------------------------------------ +slot _29 +------------------------------------ +slot _3 +------------------------------------ +slot _30 +------------------------------------ +slot _31 +------------------------------------ +slot _32 +------------------------------------ +slot _33 +------------------------------------ +slot _34 +------------------------------------ +slot _35 +------------------------------------ +slot _36 +------------------------------------ +slot _37 +------------------------------------ +slot _38 +------------------------------------ +slot _39 +------------------------------------ +slot _4 +------------------------------------ +slot _40 +------------------------------------ +slot _41 +------------------------------------ +slot _42 +------------------------------------ +slot _43 +------------------------------------ +slot _44 +------------------------------------ +slot _45 +------------------------------------ +slot _46 +------------------------------------ +slot _47 +------------------------------------ +slot _48 +------------------------------------ +slot _49 +------------------------------------ +slot _5 +------------------------------------ +slot _50 +------------------------------------ +slot _51 +------------------------------------ +slot _52 +------------------------------------ +slot _53 +------------------------------------ +slot _54 +------------------------------------ +slot _55 +------------------------------------ +slot _56 +------------------------------------ +slot _57 +------------------------------------ +slot _58 +------------------------------------ +slot _59 +------------------------------------ +slot _6 +------------------------------------ +slot _60 +------------------------------------ +slot _61 +------------------------------------ +slot _62 +------------------------------------ +slot _63 +------------------------------------ +slot _64 +------------------------------------ +slot _65 +------------------------------------ +slot _66 +------------------------------------ +slot _67 +------------------------------------ +slot _68 +------------------------------------ +slot _69 +------------------------------------ +slot _7 +------------------------------------ +slot _70 +------------------------------------ +slot _71 +------------------------------------ +slot _72 +------------------------------------ +slot _73 +------------------------------------ +slot _74 +------------------------------------ +slot _75 +------------------------------------ +slot _76 +------------------------------------ +slot _77 +------------------------------------ +slot _78 +------------------------------------ +slot _79 +------------------------------------ +slot _8 +------------------------------------ +slot _80 +------------------------------------ +slot _81 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: 8 +}, +{ + index: 2 + tag: 0 + val: 2 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 0 + val: 2 +}, +{ + index: 5 + tag: 2 + val: 0 +}, +{ + index: 6 + tag: 0 + val: 2 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +------------------------------------ +slot _82 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: 8 +}, +{ + index: 2 + tag: 0 + val: 2 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 0 + val: 24 +}, +{ + index: 5 + tag: 24 + val: _81 +}, +{ + index: 6 + tag: 0 + val: 2 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +{ + index: 8 + tag: 0 + val: 2 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +------------------------------------ +slot _83 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: 3 +}, +{ + index: 2 + tag: 0 + val: 2 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 0 + val: 5 +}, +{ + index: 5 + tag: 5 + val: values +}, +{ + index: 6 + tag: 0 + val: 2 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +{ + index: 8 + tag: 0 + val: 2 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +{ + index: 10 + tag: 0 + val: 24 +}, +{ + index: 11 + tag: 24 + val: _82 +}, +------------------------------------ +slot _84 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 0 +}, +{ + index: 5 + tag: 2 + val: 0 +}, +------------------------------------ +slot _9 diff --git a/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1.d.ts b/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1.d.ts new file mode 100644 index 00000000000..dea926f9174 --- /dev/null +++ b/es2panda/test/type_extractor/dts-testcases/test-interface-type-test-1.d.ts @@ -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. + */ + + +interface Iterator { +} + +interface IterableIterator extends Iterator { +} + +declare class Set extends Object { + values(): IterableIterator; +} -- Gitee