lib/minjs/compressor.rb in minjs-0.2.2 vs lib/minjs/compressor.rb in minjs-0.3.0
- old
+ new
@@ -1,21 +1,19 @@
#!/usr/bin/env ruby
# coding: utf-8
require 'minjs/lex'
require 'minjs/ecma262'
-require 'minjs/literal'
require 'minjs/statement'
require 'minjs/expression'
require 'minjs/func'
require 'minjs/program'
require 'minjs/exceptions'
require 'minjs/version'
require 'logger'
module Minjs
class Compressor
- include Literal
include Statement
include Exp
include Func
include Program
include Ctype
@@ -93,19 +91,22 @@
def parse(data)
@lex = Minjs::Lex.new(data, :logger => @logger)
@global_context = ECMA262::Context.new
@heading_comments = []
- @lex.eval_lit{
- while a = @lex.ws_lit
- @heading_comments.push(a)
- end
- nil
- }
- @prog = source_elements(@lex, @global_context)
+ while a = (@lex.comment || @lex.line_terminator || @lex.white_space)
+ @heading_comments.push(a)
+ end
+ while @heading_comments.last == ECMA262::LIT_LINE_FEED and
+ !(@heading_comments[-2].kind_of?(ECMA262::SingleLineComment))
+ @heading_comments.pop
+ end
+ @prog = program(@lex, @global_context)
+
remove_empty_statement
+ @lex.clear_cache
self
end
def next_sym(s)
def c2i(c)
@@ -634,22 +635,24 @@
#}
#console.log(eee); //=>global
#test();
#
catch_scopes.each{|st, parent|
- catch_context = ECMA262::Context.new
- catch_context.lex_env = st.context.lex_env.new_declarative_env()
- catch_context.var_env = st.context.var_env
- catch_context.lex_env.record.create_mutable_binding(st.catch[0], nil)
- catch_context.lex_env.record.set_mutable_binding(st.catch[0], :undefined, nil)
- st.catch[0].context = catch_context
+ if st.catch
+ catch_context = ECMA262::Context.new
+ catch_context.lex_env = st.context.lex_env.new_declarative_env()
+ catch_context.var_env = st.context.var_env
+ catch_context.lex_env.record.create_mutable_binding(st.catch[0], nil)
+ catch_context.lex_env.record.set_mutable_binding(st.catch[0], :undefined, nil)
+ st.catch[0].context = catch_context
- st.catch[1].traverse(parent){|st2|
- if st2.kind_of? ECMA262::IdentifierName and st2 == st.catch[0] and st2.binding_env == st.catch[0].binding_env
- st2.context = catch_context
- end
- }
- func_scopes.unshift([st, parent])
+ st.catch[1].traverse(parent){|st2|
+ if st2.kind_of? ECMA262::IdentifierName and st2 == st.catch[0] and st2.binding_env == st.catch[0].binding_env
+ st2.context = catch_context
+ end
+ }
+ func_scopes.unshift([st, parent])
+ end
}
# with_scopes.each{|st, parent|
# with_context = ECMA262::Context.new
# with_context.lex_env = st.context.lex_env.new_declarative_env()
# with_context.var_env = st.context.var_env