Class: Estreet::Expression
Direct Known Subclasses
ArrayExpression, AssignmentExpression, BinaryExpression, CallExpression, FunctionExpression, Identifier, Literal, MemberExpression, ObjectExpression, ThisExpression, UnaryExpression
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.coerce(thing) ⇒ Object
Return an expression if at all possible.
Instance Method Summary collapse
-
#[](member) ⇒ Object
creates a computed MemberExpression.
-
#call(*args) ⇒ Object
Creates a call expression with the receiver as the callee and the specified arguments.
-
#property(prop) ⇒ Object
creates a non-computed MemberExpression, e.g.
- #to_expression ⇒ Object
- #to_statement ⇒ Object
Methods inherited from Node
#as_json, #initialize, #loc, #type
Constructor Details
This class inherits a constructor from Estreet::Node
Class Method Details
.coerce(thing) ⇒ Object
Return an expression if at all possible
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/estreet/expression.rb', line 12 def self.coerce(thing) case thing when Expression thing when Array ArrayExpression.new(thing.map {|element| element }) when Symbol, String Identifier.new(thing) else raise TypeError, "Can't convert to expression: #{thing.inspect}" end end |
Instance Method Details
#[](member) ⇒ Object
creates a computed MemberExpression
37 38 39 40 |
# File 'lib/estreet/expression.rb', line 37 def [](member) member = Literal[member] unless member.is_a? Expression MemberExpression.new(self, member, true) end |
#call(*args) ⇒ Object
Creates a call expression with the receiver as the callee and the specified arguments
32 33 34 |
# File 'lib/estreet/expression.rb', line 32 def call(*args) CallExpression.new(self, args) end |
#property(prop) ⇒ Object
creates a non-computed MemberExpression, e.g. ‘object.property` in JS
26 27 28 |
# File 'lib/estreet/expression.rb', line 26 def property(prop) MemberExpression.new(self, Identifier[prop], false) end |
#to_expression ⇒ Object
3 4 5 |
# File 'lib/estreet/expression.rb', line 3 def to_expression self end |
#to_statement ⇒ Object
7 8 9 |
# File 'lib/estreet/expression.rb', line 7 def to_statement ExpressionStatement.new(self, source_location) end |