Class: Minjs::ECMA262::ExpParen

Inherits:
Expression show all
Defined in:
lib/minjs/ecma262/expression.rb

Overview

Class of the Grouping operator expression element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Expression

#reduce, #side_effect?

Methods inherited from Base

#add_remove_paren, #concat

Constructor Details

#initialize(val) ⇒ ExpParen

Returns a new instance of ExpParen.



324
325
326
# File 'lib/minjs/ecma262/expression.rb', line 324

def initialize(val)
  @val = val
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



322
323
324
# File 'lib/minjs/ecma262/expression.rb', line 322

def val
  @val
end

Instance Method Details

#==(obj) ⇒ Object

compare object



355
356
357
# File 'lib/minjs/ecma262/expression.rb', line 355

def ==(obj)
  self.class == obj.class and @val == obj.val
end

#add_parenObject

add parenthesis if need



395
396
397
# File 'lib/minjs/ecma262/expression.rb', line 395

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



335
336
337
# File 'lib/minjs/ecma262/expression.rb', line 335

def deep_dup
  self.class.new(@val.deep_dup)
end

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    type of val



416
417
418
419
420
421
422
# 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?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



366
367
368
# File 'lib/minjs/ecma262/expression.rb', line 366

def left_hand_side_exp?
  true
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



329
330
331
# File 'lib/minjs/ecma262/expression.rb', line 329

def priority
  PRIORITY_PRIMARY
end

#remove_parenObject

remove parenthesis if possible



387
388
389
390
391
392
# 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?Boolean

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.

Returns:



377
378
379
380
381
382
383
384
# 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) ⇒ Object

Replaces children object.

See Also:



341
342
343
344
345
# File 'lib/minjs/ecma262/expression.rb', line 341

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

#to_ecma262_booleanBoolean

Returns results of ToBoolean()

Returns true or false if trivial, otherwise nil.

Returns:

See Also:



407
408
409
410
411
# 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 = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



361
362
363
# File 'lib/minjs/ecma262/expression.rb', line 361

def to_js(options = {})
  "(#{@val.to_js(options)})"
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



349
350
351
352
# File 'lib/minjs/ecma262/expression.rb', line 349

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