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 "etsNonNullishTypeNode.h"
17 #include "checker/ETSchecker.h"
18
19 namespace ark::es2panda::ir {
TransformChildren(const NodeTransformer & cb,std::string_view const transformationName)20 void ETSNonNullishTypeNode::TransformChildren([[maybe_unused]] const NodeTransformer &cb,
21 [[maybe_unused]] std::string_view const transformationName)
22 {
23 if (auto *transformedNode = cb(typeNode_); typeNode_ != transformedNode) {
24 typeNode_->SetTransformedNode(transformationName, transformedNode);
25 typeNode_ = static_cast<TypeNode *>(transformedNode);
26 }
27 }
28
Iterate(const NodeTraverser & cb) const29 void ETSNonNullishTypeNode::Iterate([[maybe_unused]] const NodeTraverser &cb) const
30 {
31 cb(typeNode_);
32 }
33
Dump(ir::AstDumper * dumper) const34 void ETSNonNullishTypeNode::Dump(ir::AstDumper *dumper) const
35 {
36 dumper->Add({{"type", "ETSNonNullishType"}, {"typeNode", typeNode_}});
37 }
38
Dump(ir::SrcDumper * dumper) const39 void ETSNonNullishTypeNode::Dump(ir::SrcDumper *dumper) const
40 {
41 for (auto *anno : Annotations()) {
42 anno->Dump(dumper);
43 }
44 typeNode_->Dump(dumper);
45 dumper->Add("!");
46 }
47
Compile(compiler::PandaGen * pg) const48 void ETSNonNullishTypeNode::Compile([[maybe_unused]] compiler::PandaGen *pg) const
49 {
50 ES2PANDA_UNREACHABLE();
51 }
52
Check(checker::TSChecker * checker)53 checker::Type *ETSNonNullishTypeNode::Check([[maybe_unused]] checker::TSChecker *checker)
54 {
55 ES2PANDA_UNREACHABLE();
56 }
57
Check(checker::ETSChecker * checker)58 checker::VerifiedType ETSNonNullishTypeNode::Check([[maybe_unused]] checker::ETSChecker *checker)
59 {
60 return {this, checker->GetAnalyzer()->Check(this)};
61 }
62
GetType(checker::ETSChecker * checker)63 checker::Type *ETSNonNullishTypeNode::GetType([[maybe_unused]] checker::ETSChecker *checker)
64 {
65 return TsType() != nullptr ? TsType() : Check(checker);
66 }
67
Clone(ArenaAllocator * allocator,AstNode * parent)68 ETSNonNullishTypeNode *ETSNonNullishTypeNode::Clone(ArenaAllocator *allocator, AstNode *parent)
69 {
70 TypeNode *typeNode = typeNode_->Clone(allocator, nullptr);
71 ETSNonNullishTypeNode *clone = allocator->New<ir::ETSNonNullishTypeNode>(typeNode, allocator);
72 ES2PANDA_ASSERT(clone);
73 clone->SetParent(parent);
74 clone->typeNode_->SetParent(clone);
75 return clone;
76 }
77 } // namespace ark::es2panda::ir
78