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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e80ba00a3806f9848b926823cd7cee1d7f6fd72a050c8b17f5dd084f45a1ed39
4
- data.tar.gz: 32f396008cd005a2725b698b55a9167872c13b5334e637801ca725ba7049fcc5
3
+ metadata.gz: 6eb829d19c603a2d3760e02f0235d9d654f640111734caa9317449378e40fa26
4
+ data.tar.gz: '0774580cb6353b90d72e5febfdc6777bc05c6d6d773b09e4aab3b82178fe8acd'
5
5
  SHA512:
6
- metadata.gz: 464ea32ccd16245306fcc71c575580890d0590dd61e913b1c8b10496dd80c1f6d44d1f3716a06fa4a9d145bca75243e880f466b63e9f07719c02962b8667f9c4
7
- data.tar.gz: 3b5a4997bcf52bc6fa0670fab41a187eeff8e716a579309a2949b1b2677334e4298cb6358e8359c3597f34126a3c13b2e1929cf40db99d798cfc5c0357af6522
6
+ metadata.gz: 81f5c10b9dd4b9c84a6fe850dfb45b30bb25e0d9b04fa089ff745683028d1733e6b0b1c92846788af96197ee8774d8a7d105b424bc88f38b0c5abab5971bded0
7
+ data.tar.gz: 3120b0abc086792140a2cdb3a8ecae725327c8c8ea7b55c49d98be196e97de526087583c5bb2b6a0c169e86277474e8ae8a82d6a02cc23cd58cf0276defff03a
@@ -0,0 +1,14 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v1
11
+ - uses: lautis/rubocop-action@master
12
+ name: Lint
13
+ env:
14
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -6,6 +6,9 @@ AllCops:
6
6
  - "vendor/**/*"
7
7
  - "gemfiles/vendor/**/*"
8
8
 
9
+ Metrics/AbcSize:
10
+ Max: 20
11
+
9
12
  Metrics/BlockLength:
10
13
  Enabled: true
11
14
  Exclude:
@@ -6,28 +6,29 @@ rvm:
6
6
  - 2.0.0
7
7
  - 2.1.10
8
8
  - 2.2.10
9
- - 2.3.7
10
- - 2.4.4
11
- - 2.5.1
9
+ - 2.3.8
10
+ - 2.4.5
11
+ - 2.5.3
12
+ - 2.6.0
12
13
  - ruby-head
13
- - jruby-9.2.0.0
14
+ - jruby-9.2.5.0
14
15
  before_install:
15
- - gem install bundler -v 1.16.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.1
23
+ - rvm: 2.5.3
23
24
  gemfile: gemfiles/rubyracer
24
- - rvm: jruby-9.2.0.0
25
+ - rvm: jruby-9.2.5.0
25
26
  gemfile: gemfiles/rubyrhino
26
- - rvm: 2.5.1
27
+ - rvm: 2.5.3
27
28
  gemfile: gemfiles/alaska
28
29
  env: ALASKA=1
29
30
  allow_failures:
30
- - rvm: 2.5.1
31
+ - rvm: 2.5.3
31
32
  gemfile: gemfiles/alaska
32
33
  env: ALASKA=1
33
34
  - rvm: ruby-head
@@ -1,3 +1,8 @@
1
+ ## 4.2.0 (25 September 2019)
2
+
3
+ - show code context for error messages (#167)
4
+ - defer initialisation of ExecJS context to fix #165
5
+
1
6
  ## 4.1.20 (17 November 2018)
2
7
 
3
8
  - update UglifyJS to [3.4.8](https://github.com/mishoo/UglifyJS2/compare/v3.4.9...v3.4.8)
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
  ```
@@ -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(@context.call("uglifier", options), generate_map)
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 error_message(result)
224
- result['error']['message'] +
225
- if result['error']['message'].start_with?("Unexpected token") && !harmony?
226
- ". To use ES6 syntax, harmony mode must be enabled with " \
227
- "Uglifier.new(:harmony => true)."
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']]
@@ -1,4 +1,4 @@
1
1
  class Uglifier
2
2
  # Current version of Uglifier.
3
- VERSION = "4.1.20"
3
+ VERSION = "4.2.0"
4
4
  end
@@ -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", "~> 1.3"
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.1.20
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: 2018-11-17 00:00:00.000000000 Z
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
- rubyforge_project:
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