1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "tsModuleDeclaration.h" 17 18 #include <binder/binder.h> 19 #include <binder/scope.h> 20 #include <ir/astDump.h> 21 #include <ir/expression.h> 22 23 namespace panda::es2panda::ir { 24 Iterate(const NodeTraverser & cb) const25 void TSModuleDeclaration::Iterate(const NodeTraverser &cb) const 26 { 27 cb(name_); 28 29 if (body_) { 30 cb(body_); 31 } 32 } 33 Dump(ir::AstDumper * dumper) const34 void TSModuleDeclaration::Dump(ir::AstDumper *dumper) const 35 { 36 dumper->Add({{"type", "TSModuleDeclaration"}, 37 {"id", name_}, 38 {"body", AstDumper::Optional(body_)}, 39 {"declare", declare_}, 40 {"global", global_}}); 41 } 42 Compile(compiler::PandaGen * pg) const43 void TSModuleDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} 44 Check(checker::Checker * checker) const45 checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::Checker *checker) const 46 { 47 return nullptr; 48 } 49 UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)50 void TSModuleDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) 51 { 52 name_ = std::get<ir::AstNode *>(cb(name_))->AsExpression(); 53 54 if (body_) { 55 auto scopeCtx = binder::LexicalScope<binder::TSModuleScope>::Enter(binder, scope_); 56 body_ = std::get<ir::AstNode *>(cb(body_))->AsStatement(); 57 } 58 } 59 60 } // namespace panda::es2panda::ir 61