summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.h
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-05-21 17:28:28 -0700
committerAndreas Kling <kling@serenityos.org>2020-05-22 10:59:05 +0200
commitc35732c0112abc41731609f09ef566f25bc6dcc3 (patch)
tree08673eb520ea66ff7852d551bd690da5ac8c798f /Libraries/LibJS/AST.h
parent3a90a01dd405d1eb8ebad6e085586093d27c6357 (diff)
downloadserenity-c35732c0112abc41731609f09ef566f25bc6dcc3.zip
LibJS: Add object literal getter/setter shorthand
Adds support for the following syntax: let foo = { get x() { // ... }, set x(value) { // ... } }
Diffstat (limited to 'Libraries/LibJS/AST.h')
-rw-r--r--Libraries/LibJS/AST.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h
index aa81e3927c..7d68284889 100644
--- a/Libraries/LibJS/AST.h
+++ b/Libraries/LibJS/AST.h
@@ -722,17 +722,24 @@ private:
class ObjectProperty final : public ASTNode {
public:
- ObjectProperty(NonnullRefPtr<Expression> key, NonnullRefPtr<Expression> value)
+ enum class Type {
+ KeyValue,
+ Getter,
+ Setter,
+ Spread,
+ };
+
+ ObjectProperty(NonnullRefPtr<Expression> key, NonnullRefPtr<Expression> value, Type property_type)
: m_key(move(key))
, m_value(move(value))
+ , m_property_type(property_type)
{
}
const Expression& key() const { return m_key; }
const Expression& value() const { return m_value; }
- bool is_spread() const { return m_is_spread; }
- void set_is_spread() { m_is_spread = true; }
+ Type type() const { return m_property_type; }
virtual void dump(int indent) const override;
virtual Value execute(Interpreter&) const override;
@@ -742,7 +749,7 @@ private:
NonnullRefPtr<Expression> m_key;
NonnullRefPtr<Expression> m_value;
- bool m_is_spread { false };
+ Type m_property_type;
};
class ObjectExpression : public Expression {