uglifier 1.2.7 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of uglifier might be problematic. Click here for more details.
- data/Gemfile +1 -1
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/uglifier.rb +32 -5
- data/spec/uglifier_spec.rb +10 -0
- data/uglifier.gemspec +5 -5
- metadata +11 -5
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,7 @@ Available options and their defaults are
|
|
43
43
|
:ascii_only => false, # Encode non-ASCII characters as Unicode code points
|
44
44
|
:inline_script => false, # Escape </script
|
45
45
|
:quote_keys => false, # Quote keys in object literals
|
46
|
+
:define => {}, # Define values for symbol replacement
|
46
47
|
:beautify => false, # Ouput indented code
|
47
48
|
:beautify_options => {
|
48
49
|
:indent_level => 4,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/uglifier.rb
CHANGED
@@ -22,6 +22,7 @@ class Uglifier
|
|
22
22
|
:ascii_only => false, # Encode non-ASCII characters as Unicode code points
|
23
23
|
:inline_script => false, # Escape </script
|
24
24
|
:quote_keys => false, # Quote keys in object literals
|
25
|
+
:define => {}, # Define values for symbol replacement
|
25
26
|
:beautify => false, # Ouput indented code
|
26
27
|
:beautify_options => {
|
27
28
|
:indent_level => 4,
|
@@ -61,7 +62,7 @@ class Uglifier
|
|
61
62
|
|
62
63
|
js = []
|
63
64
|
js << "var result = '';"
|
64
|
-
js << "var source = #{
|
65
|
+
js << "var source = #{json_encode(source)};"
|
65
66
|
js << "var ast = UglifyJS.parser.parse(source);"
|
66
67
|
|
67
68
|
if @options[:lift_vars]
|
@@ -78,17 +79,17 @@ class Uglifier
|
|
78
79
|
JS
|
79
80
|
end
|
80
81
|
|
81
|
-
js << "ast = UglifyJS.uglify.ast_mangle(ast, #{
|
82
|
+
js << "ast = UglifyJS.uglify.ast_mangle(ast, #{json_encode(mangle_options)});"
|
82
83
|
|
83
84
|
if @options[:squeeze]
|
84
|
-
js << "ast = UglifyJS.uglify.ast_squeeze(ast, #{
|
85
|
+
js << "ast = UglifyJS.uglify.ast_squeeze(ast, #{json_encode(squeeze_options)});"
|
85
86
|
end
|
86
87
|
|
87
88
|
if @options[:unsafe]
|
88
89
|
js << "ast = UglifyJS.uglify.ast_squeeze_more(ast);"
|
89
90
|
end
|
90
91
|
|
91
|
-
js << "result += UglifyJS.uglify.gen_code(ast, #{
|
92
|
+
js << "result += UglifyJS.uglify.gen_code(ast, #{json_encode(gen_code_options)});"
|
92
93
|
|
93
94
|
if !@options[:beautify] && @options[:max_line_length]
|
94
95
|
js << "result = UglifyJS.uglify.split_lines(result, #{@options[:max_line_length].to_i})"
|
@@ -106,7 +107,7 @@ class Uglifier
|
|
106
107
|
{
|
107
108
|
"mangle" => @options[:mangle],
|
108
109
|
"toplevel" => @options[:toplevel],
|
109
|
-
"defines" =>
|
110
|
+
"defines" => defines,
|
110
111
|
"except" => @options[:except],
|
111
112
|
"no_functions" => @options[:mangle] == :vars
|
112
113
|
}
|
@@ -120,6 +121,21 @@ class Uglifier
|
|
120
121
|
}
|
121
122
|
end
|
122
123
|
|
124
|
+
def defines
|
125
|
+
Hash[(@options[:define] || {}).map do |k, v|
|
126
|
+
token = if v.is_a? Numeric
|
127
|
+
['num', v]
|
128
|
+
elsif [true, false].include?(v)
|
129
|
+
['name', v.to_s]
|
130
|
+
elsif v == nil
|
131
|
+
['name', 'null']
|
132
|
+
else
|
133
|
+
['string', v.to_s]
|
134
|
+
end
|
135
|
+
[k, token]
|
136
|
+
end]
|
137
|
+
end
|
138
|
+
|
123
139
|
def gen_code_options
|
124
140
|
options = {
|
125
141
|
:ascii_only => @options[:ascii_only],
|
@@ -133,4 +149,15 @@ class Uglifier
|
|
133
149
|
options
|
134
150
|
end
|
135
151
|
end
|
152
|
+
|
153
|
+
# MultiJson API detection
|
154
|
+
if MultiJson.respond_to? :dump
|
155
|
+
def json_encode(obj)
|
156
|
+
MultiJson.dump(obj)
|
157
|
+
end
|
158
|
+
else
|
159
|
+
def json_encode(obj)
|
160
|
+
MultiJson.encode(obj)
|
161
|
+
end
|
162
|
+
end
|
136
163
|
end
|
data/spec/uglifier_spec.rb
CHANGED
@@ -120,6 +120,16 @@ describe "Uglifier" do
|
|
120
120
|
Uglifier.compile(code, :quote_keys => true).should include('"foo"')
|
121
121
|
end
|
122
122
|
|
123
|
+
it "handles constant definitions" do
|
124
|
+
code = "if (BOOLEAN) { var a = STRING; var b = NULL; var c = NUMBER; }"
|
125
|
+
defines = {"NUMBER" => 1234, "BOOLEAN" => true, "NULL" => nil, "STRING" => "str"}
|
126
|
+
processed = Uglifier.compile(code, :define => defines)
|
127
|
+
processed.should include("a=\"str\"")
|
128
|
+
processed.should_not include("if")
|
129
|
+
processed.should include("b=null")
|
130
|
+
processed.should include("c=1234")
|
131
|
+
end
|
132
|
+
|
123
133
|
describe "Input Formats" do
|
124
134
|
let(:code) { "function hello() { return 'hello world'; }" }
|
125
135
|
|
data/uglifier.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "uglifier"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ville Lautanala"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-09-02"
|
13
13
|
s.email = "lautis@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -43,14 +43,14 @@ Gem::Specification.new do |s|
|
|
43
43
|
|
44
44
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
45
|
s.add_runtime_dependency(%q<execjs>, [">= 0.3.0"])
|
46
|
-
s.add_runtime_dependency(%q<multi_json>, ["~> 1.
|
46
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 1.0.2", "~> 1.0"])
|
47
47
|
s.add_development_dependency(%q<rspec>, ["~> 2.7"])
|
48
48
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
49
49
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
50
50
|
s.add_development_dependency(%q<rdoc>, ["~> 3.11"])
|
51
51
|
else
|
52
52
|
s.add_dependency(%q<execjs>, [">= 0.3.0"])
|
53
|
-
s.add_dependency(%q<multi_json>, ["~> 1.
|
53
|
+
s.add_dependency(%q<multi_json>, [">= 1.0.2", "~> 1.0"])
|
54
54
|
s.add_dependency(%q<rspec>, ["~> 2.7"])
|
55
55
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
56
56
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
@@ -58,7 +58,7 @@ Gem::Specification.new do |s|
|
|
58
58
|
end
|
59
59
|
else
|
60
60
|
s.add_dependency(%q<execjs>, [">= 0.3.0"])
|
61
|
-
s.add_dependency(%q<multi_json>, ["~> 1.
|
61
|
+
s.add_dependency(%q<multi_json>, [">= 1.0.2", "~> 1.0"])
|
62
62
|
s.add_dependency(%q<rspec>, ["~> 2.7"])
|
63
63
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
64
64
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uglifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
@@ -32,17 +32,23 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.2
|
35
38
|
- - ~>
|
36
39
|
- !ruby/object:Gem::Version
|
37
|
-
version: '1.
|
40
|
+
version: '1.0'
|
38
41
|
type: :runtime
|
39
42
|
prerelease: false
|
40
43
|
version_requirements: !ruby/object:Gem::Requirement
|
41
44
|
none: false
|
42
45
|
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.0.2
|
43
49
|
- - ~>
|
44
50
|
- !ruby/object:Gem::Version
|
45
|
-
version: '1.
|
51
|
+
version: '1.0'
|
46
52
|
- !ruby/object:Gem::Dependency
|
47
53
|
name: rspec
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
151
|
version: '0'
|
146
152
|
segments:
|
147
153
|
- 0
|
148
|
-
hash: -
|
154
|
+
hash: -550840341360460746
|
149
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
156
|
none: false
|
151
157
|
requirements:
|