Class: Minjs::ECMA262::StSwitch
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 SwitchStatement element.
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#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, blocks) ⇒ StSwitch
constructor
block: [condition, blocks].
-
#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 Statement
#empty?, #priority, #to_exp?, #to_return?
Methods inherited from Base
Constructor Details
#initialize(exp, blocks) ⇒ StSwitch
block: [condition, blocks]
1223 1224 1225 1226 |
# File 'lib/minjs/ecma262/statement.rb', line 1223 def initialize(exp, blocks) @exp = exp @blocks = blocks end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
1218 1219 1220 |
# File 'lib/minjs/ecma262/statement.rb', line 1218 def blocks @blocks end |
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
1218 1219 1220 |
# File 'lib/minjs/ecma262/statement.rb', line 1218 def exp @exp end |
Instance Method Details
#==(obj) ⇒ Object
compare object
1263 1264 1265 1266 1267 |
# File 'lib/minjs/ecma262/statement.rb', line 1263 def ==(obj) self.class == obj.class and @exp == obj.exp and @blocks == obj.blocks end |
#add_paren ⇒ Object
add parenthesis if need
1297 1298 1299 |
# File 'lib/minjs/ecma262/statement.rb', line 1297 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/minjs/ecma262/statement.rb', line 1230 def deep_dup self.class.new(@exp.deep_dup, @blocks.collect{|x, y| [ x ? x.deep_dup : nil, y ? y.deep_dup : nil ] }) end |
#remove_paren ⇒ Object
remove parenthesis if possible
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/minjs/ecma262/statement.rb', line 1284 def remove_paren if @exp.kind_of? ExpParen @exp = @exp.val end @blocks.each do |b| if b[0] and b[0].kind_of? ExpParen b[0] = b[0].val end end self end |
#replace(from, to) ⇒ Object
Replaces children object.
1242 1243 1244 1245 1246 1247 1248 |
# File 'lib/minjs/ecma262/statement.rb', line 1242 def replace(from, to) if @exp .eql? from @exp = to elsif @blocks .eql? from @blocks = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/minjs/ecma262/statement.rb', line 1271 def to_js( = {}) t = concat(, :switch, "(", @exp, ")", "{") @blocks.each do |b| if b[0] t = concat(, t, :case, b[0], ":", b[1]) else t = concat(, t, :default, ":", b[1]) end end t = concat(, t, "}") end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 |
# File 'lib/minjs/ecma262/statement.rb', line 1251 def traverse(parent, &blocks) @exp.traverse(self, &blocks) @blocks.each do |b| if b[0] b[0].traverse(self, &blocks) end b[1].traverse(self, &blocks) end yield parent, self end |