Class: Minjs::ECMA262::ExpCall
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpCall
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the Call expression element.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
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(name, args) ⇒ ExpCall
constructor
A new instance of ExpCall.
-
#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(name, args) ⇒ ExpCall
Returns a new instance of ExpCall.
594 595 596 597 |
# File 'lib/minjs/ecma262/expression.rb', line 594 def initialize(name, args) @name = name @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
592 593 594 |
# File 'lib/minjs/ecma262/expression.rb', line 592 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
591 592 593 |
# File 'lib/minjs/ecma262/expression.rb', line 591 def name @name end |
Instance Method Details
#==(obj) ⇒ Object
compare object
637 638 639 |
# File 'lib/minjs/ecma262/expression.rb', line 637 def ==(obj) self.class == obj.class and @name == obj.name and @args == obj.args end |
#add_paren ⇒ Object
add parenthesis if need
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/minjs/ecma262/expression.rb', line 671 def add_paren if @name.priority > PRIORITY_LEFT_HAND_SIDE @name = ExpParen.new(@name) end if @args @args.map! do |arg| if arg.priority > PRIORITY_ASSIGNMENT ExpParen.new(arg) else arg end end end self end |
#deep_dup ⇒ Object
duplicate object
606 607 608 609 |
# File 'lib/minjs/ecma262/expression.rb', line 606 def deep_dup self.class.new(@name.deep_dup, @args ? @args.collect{|x| x.deep_dup} : nil) end |
#left_hand_side_exp? ⇒ Boolean
Returns true if expression is kind of LeftHandSideExpression.
649 650 651 |
# File 'lib/minjs/ecma262/expression.rb', line 649 def left_hand_side_exp? true end |
#priority ⇒ Fixnum
Returns expression priority.
600 601 602 |
# File 'lib/minjs/ecma262/expression.rb', line 600 def priority PRIORITY_LEFT_HAND_SIDE end |
#remove_paren ⇒ Object
remove parenthesis if possible
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/minjs/ecma262/expression.rb', line 654 def remove_paren if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE @name = @name.val if @name.remove_paren? end if @args @args.map! do |arg| if arg.kind_of? ExpParen and arg.val.priority <= PRIORITY_ASSIGNMENT #AssignmentOperators arg.val if arg.remove_paren? else arg end end end self end |
#replace(from, to) ⇒ Object
Replaces children object.
613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/minjs/ecma262/expression.rb', line 613 def replace(from, to) if @name .eql? from @name = to else @args.each_index do |i| arg = @args[i] if arg .eql? from @args[i] = to break end end end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
643 644 645 646 |
# File 'lib/minjs/ecma262/expression.rb', line 643 def to_js( = {}) args = @args.collect{|x| x.to_js()}.join(",") "#{@name.to_js()}(#{args})" end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
628 629 630 631 632 633 634 |
# File 'lib/minjs/ecma262/expression.rb', line 628 def traverse(parent, &block) @name.traverse(self, &block) @args.each do |x| x.traverse(self, &block) end yield parent, self end |