Class: Minjs::ECMA262::StReturn
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ReturnStatement element.
Instance Attribute Summary collapse
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
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(exp = nil) ⇒ StReturn
constructor
A new instance of StReturn.
-
#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.
-
#to_return ⇒ Object
Converts block to ‘return statement’ and returns it.
-
#to_return? ⇒ Boolean
return true if statement can convert to return statement.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Statement
Methods inherited from Base
Constructor Details
#initialize(exp = nil) ⇒ StReturn
Returns a new instance of StReturn.
1089 1090 1091 |
# File 'lib/minjs/ecma262/statement.rb', line 1089 def initialize(exp = nil) @exp = exp end |
Instance Attribute Details
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
1087 1088 1089 |
# File 'lib/minjs/ecma262/statement.rb', line 1087 def exp @exp end |
Instance Method Details
#==(obj) ⇒ Object
compare object
1124 1125 1126 |
# File 'lib/minjs/ecma262/statement.rb', line 1124 def ==(obj) self.class == obj.class and @exp == obj.exp end |
#add_paren ⇒ Object
add parenthesis if need
1147 1148 1149 |
# File 'lib/minjs/ecma262/statement.rb', line 1147 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
1095 1096 1097 |
# File 'lib/minjs/ecma262/statement.rb', line 1095 def deep_dup self.class.new(exp ? exp.deep_dup : nil) end |
#remove_paren ⇒ Object
remove parenthesis if possible
1139 1140 1141 1142 1143 1144 |
# File 'lib/minjs/ecma262/statement.rb', line 1139 def remove_paren if @exp.kind_of? ExpParen @exp = @exp.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
1101 1102 1103 1104 1105 |
# File 'lib/minjs/ecma262/statement.rb', line 1101 def replace(from, to) if from .eql? @exp @exp = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/minjs/ecma262/statement.rb', line 1130 def to_js( = {}) if @exp concat , :return, @exp, ";" else concat , :return, ";" end end |
#to_return ⇒ Object
Converts block to ‘return statement’ and returns it
1119 1120 1121 |
# File 'lib/minjs/ecma262/statement.rb', line 1119 def to_return self end |
#to_return? ⇒ Boolean
return true if statement can convert to return statement.
1114 1115 1116 |
# File 'lib/minjs/ecma262/statement.rb', line 1114 def to_return? true end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
1108 1109 1110 1111 |
# File 'lib/minjs/ecma262/statement.rb', line 1108 def traverse(parent, &block) @exp.traverse(self, &block) if @exp yield parent, self end |