uglifier 4.1.20 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +14 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +10 -9
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/lib/uglifier.rb +69 -12
- data/lib/uglifier/version.rb +1 -1
- data/uglifier.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eb829d19c603a2d3760e02f0235d9d654f640111734caa9317449378e40fa26
|
4
|
+
data.tar.gz: '0774580cb6353b90d72e5febfdc6777bc05c6d6d773b09e4aab3b82178fe8acd'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f5c10b9dd4b9c84a6fe850dfb45b30bb25e0d9b04fa089ff745683028d1733e6b0b1c92846788af96197ee8774d8a7d105b424bc88f38b0c5abab5971bded0
|
7
|
+
data.tar.gz: 3120b0abc086792140a2cdb3a8ecae725327c8c8ea7b55c49d98be196e97de526087583c5bb2b6a0c169e86277474e8ae8a82d6a02cc23cd58cf0276defff03a
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -6,28 +6,29 @@ rvm:
|
|
6
6
|
- 2.0.0
|
7
7
|
- 2.1.10
|
8
8
|
- 2.2.10
|
9
|
-
- 2.3.
|
10
|
-
- 2.4.
|
11
|
-
- 2.5.
|
9
|
+
- 2.3.8
|
10
|
+
- 2.4.5
|
11
|
+
- 2.5.3
|
12
|
+
- 2.6.0
|
12
13
|
- ruby-head
|
13
|
-
- jruby-9.2.
|
14
|
+
- jruby-9.2.5.0
|
14
15
|
before_install:
|
15
|
-
- gem install bundler -v 1.
|
16
|
+
- gem install bundler -v 1.17.3
|
16
17
|
git:
|
17
18
|
submodules: false
|
18
19
|
gemfile:
|
19
20
|
- Gemfile
|
20
21
|
matrix:
|
21
22
|
include:
|
22
|
-
- rvm: 2.5.
|
23
|
+
- rvm: 2.5.3
|
23
24
|
gemfile: gemfiles/rubyracer
|
24
|
-
- rvm: jruby-9.2.
|
25
|
+
- rvm: jruby-9.2.5.0
|
25
26
|
gemfile: gemfiles/rubyrhino
|
26
|
-
- rvm: 2.5.
|
27
|
+
- rvm: 2.5.3
|
27
28
|
gemfile: gemfiles/alaska
|
28
29
|
env: ALASKA=1
|
29
30
|
allow_failures:
|
30
|
-
- rvm: 2.5.
|
31
|
+
- rvm: 2.5.3
|
31
32
|
gemfile: gemfiles/alaska
|
32
33
|
env: ALASKA=1
|
33
34
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -168,6 +168,7 @@ Available options and their defaults are
|
|
168
168
|
:output_filename => nil, # The filename or URL where the minified output can be found
|
169
169
|
:input_source_map => nil # The contents of the source map describing the input
|
170
170
|
},
|
171
|
+
:error_context_lines => 8, # How many context lines surrounding the error line. Env var ERROR_CONTEXT_LINES overrides this option
|
171
172
|
:harmony => false # Enable ES6/Harmony mode (experimental). Disabling mangling and compressing is recommended with Harmony mode.
|
172
173
|
}
|
173
174
|
```
|
data/lib/uglifier.rb
CHANGED
@@ -98,6 +98,7 @@ class Uglifier
|
|
98
98
|
:toplevel => false,
|
99
99
|
:ie8 => true, # Generate safe code for IE8
|
100
100
|
:source_map => false, # Generate source map
|
101
|
+
:error_context_lines => 8, # How many lines surrounding the error line
|
101
102
|
:harmony => false # Enable ES6/Harmony mode (experimental). Disabling mangling and compressing is recommended with Harmony mode.
|
102
103
|
}
|
103
104
|
|
@@ -149,9 +150,6 @@ class Uglifier
|
|
149
150
|
raise ArgumentError, "Invalid option: #{missing}"
|
150
151
|
end
|
151
152
|
@options = options
|
152
|
-
|
153
|
-
source = harmony? ? source_with(HarmonySourcePath) : source_with(SourcePath)
|
154
|
-
@context = ExecJS.compile(source)
|
155
153
|
end
|
156
154
|
|
157
155
|
# Minifies JavaScript code
|
@@ -180,6 +178,13 @@ class Uglifier
|
|
180
178
|
|
181
179
|
private
|
182
180
|
|
181
|
+
def context
|
182
|
+
@context ||= begin
|
183
|
+
source = harmony? ? source_with(HarmonySourcePath) : source_with(SourcePath)
|
184
|
+
ExecJS.compile(source)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
183
188
|
def source_map_comments
|
184
189
|
return '' unless @options[:source_map].respond_to?(:[])
|
185
190
|
|
@@ -213,25 +218,77 @@ class Uglifier
|
|
213
218
|
:ie8 => ie8?
|
214
219
|
}
|
215
220
|
|
216
|
-
parse_result(
|
221
|
+
parse_result(context.call("uglifier", options), generate_map, options)
|
217
222
|
end
|
218
223
|
|
219
224
|
def harmony?
|
220
225
|
@options[:harmony]
|
221
226
|
end
|
222
227
|
|
223
|
-
def
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
+
def harmony_error_message(message)
|
229
|
+
if message.start_with?("Unexpected token")
|
230
|
+
". To use ES6 syntax, harmony mode must be enabled with " \
|
231
|
+
"Uglifier.new(:harmony => true)."
|
232
|
+
else
|
233
|
+
""
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def error_context_lines
|
238
|
+
@options.fetch(:error_context_lines, DEFAULTS[:error_context_lines]).to_i
|
239
|
+
end
|
240
|
+
|
241
|
+
def error_context_format_options(low, high, line_index, column)
|
242
|
+
line_width = high.to_s.size
|
243
|
+
{
|
244
|
+
:line_index => line_index,
|
245
|
+
:base_index => low,
|
246
|
+
:line_width => line_width,
|
247
|
+
:line_format => "\e[36m%#{line_width + 1}d\e[0m ", # cyan
|
248
|
+
:col => column
|
249
|
+
}
|
250
|
+
end
|
251
|
+
|
252
|
+
def format_error_line(line, options)
|
253
|
+
# light red
|
254
|
+
indicator = ' => '.rjust(options[:line_width] + 2)
|
255
|
+
colored_line = "#{line[0...options[:col]]}\e[91m#{line[options[:col]..-1]}"
|
256
|
+
"\e[91m#{indicator}\e[0m#{colored_line}\e[0m"
|
257
|
+
end
|
258
|
+
|
259
|
+
def format_lines(lines, options)
|
260
|
+
lines.map.with_index do |line, index|
|
261
|
+
if options[:base_index] + index == options[:line_index]
|
262
|
+
format_error_line(line, options)
|
228
263
|
else
|
229
|
-
""
|
264
|
+
"#{options[:line_format] % (options[:base_index] + index + 1)}#{line}"
|
230
265
|
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def context_lines_message(source, line_number, column)
|
270
|
+
return if line_number.nil?
|
271
|
+
|
272
|
+
line_index = line_number - 1
|
273
|
+
lines = source.split("\n")
|
274
|
+
|
275
|
+
first_line = [line_index - error_context_lines, 0].max
|
276
|
+
last_line = [line_number + error_context_lines, lines.size].min
|
277
|
+
options = error_context_format_options(first_line, last_line, line_index, column)
|
278
|
+
context_lines = lines[first_line...last_line]
|
279
|
+
|
280
|
+
"--\n#{format_lines(context_lines, options).join("\n")}\n=="
|
281
|
+
end
|
282
|
+
|
283
|
+
def error_message(result, options)
|
284
|
+
err = result['error']
|
285
|
+
harmony_msg = harmony? ? '' : harmony_error_message(err['message'].to_s)
|
286
|
+
src_ctx = context_lines_message(options[:source], err['line'], err['col'])
|
287
|
+
"#{err['message']}#{harmony_msg}\n#{src_ctx}"
|
231
288
|
end
|
232
289
|
|
233
|
-
def parse_result(result, generate_map)
|
234
|
-
raise Error, error_message(result) if result.has_key?('error')
|
290
|
+
def parse_result(result, generate_map, options)
|
291
|
+
raise Error, error_message(result, options) if result.has_key?('error')
|
235
292
|
|
236
293
|
if generate_map
|
237
294
|
[result['code'] + source_map_comments, result['map']]
|
data/lib/uglifier/version.rb
CHANGED
data/uglifier.gemspec
CHANGED
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_runtime_dependency "execjs", [">= 0.3.0", "< 3"]
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
spec.add_development_dependency "rake", "~> 12.0"
|
33
|
-
spec.add_development_dependency "bundler", "
|
33
|
+
spec.add_development_dependency "bundler", ">= 1.3"
|
34
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.
|
4
|
+
version: 4.2.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:
|
11
|
+
date: 2019-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -62,14 +62,14 @@ dependencies:
|
|
62
62
|
name: bundler
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '1.3'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.3'
|
75
75
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,7 @@ extra_rdoc_files:
|
|
99
99
|
- CONTRIBUTING.md
|
100
100
|
files:
|
101
101
|
- ".document"
|
102
|
+
- ".github/workflows/ruby.yml"
|
102
103
|
- ".gitignore"
|
103
104
|
- ".gitmodules"
|
104
105
|
- ".rspec"
|
@@ -139,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
140
|
- !ruby/object:Gem::Version
|
140
141
|
version: '0'
|
141
142
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.7.6
|
143
|
+
rubygems_version: 3.0.3
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Ruby wrapper for UglifyJS JavaScript compressor
|