Class: Minjs::ECMA262::ExpNew
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpNew
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the New 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) ⇒ ExpNew
constructor
A new instance of ExpNew.
-
#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) ⇒ ExpNew
Returns a new instance of ExpNew.
695 696 697 698 |
# File 'lib/minjs/ecma262/expression.rb', line 695 def initialize(name, args) @name = name @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
693 694 695 |
# File 'lib/minjs/ecma262/expression.rb', line 693 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
693 694 695 |
# File 'lib/minjs/ecma262/expression.rb', line 693 def name @name end |
Instance Method Details
#==(obj) ⇒ Object
compare object
737 738 739 |
# File 'lib/minjs/ecma262/expression.rb', line 737 def ==(obj) self.class == obj.class and @name == obj.name and @args == obj.args end |
#add_paren ⇒ Object
add parenthesis if need
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
# File 'lib/minjs/ecma262/expression.rb', line 775 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
707 708 709 710 |
# File 'lib/minjs/ecma262/expression.rb', line 707 def deep_dup self.class.new(@name, @args ? @args.collect{|x| x.deep_dup} : nil) end |
#left_hand_side_exp? ⇒ Boolean
Returns true if expression is kind of LeftHandSideExpression.
753 754 755 |
# File 'lib/minjs/ecma262/expression.rb', line 753 def left_hand_side_exp? true end |
#priority ⇒ Fixnum
Returns expression priority.
701 702 703 |
# File 'lib/minjs/ecma262/expression.rb', line 701 def priority PRIORITY_LEFT_HAND_SIDE + ((args == nil) ? 1 : 0) end |
#remove_paren ⇒ Object
remove parenthesis if possible
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
# File 'lib/minjs/ecma262/expression.rb', line 758 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 arg.val if arg.remove_paren? else arg end end end self end |
#replace(from, to) ⇒ Object
Replaces children object.
714 715 716 717 718 719 720 721 722 |
# File 'lib/minjs/ecma262/expression.rb', line 714 def replace(from, to) if @name .eql? from @name = from elsif @args .eql? from @args = to elsif @args and (idx = @args.index(from)) @args[idx] = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
743 744 745 746 747 748 749 750 |
# File 'lib/minjs/ecma262/expression.rb', line 743 def to_js( = {}) if @args args = @args.collect{|x| x.to_js()}.join(",") concat , :new, @name, '(', args, ')' else concat , :new, @name end end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
726 727 728 729 730 731 732 733 734 |
# File 'lib/minjs/ecma262/expression.rb', line 726 def traverse(parent, &block) @name.traverse(self, &block) if @args @args.each do |arg| arg.traverse(self, &block) end end yield parent, self end |