lib/minjs/ecma262/base.rb in minjs-0.2.1 vs lib/minjs/ecma262/base.rb in minjs-0.2.2

- old
+ new

@@ -65,10 +65,20 @@ def ==(obj) puts "warning: #{self.class}: == not implement" raise "warning: #{self.class}: == not implement" end + + def add_remove_paren(node = self) + node.traverse(nil) {|st, parent| + if st.respond_to? :remove_paren + st.add_paren + st.remove_paren + end + } + node + end end class StatementList < Base attr_reader :statement_list @@ -109,12 +119,20 @@ new_sl.push(StExp.new(t)) end end if idx = new_sl.index{|x| x.class == StReturn} - while idx < new_sl.length - 1 - new_sl.pop + idx += 1 + while idx < new_sl.length + if new_sl[idx].kind_of? StVar + ; + elsif new_sl[idx].kind_of? StFunc + ; + else + new_sl[idx] = StEmpty.new + end + idx += 1 end end if self.kind_of? SourceElements if new_sl[-1].kind_of? StReturn and new_sl[-1].exp.nil? @@ -151,10 +169,11 @@ x.class == StEmpty } end def traverse(parent, &block) + _self = self @statement_list.each do|st| st.traverse(self, &block) end yield self, parent end @@ -238,9 +257,16 @@ end def deep_dup self.class.new(context, source_elements.deep_dup) end + + def replace(from, to) + if from == @source_elements + @source_elements = to + end + end + def traverse(parent, &block) @source_elements.traverse(self, &block) yield self, parent end