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 "exportSpecifier.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
24namespace ark::es2panda::ir {
25void ExportSpecifier::TransformChildren(const NodeTransformer &cb, std::string_view transformationName)
26{
27    if (auto *transformedNode = cb(local_); local_ != transformedNode) {
28        local_->SetTransformedNode(transformationName, transformedNode);
29        local_ = transformedNode->AsIdentifier();
30    }
31
32    if (auto *transformedNode = cb(exported_); exported_ != transformedNode) {
33        exported_->SetTransformedNode(transformationName, transformedNode);
34        exported_ = transformedNode->AsIdentifier();
35    }
36}
37
38void ExportSpecifier::Iterate(const NodeTraverser &cb) const
39{
40    cb(local_);
41    cb(exported_);
42}
43
44void ExportSpecifier::Dump(ir::AstDumper *dumper) const
45{
46    dumper->Add({{"type", "ExportSpecifier"}, {"local", local_}, {"exported", exported_}});
47}
48
49void ExportSpecifier::Dump(ir::SrcDumper *dumper) const
50{
51    exported_->Dump(dumper);
52
53    if (local_ != nullptr) {
54        dumper->Add(" as ");
55        local_->Dump(dumper);
56    }
57}
58
59void ExportSpecifier::Compile(compiler::PandaGen *pg) const
60{
61    pg->GetAstCompiler()->Compile(this);
62}
63
64void ExportSpecifier::Compile(compiler::ETSGen *etsg) const
65{
66    etsg->GetAstCompiler()->Compile(this);
67}
68
69checker::Type *ExportSpecifier::Check(checker::TSChecker *checker)
70{
71    return checker->GetAnalyzer()->Check(this);
72}
73
74checker::Type *ExportSpecifier::Check(checker::ETSChecker *checker)
75{
76    return checker->GetAnalyzer()->Check(this);
77}
78}  // namespace ark::es2panda::ir
79