diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp index e8e62da9d81535419abcc720e1806f154c55d70b..0a2b7f0f7571dcfaabd17ddd9b7b60cc4636bccc 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 0000000000000000000000000000000000000000..3ee1833f7744624eaeb8a1820cd7a475a452c5ca --- /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 0000000000000000000000000000000000000000..ce013625030ba8dba906f756967f9e9ca394464a --- /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 0000000000000000000000000000000000000000..7c05096db906c50c52b3fc5ef275e335e7579190 --- /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");