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_CLASS_PROPERTY_H 17 #define ES2PANDA_PARSER_INCLUDE_AST_CLASS_PROPERTY_H 18 19 #include "ir/base/classElement.h" 20 21 namespace ark::es2panda::checker { 22 class ETSAnalyzer; 23 } // namespace ark::es2panda::checker 24 25 namespace ark::es2panda::ir { 26 class Expression; 27 class TypeNode; 28 29 class ClassProperty : public ClassElement { 30 public: 31 ClassProperty() = delete; 32 ~ClassProperty() override = default; 33 34 NO_COPY_SEMANTIC(ClassProperty); 35 NO_MOVE_SEMANTIC(ClassProperty); 36 ClassProperty(Expression *const key, Expression *const value, TypeNode *const typeAnnotation, ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed)37 explicit ClassProperty(Expression *const key, Expression *const value, TypeNode *const typeAnnotation, 38 ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const isComputed) 39 : ClassElement(AstNodeType::CLASS_PROPERTY, key, value, modifiers, allocator, isComputed), 40 typeAnnotation_(typeAnnotation) 41 { 42 } 43 44 [[nodiscard]] TypeNode *TypeAnnotation() const noexcept 45 { 46 return typeAnnotation_; 47 } 48 49 void SetTypeAnnotation(TypeNode *typeAnnotation) noexcept 50 { 51 typeAnnotation_ = typeAnnotation; 52 } 53 54 [[nodiscard]] PrivateFieldKind ToPrivateFieldKind(bool const isStatic) const override 55 { 56 return isStatic ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; 57 } 58 59 [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; 60 61 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 62 void Iterate(const NodeTraverser &cb) const override; 63 64 void Dump(ir::AstDumper *dumper) const override; 65 void Dump(ir::SrcDumper *dumper) const override; 66 void Compile(compiler::PandaGen *pg) const override; 67 void Compile(compiler::ETSGen *etsg) const override; 68 checker::Type *Check(checker::TSChecker *checker) override; 69 checker::Type *Check(checker::ETSChecker *checker) override; 70 71 void Accept(ASTVisitorT *v) override 72 { 73 v->Accept(this); 74 } 75 76 private: 77 TypeNode *typeAnnotation_; 78 }; 79 } // namespace ark::es2panda::ir 80 81 #endif 82