Class: Minjs::ECMA262::StDoWhile

Inherits:
Statement show all
Defined in:
lib/minjs/ecma262/statement.rb

Overview

Base class of ECMA262 ‘do-while’ IterationStatement element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

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

Methods inherited from Base

#add_remove_paren, #concat

Constructor Details

#initialize(exp, statement) ⇒ StDoWhile

Returns a new instance of StDoWhile.



571
572
573
# File 'lib/minjs/ecma262/statement.rb', line 571

def initialize(exp, statement)
  @exp, @statement = exp, statement
end

Instance Attribute Details

#expObject (readonly)

Returns the value of attribute exp.



569
570
571
# File 'lib/minjs/ecma262/statement.rb', line 569

def exp
  @exp
end

#statementObject (readonly)

Returns the value of attribute statement.



569
570
571
# File 'lib/minjs/ecma262/statement.rb', line 569

def statement
  @statement
end

Instance Method Details

#==(obj) ⇒ Object

compare object



597
598
599
600
601
# File 'lib/minjs/ecma262/statement.rb', line 597

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

#add_parenObject

add parenthesis if need



624
625
626
# File 'lib/minjs/ecma262/statement.rb', line 624

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



577
578
579
# File 'lib/minjs/ecma262/statement.rb', line 577

def deep_dup
  self.class.new(@exp.deep_dup, @statement.deep_dup)
end

#remove_parenObject

remove parenthesis if possible



616
617
618
619
620
621
# File 'lib/minjs/ecma262/statement.rb', line 616

def remove_paren
  if @exp.kind_of? ExpParen
    @exp = @exp.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



583
584
585
586
587
# File 'lib/minjs/ecma262/statement.rb', line 583

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

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



605
606
607
608
609
610
611
612
613
# File 'lib/minjs/ecma262/statement.rb', line 605

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

  concat options, :do, statement, :while, "(", @exp, ")", ";"
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:



590
591
592
593
594
# File 'lib/minjs/ecma262/statement.rb', line 590

def traverse(parent, &block)
  @exp.traverse(self, &block)
  @statement.traverse(self, &block)
  yield parent, self
end