From ad0dec7b20451960e1dfbac52bafb8800b98f828 Mon Sep 17 00:00:00 2001 From: songqi Date: Mon, 31 Jul 2023 13:16:13 +0800 Subject: [PATCH] fixed f6f50c9 from https://gitee.com/gitee-dakeQI/arkcompiler_ets_frontend_xc/pulls/1152 Fix transformer of ImportEqual Issue: I7P8VP Tests: test_es2abc Signed-off-by: songqi Change-Id: Id3513cf21720d03ff87c93958fc21361bfbf9118 --- es2panda/parser/transformer/transformer.cpp | 11 +++++++--- .../test-ts-export-type.ts | 19 ++++++++++++++++++ .../test-ts-import-type-exec-expected.txt | 1 + .../test-ts-import-type-exec.ts | 20 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-export-type.ts create mode 100644 es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec-expected.txt create mode 100644 es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec.ts diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp index e8e62da9d8..0a2b7f0f75 100644 --- a/es2panda/parser/transformer/transformer.cpp +++ b/es2panda/parser/transformer/transformer.cpp @@ -1145,12 +1145,17 @@ binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, return nullptr; } - // we don't process js variable here because it can't be used in import equals. + res = currentScope->FindLocal(name, binder::ResolveBindingOptions::BINDINGS); + if (res != nullptr) { + *isType = false; + return nullptr; + } + currentScope = currentScope->Parent(); } - // It should be an imported variable, so it won't be a type here. - *isType = false; + // can not find variable + *isType = true; return nullptr; } diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-export-type.ts b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-export-type.ts new file mode 100644 index 0000000000..3ee1833f77 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-export-type.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +export namespace ns { + export interface I { } +} diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec-expected.txt b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec-expected.txt new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec-expected.txt @@ -0,0 +1 @@ +hello diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec.ts b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec.ts new file mode 100644 index 0000000000..7c05096db9 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_4/test-ts-import-type-exec.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + + +import type ns from './test-ts-export-type'; +import ie = ns.I; + +print("hello"); -- Gitee