Class: Minjs::ECMA262::ExpPropBrac

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

Overview

Class of the Property Accessors expression element.

This is another expression of ExpProp. This class uses bracket instead of period.

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, val2) ⇒ ExpPropBrac

Returns a new instance of ExpPropBrac.



434
435
436
437
# File 'lib/minjs/ecma262/expression.rb', line 434

def initialize(val, val2)
  @val = val
  @val2 = val2
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



432
433
434
# File 'lib/minjs/ecma262/expression.rb', line 432

def val
  @val
end

#val2Object (readonly)

Returns the value of attribute val2.



432
433
434
# File 'lib/minjs/ecma262/expression.rb', line 432

def val2
  @val2
end

Instance Method Details

#==(obj) ⇒ Object

compare object



469
470
471
472
473
# File 'lib/minjs/ecma262/expression.rb', line 469

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

#add_parenObject

add parenthesis if need



498
499
500
501
502
503
# File 'lib/minjs/ecma262/expression.rb', line 498

def add_paren
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
    @val = ExpParen.new(@val)
  end
  self
end

#deep_dupObject

duplicate object

See Also:



441
442
443
# File 'lib/minjs/ecma262/expression.rb', line 441

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

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



482
483
484
# File 'lib/minjs/ecma262/expression.rb', line 482

def left_hand_side_exp?
  true
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



456
457
458
# File 'lib/minjs/ecma262/expression.rb', line 456

def priority
  PRIORITY_LEFT_HAND_SIDE
end

#remove_parenObject

remove parenthesis if possible



487
488
489
490
491
492
493
494
495
# File 'lib/minjs/ecma262/expression.rb', line 487

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
    @val2 = @val2.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



447
448
449
450
451
452
453
# File 'lib/minjs/ecma262/expression.rb', line 447

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

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



477
478
479
# File 'lib/minjs/ecma262/expression.rb', line 477

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

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



462
463
464
465
466
# File 'lib/minjs/ecma262/expression.rb', line 462

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