uglifier 2.5.3 → 2.6.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abc5fa742a4bcf09fe7f93ab645ce6777708aab6
4
- data.tar.gz: 5332624660b317ffa1e1e40cc44a8fd44facd8a4
3
+ metadata.gz: 585ecdc74ace303e7a9ab552441517c2cd455bb7
4
+ data.tar.gz: b974ac6688e88acbf12928ce84e035f1edab1519
5
5
  SHA512:
6
- metadata.gz: 36a3cc5f14f7797f1ca838d8321abe1afd836fdab4a2780ebecbd670778f8e939ed32d7d5382e9df400934955f96aa10835209e6d39e81f91276686b87576774
7
- data.tar.gz: 2da7f0e4ca2e183e2b5f6b5cafc1c17d1f5633d7741fb8b21ef381ff3e9fd9d46e9a6105ea921126a1f0e41602326028b030fd4c5b465cacb59f611e3ac58a39
6
+ metadata.gz: f4ce4b2b9b9bacf055ae287c7c9b290ed9bf0a7cf405a829208e10906d10726ef11815366d2a3572e020d0dd65422605a98fcde2ef2c2c76790a13c9101bd285
7
+ data.tar.gz: d7c2783bfe8e21e0f11eda932a302f5c60ec8b3361b693ea7a81e1c610e5a5e01234d78c90614207852216dbdc679bac676ddf6e91a219eb1863ef2af5fe90f5
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.2
6
+ - 2.1.5
7
7
  - jruby
8
8
  #- rbx-2 # Fails on Travis
9
9
  git:
@@ -12,7 +12,7 @@ gemfile:
12
12
  - Gemfile
13
13
  matrix:
14
14
  include:
15
- - rvm: 2.1.2
15
+ - rvm: 2.1.5
16
16
  gemfile: gemfiles/rubyracer
17
17
  - rvm: 2.0.0
18
18
  gemfile: gemfiles/rubyracer
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.6.0 (8 December 2014)
2
+
3
+ - allow metadata to be appended to minified code
4
+
1
5
  ## 2.5.3 (18 July 2014)
2
6
 
3
7
  - no changes
data/Gemfile CHANGED
@@ -9,8 +9,7 @@ platforms :rbx do
9
9
  end
10
10
 
11
11
  if RUBY_VERSION >= '1.9'
12
- gem 'rubocop', '~> 0.24', :group => [:development]
12
+ gem 'rubocop', '~> 0.27', :group => [:development]
13
13
  else
14
14
  gem 'execjs', '~> 2.0.2'
15
15
  end
16
-
data/README.md CHANGED
@@ -95,7 +95,9 @@ Available options and their defaults are
95
95
  :source_root => nil, # The URL of the directory which contains :source_filename
96
96
  :output_filename => nil, # The filename or URL where the minified output can be found
97
97
  :input_source_map => nil, # The contents of the source map describing the input
98
- :screw_ie8 => false # Don't bother to generate safe code for IE8
98
+ :screw_ie8 => false, # Don't bother to generate safe code for IE8
99
+ :source_map_url => false, # Url for source mapping to be appended in minified source
100
+ :source_url => false # Url to original source to be appended in minified source
99
101
  }
100
102
  ```
101
103
 
data/lib/uglifier.rb CHANGED
@@ -6,7 +6,9 @@ require "uglifier/version"
6
6
 
7
7
  # A wrapper around the UglifyJS interface
8
8
  class Uglifier
9
+ # Error class for compilation errors.
9
10
  Error = ExecJS::Error
11
+ # JavaScript code to call UglifyJS
10
12
  JS = <<-JS
11
13
  function comments(option) {
12
14
  if (Object.prototype.toString.call(option) === '[object Array]') {
@@ -55,6 +57,15 @@ class Uglifier
55
57
  var stream = UglifyJS.OutputStream(gen_code_options);
56
58
 
57
59
  ast.print(stream);
60
+
61
+ if (options.source_map_options.map_url) {
62
+ stream += "\\n//# sourceMappingURL=" + options.source_map_options.map_url;
63
+ }
64
+
65
+ if (options.source_map_options.url) {
66
+ stream += "\\n//# sourceURL=" + options.source_map_options.url;
67
+ }
68
+
58
69
  if (options.generate_map) {
59
70
  return [stream.toString(), source_map.toString()];
60
71
  } else {
@@ -62,7 +73,7 @@ class Uglifier
62
73
  }
63
74
  JS
64
75
 
65
- # UglifyJS source patch
76
+ # UglifyJS source path
66
77
  SourcePath = File.expand_path("../uglify.js", __FILE__)
67
78
  # ES5 shims source path
68
79
  ES5FallbackPath = File.expand_path("../es5.js", __FILE__)
@@ -124,48 +135,45 @@ class Uglifier
124
135
  :source_root => nil, # The URL of the directory which contains :source_filename
125
136
  :output_filename => nil, # The filename or URL where the minified output can be found
126
137
  :input_source_map => nil, # The contents of the source map describing the input
127
- :screw_ie8 => false # Don't bother to generate safe code for IE8
138
+ :screw_ie8 => false, # Don't bother to generate safe code for IE8
139
+ :source_map_url => false, # Url for source mapping to be appended in minified source
140
+ :source_url => false # Url for original source to be appended in minified source
128
141
  }
129
142
  # rubocop:enable LineLength
130
143
 
131
144
  # Minifies JavaScript code using implicit context.
132
145
  #
133
- # source should be a String or IO object containing valid JavaScript.
134
- # options contain optional overrides to Uglifier::DEFAULTS
135
- #
136
- # Returns minified code as String
146
+ # @param source [IO, String] valid JS source code.
147
+ # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
148
+ # @return [String] minified code.
137
149
  def self.compile(source, options = {})
138
150
  new(options).compile(source)
139
151
  end
140
152
 
141
153
  # Minifies JavaScript code and generates a source map using implicit context.
142
154
  #
143
- # source should be a String or IO object containing valid JavaScript.
144
- # options contain optional overrides to Uglifier::DEFAULTS
145
- #
146
- # Returns a pair of [minified code as String, source map as a String]
155
+ # @param source [IO, String] valid JS source code.
156
+ # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
157
+ # @return [Array(String, String)] minified code and source map.
147
158
  def self.compile_with_map(source, options = {})
148
159
  new(options).compile_with_map(source)
149
160
  end
150
161
 
151
162
  # Initialize new context for Uglifier with given options
152
163
  #
153
- # options - Hash of options to override Uglifier::DEFAULTS
164
+ # @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
154
165
  def initialize(options = {})
155
166
  (options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
156
167
  raise ArgumentError, "Invalid option: #{missing}"
157
168
  end
158
169
  @options = options
159
- @context = ExecJS.compile(File.open(ES5FallbackPath, "r:UTF-8").read +
160
- File.open(SplitFallbackPath, "r:UTF-8").read +
161
- File.open(SourcePath, "r:UTF-8").read)
170
+ @context = ExecJS.compile(uglifyjs_source)
162
171
  end
163
172
 
164
173
  # Minifies JavaScript code
165
174
  #
166
- # source should be a String or IO object containing valid JavaScript.
167
- #
168
- # Returns minified code as String
175
+ # @param source [IO, String] valid JS source code.
176
+ # @return [String] minified code.
169
177
  def compile(source)
170
178
  run_uglifyjs(source, false)
171
179
  end
@@ -173,15 +181,20 @@ class Uglifier
173
181
 
174
182
  # Minifies JavaScript code and generates a source map
175
183
  #
176
- # source should be a String or IO object containing valid JavaScript.
177
- #
178
- # Returns a pair of [minified code as String, source map as a String]
184
+ # @param source [IO, String] valid JS source code.
185
+ # @return [Array(String, String)] minified code and source map.
179
186
  def compile_with_map(source)
180
187
  run_uglifyjs(source, true)
181
188
  end
182
189
 
183
190
  private
184
191
 
192
+ def uglifyjs_source
193
+ [ES5FallbackPath, SplitFallbackPath, SourcePath].map do |file|
194
+ File.open(file, "r:UTF-8") { |f| f.read }
195
+ end.join("\n")
196
+ end
197
+
185
198
  # Run UglifyJS for given source code
186
199
  def run_uglifyjs(source, generate_map)
187
200
  @context.exec(Uglifier::JS % json_encode(
@@ -263,7 +276,9 @@ class Uglifier
263
276
  {
264
277
  :file => @options[:output_filename],
265
278
  :root => @options[:source_root],
266
- :orig => @options[:input_source_map]
279
+ :orig => @options[:input_source_map],
280
+ :map_url => @options[:source_map_url],
281
+ :url => @options[:source_url]
267
282
  }
268
283
  end
269
284
 
@@ -1,3 +1,4 @@
1
1
  class Uglifier
2
- VERSION = "2.5.3"
2
+ # Current version of Uglifier.
3
+ VERSION = "2.6.0"
3
4
  end
@@ -3,16 +3,8 @@ require 'stringio'
3
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
4
 
5
5
  describe "Uglifier" do
6
- it "generates source maps" do
7
- source = File.open("lib/uglify.js", "r:UTF-8").read
8
- minified, map = Uglifier.new.compile_with_map(source)
9
- expect(minified.length).to be < source.length
10
- expect(map.length).to be > 0
11
- expect { JSON.parse(map) }.not_to raise_error
12
- end
13
-
14
- it "generates source maps with the correct meta-data" do
15
- source = <<-JS
6
+ let(:source) do
7
+ <<-JS
16
8
  function hello () {
17
9
  function world () {
18
10
  return 2;
@@ -21,7 +13,17 @@ describe "Uglifier" do
21
13
  return world() + world();
22
14
  };
23
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
24
25
 
26
+ it "generates source maps with the correct meta-data" do
25
27
  _, map = Uglifier.compile_with_map(source,
26
28
  :source_filename => "ahoy.js",
27
29
  :output_filename => "ahoy.min.js",
@@ -83,4 +85,26 @@ describe "Uglifier" do
83
85
  expect(map.mappings.first[:source_line]).to eq(1)
84
86
  expect(map.mappings.last[:source_line]).to eq(6)
85
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
86
110
  end
data/uglifier.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "execjs", ">= 0.3.0"
27
27
  spec.add_runtime_dependency "json", ">= 1.8.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
- spec.add_development_dependency "rake", "~> 10.3.0"
29
+ spec.add_development_dependency "rake", "~> 10.4"
30
30
  spec.add_development_dependency "bundler", "~> 1.3"
31
31
  spec.add_development_dependency "rdoc", ">= 3.11"
32
32
  spec.add_development_dependency "source_map", ">= 0"
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uglifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.8.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 10.3.0
61
+ version: '10.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 10.3.0
68
+ version: '10.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rdoc
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.11'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.11'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: source_map
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible
@@ -118,12 +118,12 @@ extra_rdoc_files:
118
118
  - LICENSE.txt
119
119
  - README.md
120
120
  files:
121
- - .document
122
- - .gitignore
123
- - .gitmodules
124
- - .rspec
125
- - .rubocop.yml
126
- - .travis.yml
121
+ - ".document"
122
+ - ".gitignore"
123
+ - ".gitmodules"
124
+ - ".rspec"
125
+ - ".rubocop.yml"
126
+ - ".travis.yml"
127
127
  - CHANGELOG.md
128
128
  - CONTRIBUTING.md
129
129
  - Gemfile
@@ -151,17 +151,17 @@ require_paths:
151
151
  - lib
152
152
  required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - '>='
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: 1.8.7
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - '>='
159
+ - - ">="
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.1.11
164
+ rubygems_version: 2.2.2
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Ruby wrapper for UglifyJS JavaScript compressor