Class: Minjs::ECMA262::StReturn

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

Overview

Base class of ECMA262 ReturnStatement element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

#empty?, #priority, #to_exp?

Methods inherited from Base

#add_remove_paren, #concat

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

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

add parenthesis if need



1147
1148
1149
# File 'lib/minjs/ecma262/statement.rb', line 1147

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



1095
1096
1097
# File 'lib/minjs/ecma262/statement.rb', line 1095

def deep_dup
  self.class.new(exp ? exp.deep_dup : nil)
end

#remove_parenObject

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.

See Also:



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.

See Also:



1130
1131
1132
1133
1134
1135
1136
# File 'lib/minjs/ecma262/statement.rb', line 1130

def to_js(options = {})
  if @exp
    concat options, :return, @exp, ";"
  else
    concat options, :return, ";"
  end
end

#to_returnObject

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.

Returns:



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.

Yields:

Yield Parameters:



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