Class: Minjs::ECMA262::ExpPropBrac
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpPropBrac
- 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
-
#val ⇒ Object
readonly
Returns the value of attribute val.
-
#val2 ⇒ Object
readonly
Returns the value of attribute val2.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#initialize(val, val2) ⇒ ExpPropBrac
constructor
A new instance of ExpPropBrac.
-
#left_hand_side_exp? ⇒ Boolean
True if expression is kind of LeftHandSideExpression.
-
#priority ⇒ Fixnum
Expression priority.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Expression
Methods inherited from Base
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
#val ⇒ Object (readonly)
Returns the value of attribute val.
432 433 434 |
# File 'lib/minjs/ecma262/expression.rb', line 432 def val @val end |
#val2 ⇒ Object (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_paren ⇒ Object
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_dup ⇒ Object
duplicate object
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.
482 483 484 |
# File 'lib/minjs/ecma262/expression.rb', line 482 def left_hand_side_exp? true end |
#priority ⇒ Fixnum
Returns expression priority.
456 457 458 |
# File 'lib/minjs/ecma262/expression.rb', line 456 def priority PRIORITY_LEFT_HAND_SIDE end |
#remove_paren ⇒ Object
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.
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.
477 478 479 |
# File 'lib/minjs/ecma262/expression.rb', line 477 def to_js( = {}) "#{@val.to_js()}[#{@val2.to_js()}]" end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
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 |