Class: Minjs::ECMA262::StExp

Inherits:
Statement show all
Defined in:
lib/minjs/ecma262/statement.rb

Overview

Base class of ECMA262 ExpressionStatement element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

#empty?, #priority, #to_return?

Methods inherited from Base

#add_remove_paren, #concat

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

#expObject (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_parenObject

add parenthesis if need



343
344
345
# File 'lib/minjs/ecma262/statement.rb', line 343

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



295
296
297
# File 'lib/minjs/ecma262/statement.rb', line 295

def deep_dup
  self.class.new(@exp.deep_dup)
end

#remove_parenObject

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.

See Also:



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(options = {})
  @exp.deep_dup
end

#to_exp?Boolean

true if statement can convert to expression

Returns:



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.

See Also:



320
321
322
# File 'lib/minjs/ecma262/statement.rb', line 320

def to_js(options = {})
  concat(options, @exp, ";")
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:



308
309
310
311
# File 'lib/minjs/ecma262/statement.rb', line 308

def traverse(parent, &block)
  @exp.traverse(self, &block)
  yield parent, self
end