terser 1.0.2 → 1.1.17

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.
data/lib/terser.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require "json"
5
5
  require "base64"
6
6
  require "execjs"
7
+ require "terser/railtie" if defined?(Rails::Railtie)
7
8
  require "terser/version"
8
9
 
9
10
  # A wrapper around the Terser interface
@@ -31,6 +32,7 @@ class Terser
31
32
  :ascii_only => true, # Escape non-ASCII characterss
32
33
  :comments => :copyright, # Preserve comments (:all, :jsdoc, :copyright, :none)
33
34
  :inline_script => false, # Escape occurrences of </script in strings
35
+ :keep_numbers => false, # Disables optimizations like converting 1000000 into 1e6
34
36
  :quote_keys => false, # Quote keys in object literals
35
37
  :max_line_len => 32 * 1024, # Maximum line length in minified code
36
38
  :semicolons => true, # Separate statements with semicolons
@@ -79,9 +81,11 @@ class Terser
79
81
  :pure_funcs => nil, # List of functions without side-effects. Can safely discard function calls when the result value is not used
80
82
  :drop_console => false, # Drop calls to console.* functions
81
83
  :keep_fargs => false, # Preserve unused function arguments
84
+ :keep_classnames => false, # Prevents discarding or mangling of class names. Pass a regular expression to only keep class names matching that regex.
82
85
  :keep_fnames => false, # Do not drop names in function definitions
83
86
  :passes => 1, # Number of times to run compress. Raising the number of passes will increase compress time, but can produce slightly smaller code.
84
87
  :keep_infinity => false, # Prevent compression of Infinity to 1/0
88
+ :lhs_constants => true, # Moves constant values to the left-hand side of binary nodes. `foo == 42 → 42 == foo`
85
89
  :side_effects => true, # Pass false to disable potentially dropping functions marked as "pure" using pure comment annotation. See TerserJS documentation for details.
86
90
  :switches => true # de-duplicate and remove unreachable switch branches
87
91
  }, # Apply transformations to code, set to false to skip
@@ -93,7 +97,8 @@ class Terser
93
97
  :strict => false
94
98
  },
95
99
  :define => {}, # Define values for symbol replacement
96
- :keep_fnames => false, # Generate code safe for the poor souls relying on Function.prototype.name at run-time. Sets both compress and mangle keep_fanems to true.
100
+ :keep_fnames => false, # Generate code safe for the poor souls relying on Function.prototype.name at run-time. Sets both compress and mangle keep_fnames to true.
101
+ :keep_classnames => false, # Prevents discarding or mangling of class names. Sets both compress and mangle keep_classnames to true.
97
102
  :toplevel => false,
98
103
  :source_map => false, # Generate source map
99
104
  :error_context_lines => 8 # How many lines surrounding the error line
@@ -296,7 +301,8 @@ class Terser
296
301
  def mangle_options
297
302
  defaults = conditional_option(
298
303
  DEFAULTS[:mangle],
299
- :keep_fnames => keep_fnames?(:mangle)
304
+ :keep_fnames => keep_fnames?(:mangle),
305
+ :keep_classnames => keep_classnames?(:mangle)
300
306
  )
301
307
 
302
308
  conditional_option(
@@ -334,7 +340,10 @@ class Terser
334
340
  conditional_option(
335
341
  @options[:compress],
336
342
  defaults,
337
- { :keep_fnames => keep_fnames?(:compress) }.merge(negate_iife_block)
343
+ {
344
+ :keep_fnames => keep_fnames?(:compress),
345
+ :keep_classnames => keep_classnames?(:compress)
346
+ }.merge(negate_iife_block)
338
347
  )
339
348
  end
340
349
 
@@ -397,8 +406,17 @@ class Terser
397
406
  if @options[:keep_fnames] || DEFAULTS[:keep_fnames]
398
407
  true
399
408
  else
400
- @options[type].respond_to?(:[]) && @options[type][:keep_fnames] ||
401
- DEFAULTS[type].respond_to?(:[]) && DEFAULTS[type][:keep_fnames]
409
+ (@options[type].respond_to?(:[]) && @options[type][:keep_fnames]) ||
410
+ (DEFAULTS[type].respond_to?(:[]) && DEFAULTS[type][:keep_fnames])
411
+ end
412
+ end
413
+
414
+ def keep_classnames?(type)
415
+ if @options[:keep_classnames] || DEFAULTS[:keep_classnames]
416
+ true
417
+ else
418
+ (@options[type].respond_to?(:[]) && @options[type][:keep_classnames]) ||
419
+ (DEFAULTS[type].respond_to?(:[]) && DEFAULTS[type][:keep_classnames])
402
420
  end
403
421
  end
404
422
 
@@ -410,7 +428,7 @@ class Terser
410
428
  :filename => options[:output_filename],
411
429
  :root => options.fetch(:root) { input_map ? input_map["sourceRoot"] : nil },
412
430
  :content => input_map,
413
- #:map_url => options[:map_url],
431
+ # :map_url => options[:map_url],
414
432
  :url => options[:url],
415
433
  :includeSources => options[:sources_content]
416
434
  }
@@ -45,7 +45,11 @@ function terser_wrapper(options) {
45
45
 
46
46
  var inputs = {};
47
47
  inputs[inputFilename] = source;
48
- var result = Terser.minify(inputs, options);
49
- //if (result.error) throw result.error;
50
- return result;
48
+
49
+ try {
50
+ return Terser.minifySync(inputs, options, null);
51
+ } catch (error) {
52
+ const { message, filename, line, col, pos } = error;
53
+ return {error: {message: message, filename: filename, line: line, col: col, pos: pos}}
54
+ }
51
55
  }
data/terser.gemspec CHANGED
@@ -26,13 +26,13 @@ Gem::Specification.new do |spec|
26
26
  ]
27
27
 
28
28
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
- f.match(%r{^(spec|vendor|gemfiles|patches|benchmark)/})
29
+ f.match(%r{^(spec|vendor|gemfiles|patches|benchmark|.github)/})
30
30
  end
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_runtime_dependency "execjs", [">= 0.3.0", "< 3"]
34
34
  spec.add_development_dependency "bundler", ">= 1.3"
35
- spec.add_development_dependency "rake", "~> 12.0"
35
+ spec.add_development_dependency "rake", "~> 13.0"
36
36
  spec.add_development_dependency "rspec", "~> 3.0"
37
37
  spec.add_development_dependency "sourcemap", "~> 0.1.1"
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Rosicky
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '12.0'
53
+ version: '13.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '12.0'
60
+ version: '13.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,6 @@ files:
103
103
  - ".gitmodules"
104
104
  - ".rspec"
105
105
  - ".rubocop.yml"
106
- - ".travis.yml"
107
106
  - ".yardopts"
108
107
  - CHANGELOG.md
109
108
  - CONTRIBUTING.md
@@ -117,6 +116,7 @@ files:
117
116
  - lib/terser.js
118
117
  - lib/terser.rb
119
118
  - lib/terser/compressor.rb
119
+ - lib/terser/railtie.rb
120
120
  - lib/terser/version.rb
121
121
  - lib/terser_wrapper.js
122
122
  - terser.gemspec
@@ -124,7 +124,7 @@ homepage: http://github.com/ahorek/terser-ruby
124
124
  licenses:
125
125
  - MIT
126
126
  metadata: {}
127
- post_install_message:
127
+ post_install_message:
128
128
  rdoc_options: []
129
129
  require_paths:
130
130
  - lib
@@ -139,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.1.2
143
- signing_key:
142
+ rubygems_version: 3.3.22
143
+ signing_key:
144
144
  specification_version: 4
145
145
  summary: Ruby wrapper for Terser JavaScript compressor
146
146
  test_files: []
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.3
6
- - 2.5
7
- - 2.7
8
- - ruby-head
9
- - jruby-head
10
- - jruby-9.2.12.0
11
- - truffleruby
12
- - truffleruby-head
13
- before_install:
14
- - gem install bundler -v 1.17.3
15
- git:
16
- submodules: false
17
- gemfile:
18
- - Gemfile
19
- matrix:
20
- include:
21
- - rvm: 2.5
22
- gemfile: gemfiles/miniracer
23
- allow_failures:
24
- - rvm: ruby-head
25
- - rvm: truffleruby
26
- - rvm: jruby-head
27
- - rvm: truffleruby-head
28
- fast_finish: true