class Minjs::ECMA262::StVar
Base
class of ECMA262
VariableStatement element.
@see www.ecma-international.org/ecma-262 ECMA262
12.2
Attributes
var_env[R]
vars[R]
Public Class Methods
new(var_env, vars)
click to toggle source
vars:
[[name0,init0],[name1,init1],...]
# File lib/minjs/ecma262/statement.rb, line 152 def initialize(var_env, vars) @vars = vars @var_env = var_env end
Public Instance Methods
==(obj)
click to toggle source
compare object
# File lib/minjs/ecma262/statement.rb, line 192 def ==(obj) self.class == obj.class and @vars == obj.vars end
add_paren()
click to toggle source
add parenthesis if need
# File lib/minjs/ecma262/statement.rb, line 238 def add_paren @vars.each do |x| if x[1] and x[1].priority > PRIORITY_ASSIGNMENT x[1] = ExpParen.new(x[1]) end end self end
deep_dup()
click to toggle source
duplicate object @see Base#deep_dup
# File lib/minjs/ecma262/statement.rb, line 159 def deep_dup self.class.new(@var_env, @vars.collect{|x,y| [x.deep_dup, y ? y.deep_dup : nil] }) end
normalization()
click to toggle source
If variable has no initializer, this method moves it to latter
# File lib/minjs/ecma262/statement.rb, line 214 def normalization v1 = [] v2 = [] @vars.each do |x| if x[1].nil? v2.push(x) else v1.push(x) end end @vars = v1.concat(v2) end
remove_paren()
click to toggle source
remove parenthesis if possible
# File lib/minjs/ecma262/statement.rb, line 228 def remove_paren @vars.each do |x| if x[1] and x[1].kind_of? ExpParen and x[1].val.priority <= PRIORITY_ASSIGNMENT x[1] = x[1].val end end self end
replace(from, to)
click to toggle source
Replaces children object. @see Base#replace
# File lib/minjs/ecma262/statement.rb, line 168 def replace(from, to) @vars.each do |x| if x[0] .eql? from x[0] = to break elsif x[1] and x[1] .eql? from x[1] = to break end end end
to_js(options = {})
click to toggle source
Returns a ECMAScript string containg the representation of element. @see Base#to_js
# File lib/minjs/ecma262/statement.rb, line 198 def to_js(options = {}) t = concat(options, :var, @vars.collect{|x| if x[1] concat options, x[0], '=', x[1] else concat options, x[0] end }.join(",")) if t.length > 0 concat(options, t, ";") else "" end end
traverse(parent) { |parent, self| ... }
click to toggle source
Traverses this children and itself with given block.
# File lib/minjs/ecma262/statement.rb, line 181 def traverse(parent, &block) @vars.each do |x| x[0].traverse(self, &block) if x[1] x[1].traverse(self, &block) end end yield parent, self end