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 <ir/astDump.h>
19 #include <ir/expression.h>
20
21 namespace panda::es2panda::ir {
22
Iterate(const NodeTraverser & cb) const23 void TSModuleDeclaration::Iterate(const NodeTraverser &cb) const
24 {
25 cb(name_);
26
27 if (body_) {
28 cb(body_);
29 }
30 }
31
Dump(ir::AstDumper * dumper) const32 void TSModuleDeclaration::Dump(ir::AstDumper *dumper) const
33 {
34 dumper->Add({{"type", "TSModuleDeclaration"},
35 {"id", name_},
36 {"body", AstDumper::Optional(body_)},
37 {"declare", declare_},
38 {"global", global_}});
39 }
40
Compile(compiler::PandaGen * pg) const41 void TSModuleDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {}
42
Check(checker::Checker * checker) const43 checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
44 {
45 return nullptr;
46 }
47
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)48 void TSModuleDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder)
49 {
50 name_ = std::get<ir::AstNode *>(cb(name_))->AsExpression();
51
52 if (body_) {
53 auto scopeCtx = binder::LexicalScope<binder::TSModuleScope>::Enter(binder, scope_);
54 body_ = std::get<ir::AstNode *>(cb(body_))->AsStatement();
55 }
56 }
57
58 } // namespace panda::es2panda::ir
59