1 /**
2 * Copyright (c) 2021-2025 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 "tsUndefinedKeyword.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
24 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)25 void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb,
26 [[maybe_unused]] std::string_view const transformationName)
27 {
28 for (auto *&it : VectorIterationGuard(Annotations())) {
29 if (auto *transformedNode = cb(it); it != transformedNode) {
30 it->SetTransformedNode(transformationName, transformedNode);
31 it = transformedNode->AsAnnotationUsage();
32 }
33 }
34 }
35
Iterate(const NodeTraverser & cb) const36 void TSUndefinedKeyword::Iterate([[maybe_unused]] const NodeTraverser &cb) const
37 {
38 for (auto *it : VectorIterationGuard(Annotations())) {
39 cb(it);
40 }
41 }
42
Dump(ir::AstDumper * dumper) const43 void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const
44 {
45 dumper->Add({{"type", "TSUndefinedKeyword"}, {"annotations", AstDumper::Optional(Annotations())}});
46 }
47
Dump(ir::SrcDumper * dumper) const48 void TSUndefinedKeyword::Dump(ir::SrcDumper *dumper) const
49 {
50 for (auto *anno : Annotations()) {
51 anno->Dump(dumper);
52 }
53 dumper->Add("TSUndefinedKeyword");
54 }
55
Compile(compiler::PandaGen * pg) const56 void TSUndefinedKeyword::Compile(compiler::PandaGen *pg) const
57 {
58 pg->GetAstCompiler()->Compile(this);
59 }
60
Compile(compiler::ETSGen * etsg) const61 void TSUndefinedKeyword::Compile(compiler::ETSGen *etsg) const
62 {
63 etsg->GetAstCompiler()->Compile(this);
64 }
65
Check(checker::TSChecker * checker)66 checker::Type *TSUndefinedKeyword::Check(checker::TSChecker *checker)
67 {
68 return checker->GetAnalyzer()->Check(this);
69 }
70
GetType(checker::TSChecker * checker)71 checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker *checker)
72 {
73 return checker->GlobalUndefinedType();
74 }
75
Check(checker::ETSChecker * checker)76 checker::VerifiedType TSUndefinedKeyword::Check(checker::ETSChecker *checker)
77 {
78 return {this, checker->GetAnalyzer()->Check(this)};
79 }
80 } // namespace ark::es2panda::ir
81