class Minjs::ECMA262::ExpParen

Class of the Grouping operator expression element.

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

Attributes

val[R]

Public Class Methods

new(val) click to toggle source
# File lib/minjs/ecma262/expression.rb, line 324
def initialize(val)
  @val = val
end

Public Instance Methods

==(obj) click to toggle source

compare object

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

add parenthesis if need

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

duplicate object @see Base#deep_dup

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

return results of ‘typeof’ operator.

@return [Symbol] type of val

# File lib/minjs/ecma262/expression.rb, line 416
def ecma262_typeof
  if @val.respond_to? :ecma262_typeof
    @val.ecma262_typeof
  else
    nil
  end
end
left_hand_side_exp?() click to toggle source

@return [Boolean] true if expression is kind of LeftHandSideExpression.

# File lib/minjs/ecma262/expression.rb, line 366
def left_hand_side_exp?
  true
end
priority() click to toggle source

@return [Fixnum] expression priority

# File lib/minjs/ecma262/expression.rb, line 329
def priority
  PRIORITY_PRIMARY
end
remove_paren() click to toggle source

remove parenthesis if possible

# File lib/minjs/ecma262/expression.rb, line 387
def remove_paren
  if @val.kind_of? ExpParen
    @val = @val.val if @val.remove_paren?
  end
  self
end
remove_paren?() click to toggle source

returns removing parenthesis is possible or not

ECMA262 expression-statement should not start with “function” or “{”. This method checks inner of the parenthesis’ first literal.

@return [Boolean] true if possible

# File lib/minjs/ecma262/expression.rb, line 377
def remove_paren?
  js = @val.to_js
  if js.match(/^function/) or js.match(/^{/)
    false
  else
    true
  end
end
replace(from, to) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/expression.rb, line 341
def replace(from, to)
  if @val .eql? from
    @val = to
  end
end
to_ecma262_boolean() click to toggle source

Returns results of ToBoolean()

Returns true or false if trivial, otherwise nil.

@return [Boolean]

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

# File lib/minjs/ecma262/expression.rb, line 407
def to_ecma262_boolean
  return nil unless @val.respond_to? :to_ecma262_boolean
  return nil if @val.to_ecma262_boolean.nil?
  @val.to_ecma262_boolean
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 361
def to_js(options = {})
  "(#{@val.to_js(options)})"
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 349
def traverse(parent, &block)
  @val.traverse(self, &block)
  yield parent, self
end