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 #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_PROPERTY_SIGNATURE_H
17 #define ES2PANDA_PARSER_INCLUDE_AST_TS_PROPERTY_SIGNATURE_H
18 
19 #include "ir/expression.h"
20 
21 namespace ark::es2panda::ir {
22 class TypeNode;
23 
24 class TSPropertySignature : public AnnotatedAstNode {
25 public:
26     TSPropertySignature() = delete;
27     ~TSPropertySignature() override = default;
28 
29     NO_COPY_SEMANTIC(TSPropertySignature);
30     NO_MOVE_SEMANTIC(TSPropertySignature);
31 
TSPropertySignature(Expression *key, TypeNode *typeAnnotation, bool computed, bool optional, bool readonly)32     explicit TSPropertySignature(Expression *key, TypeNode *typeAnnotation, bool computed, bool optional, bool readonly)
33         : AnnotatedAstNode(AstNodeType::TS_PROPERTY_SIGNATURE, typeAnnotation),
34           key_(key),
35           computed_(computed),
36           optional_(optional),
37           readonly_(readonly)
38     {
39     }
40 
41     [[nodiscard]] const Expression *Key() const noexcept
42     {
43         return key_;
44     }
45 
46     [[nodiscard]] Expression *Key() noexcept
47     {
48         return key_;
49     }
50 
51     [[nodiscard]] bool Computed() const noexcept
52     {
53         return computed_;
54     }
55 
56     [[nodiscard]] bool Optional() const noexcept
57     {
58         return optional_;
59     }
60 
61     [[nodiscard]] bool Readonly() const noexcept
62     {
63         return readonly_;
64     }
65 
66     [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent) override;
67 
68     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
69     void Iterate(const NodeTraverser &cb) const override;
70 
71     void Dump(ir::AstDumper *dumper) const override;
72     void Dump(ir::SrcDumper *dumper) const override;
73     void Compile(compiler::PandaGen *pg) const override;
74     void Compile(compiler::ETSGen *etsg) const override;
75     checker::Type *Check(checker::TSChecker *checker) override;
76     checker::Type *Check(checker::ETSChecker *checker) override;
77 
78     void Accept(ASTVisitorT *v) override
79     {
80         v->Accept(this);
81     }
82 
83 private:
84     Expression *key_;
85     bool computed_;
86     bool optional_;
87     bool readonly_;
88 };
89 }  // namespace ark::es2panda::ir
90 
91 #endif
92