Class: Estreet::MemberExpression

Inherits:
Expression show all
Defined in:
lib/estreet/member_expression.rb

Instance Attribute Summary

Attributes inherited from Node

#source_location

Instance Method Summary collapse

Methods inherited from Expression

#[], #call, coerce, #property, #to_expression, #to_statement

Methods inherited from Node

#as_json, #loc, #type

Constructor Details

#initialize(object, property, computed) ⇒ MemberExpression

Returns a new instance of MemberExpression.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/estreet/member_expression.rb', line 3

def initialize(object, property, computed)
  @obj = object.to_expression
  # computed: true is e.g. "object[index]"
  # computer: false is "object.property"
  @computed = !!computed
  @property = if @computed
    property.to_expression
  else
    Identifier.new(property)
  end
end

Instance Method Details

#attributesObject



15
16
17
# File 'lib/estreet/member_expression.rb', line 15

def attributes
  super.merge(object: @obj, property: @property, computed: @computed)
end

#to_patternObject



19
20
21
# File 'lib/estreet/member_expression.rb', line 19

def to_pattern
  self
end