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