module Minjs::ECMA262::AssignmentOperation

Module of typically Assignment operation.

Typically unary operation expression has left-hand value(val) and right-hand value(val2)

Attributes

val[R]
val2[R]

Public Instance Methods

==(obj) click to toggle source

compare object

# File lib/minjs/ecma262/expression.rb, line 220
def ==(obj)
  self.class == obj.class and self.val == obj.val and self.val2 == obj.val2
end
add_paren() click to toggle source

add parenthesis if need

# File lib/minjs/ecma262/expression.rb, line 209
def add_paren
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
    @val = ExpParen.new(@val)
  end
  if @val2.priority > PRIORITY_ASSIGNMENT
    @val2 = ExpParen.new(@val2)
  end
  self
end
deep_dup() click to toggle source

duplicate object @see Base#deep_dup

# File lib/minjs/ecma262/expression.rb, line 237
def deep_dup
  self.class.new(@val.deep_dup, @val2.deep_dup)
end
ecma262_typeof() click to toggle source

return results of ‘typeof’ operator.

@return [Symbol] type of right-side-hand expression

or nil if typeof value is undetermined.
# File lib/minjs/ecma262/expression.rb, line 228
def ecma262_typeof
  if @val2.respond_to? :ecma262_typeof
    @val2.ecma262_typeof
  else
    nil
  end
end
reduce(parent) click to toggle source

reduce expression if available @param parent [Base] parent element

# File lib/minjs/ecma262/expression.rb, line 267
def reduce(parent)
  #
  # a = a / b => a /= b
  #
  if @val2.kind_of? ExpDiv and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpDivAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpMul and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpMulAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpMod and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpModAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpAdd and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpAddAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpSub and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpSubAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpLShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpLShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpRShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpRShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpURShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpURShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpAnd and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpAndAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpOr and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpOrAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpXor and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpXorAssign.new(@val, @val2.val2)))
  end
end
remove_paren() click to toggle source

remove parenthesis if possible

# File lib/minjs/ecma262/expression.rb, line 198
def remove_paren
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @val = @val.val if @val.remove_paren?
  end
  if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT
    @val2 = @val2.val
  end
  self
end
replace(from, to) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/expression.rb, line 243
def replace(from, to)
  if @val .eql? from
    @val = to
  elsif @val2 .eql? from
    @val2 = 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/expression.rb, line 261
def to_js(options = {})
  concat options, @val, sym, @val2
end
traverse(parent) { |parent, self| ... } click to toggle source

Traverses this children and itself with given block. @see Base#traverse

# File lib/minjs/ecma262/expression.rb, line 253
def traverse(parent, &block)
  @val.traverse(self, &block)
  @val2.traverse(self, &block)
  yield parent, self
end