Class: Minjs::ECMA262::StForInVar

Inherits:
St
  • Object
show all
Defined in:
lib/minjs/ecma262/st.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from St

#empty?, #priority, #to_exp?, #to_return?

Methods inherited from Base

#add_remove_paren, #concat, #to_s

Constructor Details

#initialize(context, var_decl, exp2, statement) ⇒ StForInVar

Returns a new instance of StForInVar.



782
783
784
785
786
787
# File 'lib/minjs/ecma262/st.rb', line 782

def initialize(context, var_decl, exp2, statement)
  @context = context
  @var_decl = var_decl
  @exp2 = exp2
  @statement = statement
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



779
780
781
# File 'lib/minjs/ecma262/st.rb', line 779

def context
  @context
end

#exp2Object (readonly)

Returns the value of attribute exp2.



780
781
782
# File 'lib/minjs/ecma262/st.rb', line 780

def exp2
  @exp2
end

#statementObject (readonly)

Returns the value of attribute statement.



780
781
782
# File 'lib/minjs/ecma262/st.rb', line 780

def statement
  @statement
end

#var_declObject (readonly)

Returns the value of attribute var_decl.



780
781
782
# File 'lib/minjs/ecma262/st.rb', line 780

def var_decl
  @var_decl
end

Instance Method Details

#==(obj) ⇒ Object



819
820
821
822
823
824
# File 'lib/minjs/ecma262/st.rb', line 819

def ==(obj)
  self.class == obj.class and
    @var_decl == obj.var_decl and
    @exp2 == obj.exp2 and
    @statement == obj.statement
end

#add_parenObject



852
853
854
# File 'lib/minjs/ecma262/st.rb', line 852

def add_paren
  self
end

#deep_dupObject



789
790
791
792
793
794
# File 'lib/minjs/ecma262/st.rb', line 789

def deep_dup
  self.class.new(@context,
                 [@var_decl[0].deep_dup, @var_decl[1] ? @var_decl[1].deep_dup : nil],
                 @exp2.deep_dup,
                 @statement.deep_dup)
end

#remove_parenObject



842
843
844
845
846
847
848
849
850
# File 'lib/minjs/ecma262/st.rb', line 842

def remove_paren
  if @var_decl[1] and @var_decl[1].kind_of? ExpParen
    @var_decl[1] = @var_decl[1].val
  end
  if @exp2.kind_of? ExpParen
    @exp2 = @exp2.val
  end
  self
end

#replace(from, to) ⇒ Object



804
805
806
807
808
# File 'lib/minjs/ecma262/st.rb', line 804

def replace(from, to)
  if from .eql? @statement
    @statement = to
  end
end

#to_js(options = {}) ⇒ Object



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# File 'lib/minjs/ecma262/st.rb', line 826

def to_js(options = {})
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
    statement = @statement.statement_list.statement_list[0]
  else
    statement = @statement
  end

  if @var_decl[1] #with initialiser
    _var_decl = concat(options, @var_decl[0], '=', @var_decl[1])
  else
    _var_decl = concat(options, @var_decl[0])
  end

  concat options, :for, "(", :var, _var_decl, :in, @exp2, ")", statement
end

#to_st_for_inObject



810
811
812
813
814
815
816
817
# File 'lib/minjs/ecma262/st.rb', line 810

def to_st_for_in
  if @var_decl[1]
    t = ExpAssign.new(@var_decl[0], @var_decl[1])
  else
    t = @var_decl[0]
  end
  StForIn.new(t, @exp2, @statement)
end

#traverse(parent) {|_self, parent| ... } ⇒ Object

Yields:

  • (_self, parent)

Yield Parameters:



796
797
798
799
800
801
802
# File 'lib/minjs/ecma262/st.rb', line 796

def traverse(parent, &block)
  @var_decl[0].traverse(self, &block)
  @var_decl[1].traverse(self, &block) if @var_decl[1]
  @exp2.traverse(self, &block)
  @statement.traverse(self, &block)
  yield self, parent
end