Class: Minjs::ECMA262::StExp
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ExpressionStatement 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) ⇒ StExp
constructor
A new instance of StExp.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_exp(options = {}) ⇒ Object
Converts statement to expression and returns it.
-
#to_exp? ⇒ Boolean
true if statement can convert to expression.
-
#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_return?
Methods inherited from Base
Constructor Details
#initialize(exp) ⇒ StExp
Returns a new instance of StExp.
289 290 291 |
# File 'lib/minjs/ecma262/statement.rb', line 289 def initialize(exp) @exp = exp end |
Instance Attribute Details
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
287 288 289 |
# File 'lib/minjs/ecma262/statement.rb', line 287 def exp @exp end |
Instance Method Details
#==(obj) ⇒ Object
compare object
314 315 316 |
# File 'lib/minjs/ecma262/statement.rb', line 314 def ==(obj) self.class == obj.class and @exp == obj.exp end |
#add_paren ⇒ Object
add parenthesis if need
343 344 345 |
# File 'lib/minjs/ecma262/statement.rb', line 343 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
295 296 297 |
# File 'lib/minjs/ecma262/statement.rb', line 295 def deep_dup self.class.new(@exp.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
335 336 337 338 339 340 |
# File 'lib/minjs/ecma262/statement.rb', line 335 def remove_paren if @exp.kind_of? ExpParen @exp = @exp.val if @exp.remove_paren? end self end |
#replace(from, to) ⇒ Object
Replaces children object.
301 302 303 304 305 |
# File 'lib/minjs/ecma262/statement.rb', line 301 def replace(from, to) if @exp .eql? from @exp = to end end |
#to_exp(options = {}) ⇒ Object
Converts statement to expression and returns it.
325 326 327 |
# File 'lib/minjs/ecma262/statement.rb', line 325 def to_exp( = {}) @exp.deep_dup end |
#to_exp? ⇒ Boolean
true if statement can convert to expression
330 331 332 |
# File 'lib/minjs/ecma262/statement.rb', line 330 def to_exp? true end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
320 321 322 |
# File 'lib/minjs/ecma262/statement.rb', line 320 def to_js( = {}) concat(, @exp, ";") end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
308 309 310 311 |
# File 'lib/minjs/ecma262/statement.rb', line 308 def traverse(parent, &block) @exp.traverse(self, &block) yield parent, self end |