Class: Minjs::ECMA262::StWhile

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

Overview

Base class of ECMA262 ‘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) ⇒ StWhile

Returns a new instance of StWhile.



507
508
509
# File 'lib/minjs/ecma262/statement.rb', line 507

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

Instance Attribute Details

#expObject (readonly)

Returns the value of attribute exp.



505
506
507
# File 'lib/minjs/ecma262/statement.rb', line 505

def exp
  @exp
end

#statementObject (readonly)

Returns the value of attribute statement.



505
506
507
# File 'lib/minjs/ecma262/statement.rb', line 505

def statement
  @statement
end

Instance Method Details

#==(obj) ⇒ Object

compare object



533
534
535
536
537
# File 'lib/minjs/ecma262/statement.rb', line 533

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

#add_parenObject

add parenthesis if need



560
561
562
# File 'lib/minjs/ecma262/statement.rb', line 560

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



513
514
515
# File 'lib/minjs/ecma262/statement.rb', line 513

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

#remove_parenObject

remove parenthesis if possible



552
553
554
555
556
557
# File 'lib/minjs/ecma262/statement.rb', line 552

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

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



519
520
521
522
523
# File 'lib/minjs/ecma262/statement.rb', line 519

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:



541
542
543
544
545
546
547
548
549
# File 'lib/minjs/ecma262/statement.rb', line 541

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, :while, "(", @exp, ")", statement)
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:



526
527
528
529
530
# File 'lib/minjs/ecma262/statement.rb', line 526

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