lib/minjs/ecma262/exp.rb in minjs-0.2.2 vs lib/minjs/ecma262/exp.rb in minjs-0.3.0
- old
+ new
@@ -28,10 +28,14 @@
end
def reduce(parent)
end
+ def left_hand_side_exp?
+ false
+ end
+
def priority
9999
end
end
@@ -44,10 +48,11 @@
if @val2.kind_of? ExpParen and @val2.val.priority < self.priority
@val2 = @val2.val
end
self
end
+
def add_paren
if @val.priority > self.priority
@val = ExpParen.new(@val)
end
if @val2.priority > self.priority
@@ -140,10 +145,14 @@
end
def to_js(options = {})
concat options, sym, @val
end
+
+ def left_hand_side_exp?
+ true
+ end
end
class ExpArg2 < Exp
attr_reader :val, :val2
@@ -210,10 +219,14 @@
def to_js(options = {})
"(#{@val.to_js(options)})"
end
+ def left_hand_side_exp?
+ true
+ end
+
def remove_paren?
js = @val.to_js
if js.match(/^function/) or js.match(/^{/)
false
else
@@ -272,10 +285,14 @@
def to_js(options = {})
"#{@val.to_js(options)}[#{@val2.to_js(options)}]"
end
+ def left_hand_side_exp?
+ true
+ end
+
def remove_paren
if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
@val = @val.val if @val.remove_paren?
end
if @val2.kind_of? ExpParen
@@ -284,11 +301,11 @@
self
end
def add_paren
if @val.priority > PRIORITY_LEFT_HAND_SIDE
- @val = ExpPare.new(@val)
+ @val = ExpParen.new(@val)
end
self
end
end
#
@@ -322,10 +339,14 @@
def to_js(options = {})
"#{@val.to_js(options)}.#{@val2.val}"
end
+ def left_hand_side_exp?
+ true
+ end
+
def remove_paren
if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
@val = @val.val if @val.remove_paren?
end
self
@@ -388,10 +409,14 @@
def to_js(options = {})
args = @args.collect{|x| x.to_js(options)}.join(",")
"#{@name.to_js(options)}(#{args})"
end
+ def left_hand_side_exp?
+ true
+ end
+
def remove_paren
if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
@name = @name.val if @name.remove_paren?
end
if @args
@@ -406,11 +431,11 @@
self
end
def add_paren
if @name.priority > PRIORITY_LEFT_HAND_SIDE
- @name = ExpPare.new(@name)
+ @name = ExpParen.new(@name)
end
if @args
@args.map! do |arg|
if arg.priority > PRIORITY_ASSIGNMENT
ExpParen.new(arg)
@@ -474,9 +499,13 @@
args = @args.collect{|x| x.to_js(options)}.join(",")
concat options, :new, @name, '(', args, ')'
else
concat options, :new, @name
end
+ end
+
+ def left_hand_side_exp?
+ true
end
def remove_paren
if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
@name = @name.val if @name.remove_paren?