1 /**
2  * Copyright (c) 2021 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 "exportNamedDeclaration.h"
17 
18 #include <compiler/core/pandagen.h>
19 #include <ir/astDump.h>
20 #include <ir/expressions/literals/stringLiteral.h>
21 #include <ir/module/exportSpecifier.h>
22 
23 namespace panda::es2panda::ir {
24 
Iterate(const NodeTraverser &cb) const25 void ExportNamedDeclaration::Iterate(const NodeTraverser &cb) const
26 {
27     if (decl_) {
28         cb(decl_);
29     } else {
30         if (source_) {
31             cb(source_);
32         }
33 
34         for (auto *it : specifiers_) {
35             cb(it);
36         }
37 
38         if (assertClause_) {
39             cb(assertClause_);
40         }
41     }
42 }
43 
Dump(ir::AstDumper *dumper) const44 void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const
45 {
46     dumper->Add({{"type", "ExportNamedDeclaration"},
47                  {"declaration", AstDumper::Nullable(decl_)},
48                  {"source", AstDumper::Nullable(source_)},
49                  {"specifiers", specifiers_},
50                  {"assertClause", AstDumper::Optional(assertClause_)},
51                  {"isType", AstDumper::Optional(IsType())}});
52 }
53 
Compile(compiler::PandaGen *pg) const54 void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const
55 {
56     if (!decl_) {
57         return;
58     }
59 
60     decl_->Compile(pg);
61 }
62 
Check([[maybe_unused]] checker::Checker *checker) const63 checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
64 {
65     return nullptr;
66 }
67 
UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)68 void ExportNamedDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
69 {
70     if (decl_) {
71         decl_ = std::get<ir::AstNode *>(cb(decl_))->AsStatement();
72     } else {
73         if (source_) {
74             source_ = std::get<ir::AstNode *>(cb(source_))->AsStringLiteral();
75         }
76 
77         for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) {
78             *iter = std::get<ir::AstNode *>(cb(*iter))->AsExportSpecifier();
79         }
80 
81         if (assertClause_) {
82             assertClause_ = std::get<ir::AstNode *>(cb(assertClause_))->AsAssertClause();
83         }
84     }
85 }
86 
87 }  // namespace panda::es2panda::ir
88