diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index dc6319947090576b159aaa623e93835d2fedae44..b3ce2fb2a76b81e5e1d1b0ec6ffc8d9fe9526623 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include namespace panda::es2panda::binder { @@ -553,6 +555,16 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) BuildTSSignatureDeclarationBaseParams(childNode); break; } + case ir::AstNodeType::TS_MODULE_DECLARATION: { + auto scopeCtx = LexicalScope::Enter(this, childNode->AsTSModuleDeclaration()->Scope()); + ResolveReferences(childNode); + break; + } + case ir::AstNodeType::TS_MODULE_BLOCK: { + auto scopeCtx = LexicalScope::Enter(this, childNode->AsTSModuleBlock()->Scope()); + ResolveReferences(childNode); + break; + } default: { ResolveReferences(childNode); break; diff --git a/es2panda/test/parser/ts/test_module_binder-expected.txt b/es2panda/test/parser/ts/test_module_binder-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf94fb985d907bae3a812cf9bf69406c7cbc7638 --- /dev/null +++ b/es2panda/test/parser/ts/test_module_binder-expected.txt @@ -0,0 +1,232 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "s", + "decorators": [], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + "declare": false, + "global": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 4, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_module_binder.ts b/es2panda/test/parser/ts/test_module_binder.ts new file mode 100644 index 0000000000000000000000000000000000000000..94a59026edb55b8de593629faf01916efde97a3b --- /dev/null +++ b/es2panda/test/parser/ts/test_module_binder.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 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. + */ + +module A { + class A { s: string } +}