diff options
author | davidot <david.tuin@gmail.com> | 2021-08-28 17:11:05 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-01 13:39:14 +0100 |
commit | def8b44c4083f2d79bdb7b44701d6a353cb52394 (patch) | |
tree | aad665b8885c15f53acd6aa35048d17b867bfcb9 /Userland/Libraries/LibJS/AST.h | |
parent | 3b6a8d1d53e4d530ff827e2ab3e61388ff62cb8b (diff) | |
download | serenity-def8b44c4083f2d79bdb7b44701d6a353cb52394.zip |
LibJS: Add support for public fields in classes
Diffstat (limited to 'Userland/Libraries/LibJS/AST.h')
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 838450e8a4..b400640bce 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -933,6 +933,30 @@ private: bool m_is_static; }; +class ClassField final : public ASTNode { +public: + ClassField(SourceRange source_range, NonnullRefPtr<Expression> key, RefPtr<Expression> init, bool is_static) + : ASTNode(source_range) + , m_key(move(key)) + , m_initializer(move(init)) + , m_is_static(is_static) + { + } + + Expression const& key() const { return *m_key; } + bool is_static() const { return m_is_static; } + RefPtr<Expression> const& initializer() const { return m_initializer; } + RefPtr<Expression>& initializer() { return m_initializer; } + + virtual Value execute(Interpreter&, GlobalObject&) const override; + virtual void dump(int indent) const override; + +private: + NonnullRefPtr<Expression> m_key; + RefPtr<Expression> m_initializer; + bool m_is_static; +}; + class SuperExpression final : public Expression { public: explicit SuperExpression(SourceRange source_range) @@ -948,12 +972,13 @@ public: class ClassExpression final : public Expression { public: - ClassExpression(SourceRange source_range, String name, RefPtr<FunctionExpression> constructor, RefPtr<Expression> super_class, NonnullRefPtrVector<ClassMethod> methods) + ClassExpression(SourceRange source_range, String name, RefPtr<FunctionExpression> constructor, RefPtr<Expression> super_class, NonnullRefPtrVector<ClassMethod> methods, NonnullRefPtrVector<ClassField> fields) : Expression(source_range) , m_name(move(name)) , m_constructor(move(constructor)) , m_super_class(move(super_class)) , m_methods(move(methods)) + , m_fields(move(fields)) { } @@ -968,6 +993,7 @@ private: RefPtr<FunctionExpression> m_constructor; RefPtr<Expression> m_super_class; NonnullRefPtrVector<ClassMethod> m_methods; + NonnullRefPtrVector<ClassField> m_fields; }; class ClassDeclaration final : public Declaration { |