Class: Minjs::ECMA262::StWhile
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ‘while’ IterationStatement element.
Instance Attribute Summary collapse
-
#exp ⇒ Object
readonly
Returns the value of attribute exp.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
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, statement) ⇒ StWhile
constructor
A new instance of StWhile.
-
#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, statement) ⇒ StWhile
Returns a new instance of StWhile.
507 508 509 |
# File 'lib/minjs/ecma262/statement.rb', line 507 def initialize(exp, statement) @exp, @statement = exp, statement end |
Instance Attribute Details
#exp ⇒ Object (readonly)
Returns the value of attribute exp.
505 506 507 |
# File 'lib/minjs/ecma262/statement.rb', line 505 def exp @exp end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
505 506 507 |
# File 'lib/minjs/ecma262/statement.rb', line 505 def statement @statement end |
Instance Method Details
#==(obj) ⇒ Object
compare object
533 534 535 536 537 |
# File 'lib/minjs/ecma262/statement.rb', line 533 def ==(obj) self.class == obj.class and @exp == obj.exp and @statement == obj.statement end |
#add_paren ⇒ Object
add parenthesis if need
560 561 562 |
# File 'lib/minjs/ecma262/statement.rb', line 560 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
513 514 515 |
# File 'lib/minjs/ecma262/statement.rb', line 513 def deep_dup self.class.new(@exp.deep_dup, @statement.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
552 553 554 555 556 557 |
# File 'lib/minjs/ecma262/statement.rb', line 552 def remove_paren if @exp.kind_of? ExpParen @exp = @exp.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
519 520 521 522 523 |
# File 'lib/minjs/ecma262/statement.rb', line 519 def replace(from, to) if from .eql? @statement @statement = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
541 542 543 544 545 546 547 548 549 |
# File 'lib/minjs/ecma262/statement.rb', line 541 def to_js( = {}) if @statement.kind_of? StBlock and @statement.statement_list.length == 1 statement = @statement.statement_list.statement_list[0] else statement = @statement end concat(, :while, "(", @exp, ")", statement) end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
526 527 528 529 530 |
# File 'lib/minjs/ecma262/statement.rb', line 526 def traverse(parent, &block) @exp.traverse(self, &block) @statement.traverse(self, &block) yield parent, self end |