uglifier 2.7.1 → 3.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.rubocop.yml +20 -3
- data/.travis.yml +10 -11
- data/.yardopts +4 -0
- data/CHANGELOG.md +102 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -5
- data/README.md +35 -12
- data/Rakefile +6 -30
- data/lib/es5.js +1 -1
- data/lib/source-map.js +3055 -0
- data/lib/uglifier/version.rb +1 -1
- data/lib/uglifier.js +120 -0
- data/lib/uglifier.rb +161 -99
- data/lib/uglify.js +55 -1803
- data/uglifier.gemspec +8 -8
- metadata +20 -48
- data/gemfiles/alaska +0 -4
- data/gemfiles/rubyracer +0 -4
- data/gemfiles/rubyrhino +0 -4
- data/spec/source_map_spec.rb +0 -110
- data/spec/spec_helper.rb +0 -23
- data/spec/uglifier_spec.rb +0 -271
data/uglifier.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = "Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible in Ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.required_ruby_version = '>= 1.
|
16
|
+
spec.required_ruby_version = '>= 1.9.3'
|
17
17
|
|
18
18
|
spec.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
@@ -21,15 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
"CHANGELOG.md",
|
22
22
|
"CONTRIBUTING.md"
|
23
23
|
]
|
24
|
-
|
25
|
-
spec.
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(spec|vendor|gemfiles|patches)/})
|
27
|
+
end
|
26
28
|
spec.require_paths = ["lib"]
|
27
29
|
|
28
|
-
spec.add_runtime_dependency "execjs", ">= 0.3.0"
|
29
|
-
spec.add_runtime_dependency "json", ">= 1.8.0"
|
30
|
+
spec.add_runtime_dependency "execjs", [">= 0.3.0", "< 3"]
|
30
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
32
33
|
spec.add_development_dependency "bundler", "~> 1.3"
|
33
|
-
spec.add_development_dependency "
|
34
|
-
spec.add_development_dependency "source_map", ">= 0"
|
34
|
+
spec.add_development_dependency "sourcemap", "~> 0.1.1"
|
35
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uglifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ville Lautanala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.3.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,20 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.3.0
|
27
|
-
-
|
28
|
-
name: json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
30
|
+
- - "<"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.8.0
|
32
|
+
version: '3'
|
41
33
|
- !ruby/object:Gem::Dependency
|
42
34
|
name: rspec
|
43
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +50,14 @@ dependencies:
|
|
58
50
|
requirements:
|
59
51
|
- - "~>"
|
60
52
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
53
|
+
version: '12.0'
|
62
54
|
type: :development
|
63
55
|
prerelease: false
|
64
56
|
version_requirements: !ruby/object:Gem::Requirement
|
65
57
|
requirements:
|
66
58
|
- - "~>"
|
67
59
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
60
|
+
version: '12.0'
|
69
61
|
- !ruby/object:Gem::Dependency
|
70
62
|
name: bundler
|
71
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,33 +73,19 @@ dependencies:
|
|
81
73
|
- !ruby/object:Gem::Version
|
82
74
|
version: '1.3'
|
83
75
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '3.11'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '3.11'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: source_map
|
76
|
+
name: sourcemap
|
99
77
|
requirement: !ruby/object:Gem::Requirement
|
100
78
|
requirements:
|
101
|
-
- - "
|
79
|
+
- - "~>"
|
102
80
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
81
|
+
version: 0.1.1
|
104
82
|
type: :development
|
105
83
|
prerelease: false
|
106
84
|
version_requirements: !ruby/object:Gem::Requirement
|
107
85
|
requirements:
|
108
|
-
- - "
|
86
|
+
- - "~>"
|
109
87
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
88
|
+
version: 0.1.1
|
111
89
|
description: Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible
|
112
90
|
in Ruby
|
113
91
|
email:
|
@@ -126,23 +104,20 @@ files:
|
|
126
104
|
- ".rspec"
|
127
105
|
- ".rubocop.yml"
|
128
106
|
- ".travis.yml"
|
107
|
+
- ".yardopts"
|
129
108
|
- CHANGELOG.md
|
130
109
|
- CONTRIBUTING.md
|
131
110
|
- Gemfile
|
132
111
|
- LICENSE.txt
|
133
112
|
- README.md
|
134
113
|
- Rakefile
|
135
|
-
- gemfiles/alaska
|
136
|
-
- gemfiles/rubyracer
|
137
|
-
- gemfiles/rubyrhino
|
138
114
|
- lib/es5.js
|
115
|
+
- lib/source-map.js
|
139
116
|
- lib/split.js
|
117
|
+
- lib/uglifier.js
|
140
118
|
- lib/uglifier.rb
|
141
119
|
- lib/uglifier/version.rb
|
142
120
|
- lib/uglify.js
|
143
|
-
- spec/source_map_spec.rb
|
144
|
-
- spec/spec_helper.rb
|
145
|
-
- spec/uglifier_spec.rb
|
146
121
|
- uglifier.gemspec
|
147
122
|
homepage: http://github.com/lautis/uglifier
|
148
123
|
licenses:
|
@@ -156,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
131
|
requirements:
|
157
132
|
- - ">="
|
158
133
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
134
|
+
version: 1.9.3
|
160
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
136
|
requirements:
|
162
137
|
- - ">="
|
@@ -164,11 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
139
|
version: '0'
|
165
140
|
requirements: []
|
166
141
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.6.8
|
168
143
|
signing_key:
|
169
144
|
specification_version: 4
|
170
145
|
summary: Ruby wrapper for UglifyJS JavaScript compressor
|
171
|
-
test_files:
|
172
|
-
- spec/source_map_spec.rb
|
173
|
-
- spec/spec_helper.rb
|
174
|
-
- spec/uglifier_spec.rb
|
146
|
+
test_files: []
|
data/gemfiles/alaska
DELETED
data/gemfiles/rubyracer
DELETED
data/gemfiles/rubyrhino
DELETED
data/spec/source_map_spec.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'stringio'
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
-
|
5
|
-
describe "Uglifier" do
|
6
|
-
let(:source) do
|
7
|
-
<<-JS
|
8
|
-
function hello () {
|
9
|
-
function world () {
|
10
|
-
return 2;
|
11
|
-
};
|
12
|
-
|
13
|
-
return world() + world();
|
14
|
-
};
|
15
|
-
JS
|
16
|
-
end
|
17
|
-
|
18
|
-
it "generates source maps" do
|
19
|
-
source = File.open("lib/uglify.js", "r:UTF-8").read
|
20
|
-
minified, map = Uglifier.new.compile_with_map(source)
|
21
|
-
expect(minified.length).to be < source.length
|
22
|
-
expect(map.length).to be > 0
|
23
|
-
expect { JSON.parse(map) }.not_to raise_error
|
24
|
-
end
|
25
|
-
|
26
|
-
it "generates source maps with the correct meta-data" do
|
27
|
-
_, map = Uglifier.compile_with_map(source,
|
28
|
-
:source_filename => "ahoy.js",
|
29
|
-
:output_filename => "ahoy.min.js",
|
30
|
-
:source_root => "http://localhost/")
|
31
|
-
|
32
|
-
map = SourceMap.from_s(map)
|
33
|
-
expect(map.file).to eq("ahoy.min.js")
|
34
|
-
expect(map.sources).to eq(["ahoy.js"])
|
35
|
-
expect(map.names).to eq(%w(hello world))
|
36
|
-
expect(map.source_root).to eq("http://localhost/")
|
37
|
-
expect(map.mappings.first[:generated_line]).to eq(1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should skip copyright lines in source maps" do
|
41
|
-
source = <<-JS
|
42
|
-
/* @copyright Conrad Irwin */
|
43
|
-
function hello () {
|
44
|
-
function world () {
|
45
|
-
return 2;
|
46
|
-
};
|
47
|
-
|
48
|
-
return world() + world();
|
49
|
-
};
|
50
|
-
JS
|
51
|
-
|
52
|
-
_, map = Uglifier.compile_with_map(source,
|
53
|
-
:source_filename => "ahoy.js",
|
54
|
-
:source_root => "http://localhost/")
|
55
|
-
map = SourceMap.from_s(map)
|
56
|
-
expect(map.mappings.first[:generated_line]).to eq(2)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be able to handle an input source map" do
|
60
|
-
source = <<-JS
|
61
|
-
function hello () {
|
62
|
-
function world () {
|
63
|
-
return 2;
|
64
|
-
};
|
65
|
-
|
66
|
-
return world() + world();
|
67
|
-
};
|
68
|
-
JS
|
69
|
-
|
70
|
-
minified1, map1 = Uglifier.compile_with_map(
|
71
|
-
source,
|
72
|
-
:source_filename => "ahoy.js",
|
73
|
-
:source_root => "http://localhost/",
|
74
|
-
:mangle => false
|
75
|
-
)
|
76
|
-
|
77
|
-
_, map2 = Uglifier.compile_with_map(source,
|
78
|
-
:input_source_map => map1,
|
79
|
-
:mangle => true)
|
80
|
-
|
81
|
-
expect(minified1.lines.to_a.length).to eq(1)
|
82
|
-
|
83
|
-
map = SourceMap.from_s(map2)
|
84
|
-
expect(map.sources).to eq(["http://localhost/ahoy.js"])
|
85
|
-
expect(map.mappings.first[:source_line]).to eq(1)
|
86
|
-
expect(map.mappings.last[:source_line]).to eq(6)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "appens source map url" do
|
90
|
-
minified, _ = Uglifier.compile_with_map(
|
91
|
-
source,
|
92
|
-
:source_filename => "ahoy.js",
|
93
|
-
:output_filename => "ahoy.min.js",
|
94
|
-
:source_root => "http://localhost/",
|
95
|
-
:source_map_url => "http://example.com/map"
|
96
|
-
)
|
97
|
-
expect(minified).to include("\n//# sourceMappingURL=http://example.com/map")
|
98
|
-
end
|
99
|
-
|
100
|
-
it "appens source url" do
|
101
|
-
minified, _ = Uglifier.compile_with_map(
|
102
|
-
source,
|
103
|
-
:source_filename => "ahoy.js",
|
104
|
-
:output_filename => "ahoy.min.js",
|
105
|
-
:source_root => "http://localhost/",
|
106
|
-
:source_url => "http://example.com/source"
|
107
|
-
)
|
108
|
-
expect(minified).to include("\n//# sourceURL=http://example.com/source")
|
109
|
-
end
|
110
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'uglifier'
|
3
|
-
require 'rspec'
|
4
|
-
require 'source_map'
|
5
|
-
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
9
|
-
|
10
|
-
if ENV["ALASKA"]
|
11
|
-
require 'alaska'
|
12
|
-
require 'tempfile'
|
13
|
-
ExecJS.runtime = Alaska::Runtime.new
|
14
|
-
end
|
15
|
-
|
16
|
-
RSpec.configure do |config|
|
17
|
-
config.mock_with :rspec do |mock|
|
18
|
-
mock.syntax = :expect
|
19
|
-
end
|
20
|
-
config.expect_with :rspec do |expect|
|
21
|
-
expect.syntax = :expect
|
22
|
-
end
|
23
|
-
end
|
data/spec/uglifier_spec.rb
DELETED
@@ -1,271 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'stringio'
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
-
|
5
|
-
describe "Uglifier" do
|
6
|
-
it "minifies JS" do
|
7
|
-
source = File.open("lib/uglify.js", "r:UTF-8").read
|
8
|
-
minified = Uglifier.new.compile(source)
|
9
|
-
expect(minified.length).to be < source.length
|
10
|
-
expect { Uglifier.new.compile(minified) }.not_to raise_error
|
11
|
-
end
|
12
|
-
|
13
|
-
it "throws an exception when compilation fails" do
|
14
|
-
expect { Uglifier.new.compile(")(") }.to raise_error(Uglifier::Error)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "throws an exception on invalid option" do
|
18
|
-
expect { Uglifier.new(:foo => true) }.to raise_error(ArgumentError)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "doesn't omit null character in strings" do
|
22
|
-
expect(Uglifier.new.compile('var foo="\0bar"')).to include("\\x00bar")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "adds trailing semicolon to minified source" do
|
26
|
-
source = "(function id(i) {return i;}());"
|
27
|
-
expect(Uglifier.new.compile(source)[-1]).to eql(";"[0])
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "argument name mangling" do
|
31
|
-
it "doesn't try to mangle $super by default to avoid breaking PrototypeJS" do
|
32
|
-
expect(Uglifier.compile('function foo($super) {return $super}')).to include("$super")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "allows variables to be excluded from mangling" do
|
36
|
-
code = "function bar(foo) {return foo + 'bar'};"
|
37
|
-
expect(Uglifier.compile(code, :mangle => { :except => ["foo"] })).to include("(foo)")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "skips mangling when set to false" do
|
41
|
-
code = "function bar(foo) {return foo + 'bar'};"
|
42
|
-
expect(Uglifier.compile(code, :mangle => false)).to include("(foo)")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "mangles argumen names by default" do
|
46
|
-
code = "function bar(foo) {return foo + 'bar'};"
|
47
|
-
expect(Uglifier.compile(code, :mangle => true)).not_to include("(foo)")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "mangles top-level names when explicitly instructed" do
|
51
|
-
code = "function bar(foo) {return foo + 'bar'};"
|
52
|
-
expect(Uglifier.compile(code, :mangle => { :toplevel => false })).to include("bar(")
|
53
|
-
expect(Uglifier.compile(code, :mangle => { :toplevel => true })).not_to include("bar(")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "comment preservation" do
|
58
|
-
let(:source) do
|
59
|
-
<<-EOS
|
60
|
-
/* @preserve Copyright Notice */
|
61
|
-
/* (c) 2011 */
|
62
|
-
// INCLUDED
|
63
|
-
//! BANG
|
64
|
-
function identity(p) { return p; }
|
65
|
-
/* Another Copyright */
|
66
|
-
/*! Another Bang */
|
67
|
-
// A comment!
|
68
|
-
function add(a, b) { return a + b; }
|
69
|
-
EOS
|
70
|
-
end
|
71
|
-
|
72
|
-
it "handles copyright option" do
|
73
|
-
compiled = Uglifier.compile(source, :copyright => false)
|
74
|
-
expect(compiled).not_to match(/Copyright/)
|
75
|
-
end
|
76
|
-
|
77
|
-
describe ":copyright" do
|
78
|
-
subject { Uglifier.compile(source, :comments => :copyright) }
|
79
|
-
|
80
|
-
it "preserves comments with string Copyright" do
|
81
|
-
expect(subject).to match(/Copyright Notice/)
|
82
|
-
expect(subject).to match(/Another Copyright/)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "preserves comments that start with a bang (!)" do
|
86
|
-
expect(subject).to match(/! BANG/)
|
87
|
-
expect(subject).to match(/! Another Bang/)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "ignores other comments" do
|
91
|
-
expect(subject).not_to match(/INCLUDED/)
|
92
|
-
expect(subject).not_to match(/A comment!/)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe ":jsdoc" do
|
97
|
-
subject { Uglifier.compile(source, :output => { :comments => :jsdoc }) }
|
98
|
-
|
99
|
-
it "preserves jsdoc license/preserve blocks" do
|
100
|
-
expect(subject).to match(/Copyright Notice/)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "ignores other comments" do
|
104
|
-
expect(subject).not_to match(/Another Copyright/)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe ":all" do
|
109
|
-
subject { Uglifier.compile(source, :comments => :all) }
|
110
|
-
|
111
|
-
it "preserves all comments" do
|
112
|
-
expect(subject).to match(/INCLUDED/)
|
113
|
-
expect(subject).to match(/2011/)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe ":none" do
|
118
|
-
subject { Uglifier.compile(source, :comments => :none) }
|
119
|
-
|
120
|
-
it "omits all comments" do
|
121
|
-
expect(subject).not_to match %r{//}
|
122
|
-
expect(subject).not_to match(/\/\*/)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "regular expression" do
|
127
|
-
subject { Uglifier.compile(source, :comments => /included/i) }
|
128
|
-
|
129
|
-
it "matches comment blocks with regex" do
|
130
|
-
expect(subject).to match(/INCLUDED/)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "omits other blocks" do
|
134
|
-
expect(subject).not_to match(/2011/)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it "squeezes code only if squeeze is set to true" do
|
140
|
-
code = "function a(a){if(a) { return 0; } else { return 1; }}"
|
141
|
-
minified = Uglifier.compile(code, :squeeze => false)
|
142
|
-
squeezed = Uglifier.compile(code, :squeeze => true)
|
143
|
-
expect(minified.length).to be > squeezed.length
|
144
|
-
end
|
145
|
-
|
146
|
-
it "honors max line length" do
|
147
|
-
code = "var foo = 123;function bar() { return foo; }"
|
148
|
-
uglifier = Uglifier.new(:output => { :max_line_len => 16 }, :compress => false)
|
149
|
-
expect(uglifier.compile(code).split("\n").length).to eq(2)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "hoists vars to top of the scope" do
|
153
|
-
code = "function something() { var a = 1; a = 2; var b = 3; return a + b;}"
|
154
|
-
minified = Uglifier.compile(code, :compress => { :hoist_vars => true })
|
155
|
-
expect(minified).to match(/var \w,\w/)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "forwards screw_ie8 option to UglifyJS" do
|
159
|
-
code = "function something() { return g['switch']; }"
|
160
|
-
expect(Uglifier.compile(code, :mangle => false, :screw_ie8 => true)).to match(/g\.switch/)
|
161
|
-
expect(Uglifier.compile(code, :compress => false, :screw_ie8 => true)).to match(/g\.switch/)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "can be configured to output only ASCII" do
|
165
|
-
code = "function emoji() { return '\\ud83c\\ude01'; }"
|
166
|
-
minified = Uglifier.compile(code, :output => { :ascii_only => true })
|
167
|
-
expect(minified).to include("\\ud83c\\ude01")
|
168
|
-
end
|
169
|
-
|
170
|
-
it "escapes </script when asked to" do
|
171
|
-
code = "function test() { return '</script>';}"
|
172
|
-
minified = Uglifier.compile(code, :output => { :inline_script => true })
|
173
|
-
expect(minified).not_to include("</script>")
|
174
|
-
end
|
175
|
-
|
176
|
-
it "quotes keys" do
|
177
|
-
code = "var a = {foo: 1}"
|
178
|
-
minified = Uglifier.compile(code, :output => { :quote_keys => true })
|
179
|
-
expect(minified).to include('"foo"')
|
180
|
-
end
|
181
|
-
|
182
|
-
it "quotes unsafe keys by default" do
|
183
|
-
code = 'var code = {"class": "", "\u200c":"A"}'
|
184
|
-
expect(Uglifier.compile(code)).to include('"class"')
|
185
|
-
expect(Uglifier.compile(code)).to include('"\u200c"')
|
186
|
-
|
187
|
-
uglifier = Uglifier.new(:output => { :ascii_only => false, :quote_keys => false })
|
188
|
-
expect(uglifier.compile(code)).to include(["200c".to_i(16)].pack("U*"))
|
189
|
-
end
|
190
|
-
|
191
|
-
it "handles constant definitions" do
|
192
|
-
code = "if (BOOL) { var a = STR; var b = NULL; var c = NUM; }"
|
193
|
-
defines = { "NUM" => 1234, "BOOL" => true, "NULL" => nil, "STR" => "str" }
|
194
|
-
processed = Uglifier.compile(code, :define => defines)
|
195
|
-
expect(processed).to include("a=\"str\"")
|
196
|
-
expect(processed).not_to include("if")
|
197
|
-
expect(processed).to include("b=null")
|
198
|
-
expect(processed).to include("c=1234")
|
199
|
-
end
|
200
|
-
|
201
|
-
it "can disable IIFE negation" do
|
202
|
-
code = "(function() { console.log('test')})();"
|
203
|
-
disabled_negation = Uglifier.compile(code, :compress => { :negate_iife => false })
|
204
|
-
expect(disabled_negation).not_to include("!")
|
205
|
-
negation = Uglifier.compile(code, :compress => { :negate_iife => true })
|
206
|
-
expect(negation).to include("!")
|
207
|
-
end
|
208
|
-
|
209
|
-
it "can drop console logging" do
|
210
|
-
code = "(function() { console.log('test')})();"
|
211
|
-
compiled = Uglifier.compile(code, :compress => { :drop_console => true })
|
212
|
-
expect(compiled).not_to include("console")
|
213
|
-
end
|
214
|
-
|
215
|
-
it "processes @ngInject annotations" do
|
216
|
-
code = <<-EOF
|
217
|
-
/**
|
218
|
-
* @ngInject
|
219
|
-
*/
|
220
|
-
var f = function(foo, bar) { return foo + bar};
|
221
|
-
EOF
|
222
|
-
with_angular = Uglifier.compile(code, :compress => { :angular => true })
|
223
|
-
without_angular = Uglifier.compile(code, :compress => { :angular => false })
|
224
|
-
expect(with_angular).to include("f.$inject")
|
225
|
-
expect(without_angular).not_to include("f.$inject")
|
226
|
-
end
|
227
|
-
|
228
|
-
it "keeps unused function arguments when keep_fargs option is set" do
|
229
|
-
code = <<-EOF
|
230
|
-
function plus(a, b, c) { return a + b};
|
231
|
-
plus(1, 2);
|
232
|
-
EOF
|
233
|
-
expect(Uglifier.compile(code, :mangle => false)).not_to include("c)")
|
234
|
-
|
235
|
-
keep_fargs = Uglifier.compile(code, :mangle => false, :compress => { :keep_fargs => true })
|
236
|
-
expect(keep_fargs).to include("c)")
|
237
|
-
end
|
238
|
-
|
239
|
-
describe "Input Formats" do
|
240
|
-
let(:code) { "function hello() { return 'hello world'; }" }
|
241
|
-
|
242
|
-
it "handles strings" do
|
243
|
-
expect(Uglifier.new.compile(code)).not_to be_empty
|
244
|
-
end
|
245
|
-
|
246
|
-
it "handles IO objects" do
|
247
|
-
expect(Uglifier.new.compile(StringIO.new(code))).not_to be_empty
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "enclose" do
|
252
|
-
let(:code) { "$.foo()" }
|
253
|
-
|
254
|
-
it "encloses code with given arguments" do
|
255
|
-
minified = Uglifier.compile(code, :enclose => { 'window.jQuery' => '$' })
|
256
|
-
expect(minified).to match(/window.jQuery/)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "handles multiple definitions" do
|
260
|
-
definitions = [%w(lol lulz), %w(foo bar)]
|
261
|
-
minified = Uglifier.compile(code, :enclose => definitions)
|
262
|
-
expect(minified).to match(/lol,foo/)
|
263
|
-
expect(minified).to match(/lulz,bar/)
|
264
|
-
end
|
265
|
-
|
266
|
-
it "wraps with function when given empty object" do
|
267
|
-
minified = Uglifier.compile(code, :enclose => {})
|
268
|
-
expect(minified).to match(/function\(/)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|