class Minjs::ECMA262::StSwitch

Base class of ECMA262 SwitchStatement element.

@see www.ecma-international.org/ecma-262 ECMA262 12.11

Attributes

blocks[R]
exp[R]

Public Class Methods

new(exp, blocks) click to toggle source

block: [condition, blocks]

# File lib/minjs/ecma262/statement.rb, line 1223
def initialize(exp, blocks)
  @exp = exp
  @blocks = blocks
end

Public Instance Methods

==(obj) click to toggle source

compare object

# File lib/minjs/ecma262/statement.rb, line 1263
def ==(obj)
  self.class == obj.class and
    @exp == obj.exp and
    @blocks == obj.blocks
end
add_paren() click to toggle source

add parenthesis if need

# File lib/minjs/ecma262/statement.rb, line 1297
def add_paren
  self
end
deep_dup() click to toggle source

duplicate object @see Base#deep_dup

# File lib/minjs/ecma262/statement.rb, line 1230
def deep_dup
  self.class.new(@exp.deep_dup,
                 @blocks.collect{|x, y|
                   [
                     x ? x.deep_dup : nil,
                     y ? y.deep_dup : nil
                   ]
                 })
end
remove_paren() click to toggle source

remove parenthesis if possible

# File lib/minjs/ecma262/statement.rb, line 1284
def remove_paren
  if @exp.kind_of? ExpParen
    @exp = @exp.val
  end
  @blocks.each do |b|
    if b[0] and b[0].kind_of? ExpParen
      b[0] = b[0].val
    end
  end
  self
end
replace(from, to) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/statement.rb, line 1242
def replace(from, to)
  if @exp .eql? from
    @exp = to
  elsif @blocks .eql? from
    @blocks = to
  end
end
to_js(options = {}) click to toggle source

Returns a ECMAScript string containg the representation of element. @see Base#to_js

# File lib/minjs/ecma262/statement.rb, line 1271
def to_js(options = {})
  t = concat(options, :switch, "(", @exp, ")", "{")
  @blocks.each do |b|
    if b[0]
      t = concat(options, t, :case, b[0], ":", b[1])
    else
      t = concat(options, t, :default, ":", b[1])
    end
  end
  t = concat(options, t, "}")
end
traverse(parent) { |parent, self| ... } click to toggle source

Traverses this children and itself with given block.

# File lib/minjs/ecma262/statement.rb, line 1251
def traverse(parent, &blocks)
  @exp.traverse(self, &blocks)
  @blocks.each do |b|
    if b[0]
      b[0].traverse(self, &blocks)
    end
    b[1].traverse(self, &blocks)
  end
  yield parent, self
end