1/** 2 * Copyright (c) 2021-2024 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 "checker/TSchecker.h" 19#include "compiler/core/ETSGen.h" 20#include "compiler/core/pandagen.h" 21#include "ir/astDump.h" 22#include "ir/srcDump.h" 23#include "ir/base/decorator.h" 24 25namespace ark::es2panda::ir { 26void TSModuleDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) 27{ 28 for (auto *&it : decorators_) { 29 if (auto *transformedNode = cb(it); it != transformedNode) { 30 it->SetTransformedNode(transformationName, transformedNode); 31 it = transformedNode->AsDecorator(); 32 } 33 } 34 35 if (auto *transformedNode = cb(name_); name_ != transformedNode) { 36 name_->SetTransformedNode(transformationName, transformedNode); 37 name_ = transformedNode->AsExpression(); 38 } 39 40 if (body_ != nullptr) { 41 if (auto *transformedNode = cb(body_); body_ != transformedNode) { 42 body_->SetTransformedNode(transformationName, transformedNode); 43 body_ = transformedNode->AsStatement(); 44 } 45 } 46} 47 48void TSModuleDeclaration::Iterate(const NodeTraverser &cb) const 49{ 50 for (auto *it : decorators_) { 51 cb(it); 52 } 53 54 cb(name_); 55 56 if (body_ != nullptr) { 57 cb(body_); 58 } 59} 60 61void TSModuleDeclaration::Dump(ir::AstDumper *dumper) const 62{ 63 dumper->Add({{"type", "TSModuleDeclaration"}, 64 {"decorators", AstDumper::Optional(decorators_)}, 65 {"id", name_}, 66 {"body", AstDumper::Optional(body_)}, 67 {"declare", declare_}, 68 {"global", global_}}); 69} 70 71void TSModuleDeclaration::Dump(ir::SrcDumper *dumper) const 72{ 73 dumper->Add("TSModuleDeclaration"); 74} 75 76void TSModuleDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const 77{ 78 pg->GetAstCompiler()->Compile(this); 79} 80 81void TSModuleDeclaration::Compile(compiler::ETSGen *etsg) const 82{ 83 etsg->GetAstCompiler()->Compile(this); 84} 85 86checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) 87{ 88 return checker->GetAnalyzer()->Check(this); 89} 90 91checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) 92{ 93 return checker->GetAnalyzer()->Check(this); 94} 95} // namespace ark::es2panda::ir 96