Class: Minjs::ECMA262::ExpCond
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpCond
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the Conditional operator expression element.
Instance Attribute Summary collapse
-
#val ⇒ Object
(also: #cond)
readonly
Returns the value of attribute val.
-
#val2 ⇒ Object
readonly
Returns the value of attribute val2.
-
#val3 ⇒ Object
readonly
Returns the value of attribute val3.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
-
#initialize(val, val2, val3) ⇒ ExpCond
constructor
A new instance of ExpCond.
-
#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
#left_hand_side_exp?, #reduce, #side_effect?
Methods inherited from Base
Constructor Details
#initialize(val, val2, val3) ⇒ ExpCond
Returns a new instance of ExpCond.
1893 1894 1895 1896 1897 |
# File 'lib/minjs/ecma262/expression.rb', line 1893 def initialize(val, val2, val3) @val = val @val2 = val2 @val3 = val3 end |
Instance Attribute Details
#val ⇒ Object (readonly) Also known as: cond
Returns the value of attribute val.
1890 1891 1892 |
# File 'lib/minjs/ecma262/expression.rb', line 1890 def val @val end |
#val2 ⇒ Object (readonly)
Returns the value of attribute val2.
1890 1891 1892 |
# File 'lib/minjs/ecma262/expression.rb', line 1890 def val2 @val2 end |
#val3 ⇒ Object (readonly)
Returns the value of attribute val3.
1890 1891 1892 |
# File 'lib/minjs/ecma262/expression.rb', line 1890 def val3 @val3 end |
Instance Method Details
#==(obj) ⇒ Object
compare object
1960 1961 1962 1963 1964 1965 |
# File 'lib/minjs/ecma262/expression.rb', line 1960 def ==(obj) self.class == obj.class and @val == obj.val and @val2 == obj.val2 and @val3 == obj.val3 end |
#add_paren ⇒ Object
add parenthesis if need
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 |
# File 'lib/minjs/ecma262/expression.rb', line 1919 def add_paren if @val.priority > PRIORITY_CONDITIONAL @val = ExpParen.new(@val) end if @val2.priority > PRIORITY_ASSIGNMENT @val2 = ExpParen.new(@val2) end if @val3.priority > PRIORITY_ASSIGNMENT @val3 = ExpParen.new(@val3) end self end |
#deep_dup ⇒ Object
duplicate object
1934 1935 1936 |
# File 'lib/minjs/ecma262/expression.rb', line 1934 def deep_dup self.class.new(@val.deep_dup, @val2.deep_dup, @val3.deep_dup) end |
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'lib/minjs/ecma262/expression.rb', line 1976 def ecma262_typeof if @val2.respond_to? :ecma262_typeof and @val3.respond_to? :ecma262_typeof if @val2.ecma262_typeof == @val3.ecma262_typeof return @val2.ecma262_typeof end end nil end |
#priority ⇒ Fixnum
Returns expression priority.
1900 1901 1902 |
# File 'lib/minjs/ecma262/expression.rb', line 1900 def priority PRIORITY_CONDITIONAL end |
#remove_paren ⇒ Object
remove parenthesis if possible
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 |
# File 'lib/minjs/ecma262/expression.rb', line 1905 def remove_paren if @val.kind_of? ExpParen and @val.val.priority < PRIORITY_CONDITIONAL @val = @val.val if @val.remove_paren? end if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT @val2 = @val2.val end if @val3.kind_of? ExpParen and @val3.val.priority <= PRIORITY_ASSIGNMENT @val3 = @val3.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
1940 1941 1942 1943 1944 1945 1946 1947 1948 |
# File 'lib/minjs/ecma262/expression.rb', line 1940 def replace(from, to) if from .eql? @val @val = to elsif from .eql? @val2 @val2 = to elsif from .eql? @val3 @val3 = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
1969 1970 1971 |
# File 'lib/minjs/ecma262/expression.rb', line 1969 def to_js( = {}) "#{@val.to_js()}?#{@val2.to_js()}:#{@val3.to_js()}" end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
1952 1953 1954 1955 1956 1957 |
# File 'lib/minjs/ecma262/expression.rb', line 1952 def traverse(parent, &block) @val.traverse(self, &block) @val2.traverse(self, &block) @val3.traverse(self, &block) yield parent, self end |