lib/minjs/ecma262/lit.rb in minjs-0.1.3 vs lib/minjs/ecma262/lit.rb in minjs-0.1.5
- old
+ new
@@ -12,11 +12,11 @@
def to_exp?
false
end
- def priority(exp)
+ def priority
10
end
end
class DivOrRegexpLiteral < Literal
@@ -76,10 +76,14 @@
class Null < Literal
def initialize(val)
@val = :null
end
+ def deep_dup
+ self #not dup
+ end
+
def traverse(parent, &block)
yield self, parent
end
def to_s
@@ -105,10 +109,14 @@
else
@val = :"false"
end
end
+ def deep_dup
+ self #//not dup
+ end
+
def traverse(parent, &block)
yield self, parent
end
def to_js(options = {})
@@ -134,10 +142,15 @@
attr_reader :val
def initialize(val)
@val = val
end
+
+ def deep_dup
+ self.class.new(@val)
+ end
+
def traverse(parent)
yield self, parent
end
def to_js(options = {})
t = "\""
@@ -195,10 +208,14 @@
end
end
@decimal = nil if @decimal == 0
end
+ def deep_dup
+ self.class.new(@integer, @decimal, @exp)
+ end
+
def traverse(parent, &block)
yield self, parent
end
def to_js(options = {})
@@ -297,10 +314,14 @@
def initialize(body, flags)
@body = body
@flags = flags
end
+ def deep_dup
+ self.class.new(@body, @flags)
+ end
+
def traverse(parent)
yield self, parent
end
def to_js(options = {})
@@ -311,12 +332,17 @@
LITERAL_TRUE = Boolean.new(:true)
LITERAL_FALSE = Boolean.new(:false)
class ECMA262Array < Literal
def initialize(val)
- @val = val
+ @val = val # val is Array
end
+
+ def deep_dup
+ self.class.new(@val.collect{|x| x ? x.deep_dup : nil})
+ end
+
def traverse(parent, &block)
yield self, parent
@val.each do |k|
k.traverse(parent, &block)
end
@@ -342,10 +368,15 @@
public
def initialize(val)
@val = val
end
+
+ def deep_dup
+ self.class.new(@val.collect{|x, y| [x.deep_dup, y ? y.deep_dup : y]})
+ end
+
def traverse(parent, &block)
yield self, parent
@val.each do |k, v|
k.traverse(parent, &block)
v.traverse(parent, &block)
@@ -422,15 +453,16 @@
end
end
class IdentifierName < Literal
attr_accessor :context
- attr_accessor :val
+ attr_reader :val
@@sym = {}
def initialize(context, val)
+ @context = context
@val = val.to_sym
end
def self.get(context, val)
@@sym[val] ||= self.new(context, val)
@@ -454,9 +486,13 @@
RESERVED_WORD.index(val)
end
def traverse(parent)
yield self, parent
+ end
+
+ def deep_dup
+ self.class.new(@context, @val)
end
def to_js(options = {})
val.to_s
end