Class: Minjs::ECMA262::ExpProp

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

Overview

Class of the Property Accessors expression element.

This is another expression of ExpPropBrac. This class uses period insted of bracket.

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) ⇒ ExpProp

Returns a new instance of ExpProp.



515
516
517
518
519
520
521
522
# File 'lib/minjs/ecma262/expression.rb', line 515

def initialize(val, val2)
  @val = val
  if val2.kind_of? IdentifierName
    @val2 = ECMA262::ECMA262String.new(val2.val)
  elsif val2.kind_of? ECMA262String
    @val2 = val2
  end
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



513
514
515
# File 'lib/minjs/ecma262/expression.rb', line 513

def val
  @val
end

#val2Object (readonly)

Returns the value of attribute val2.



513
514
515
# File 'lib/minjs/ecma262/expression.rb', line 513

def val2
  @val2
end

Instance Method Details

#==(obj) ⇒ Object

compare object



554
555
556
557
558
# File 'lib/minjs/ecma262/expression.rb', line 554

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

#add_parenObject

add parenthesis if need



580
581
582
583
584
585
# File 'lib/minjs/ecma262/expression.rb', line 580

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

#deep_dupObject

duplicate object

See Also:



526
527
528
# File 'lib/minjs/ecma262/expression.rb', line 526

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.



567
568
569
# File 'lib/minjs/ecma262/expression.rb', line 567

def left_hand_side_exp?
  true
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



531
532
533
# File 'lib/minjs/ecma262/expression.rb', line 531

def priority
  PRIORITY_LEFT_HAND_SIDE
end

#remove_parenObject

remove parenthesis if possible



572
573
574
575
576
577
# File 'lib/minjs/ecma262/expression.rb', line 572

def remove_paren
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @val = @val.val if @val.remove_paren?
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



537
538
539
540
541
542
543
# File 'lib/minjs/ecma262/expression.rb', line 537

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:



562
563
564
# File 'lib/minjs/ecma262/expression.rb', line 562

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

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



547
548
549
550
551
# File 'lib/minjs/ecma262/expression.rb', line 547

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