terser 1.2.4 → 1.2.8
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/.rubocop.yml +2 -0
- data/CHANGELOG.md +14 -0
- data/README.md +1 -0
- data/lib/terser/version.rb +1 -1
- data/lib/terser.js +2584 -878
- data/lib/terser.rb +20 -6
- metadata +2 -2
data/lib/terser.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "json"
|
|
5
|
-
require "base64"
|
|
6
5
|
require "execjs"
|
|
7
6
|
require "terser/railtie" if defined?(Rails::Railtie)
|
|
8
7
|
require "terser/version"
|
|
@@ -88,7 +87,10 @@ class Terser
|
|
|
88
87
|
:keep_infinity => false, # Prevent compression of Infinity to 1/0
|
|
89
88
|
:lhs_constants => true, # Moves constant values to the left-hand side of binary nodes. `foo == 42 → 42 == foo`
|
|
90
89
|
:side_effects => true, # Pass false to disable potentially dropping functions marked as "pure" using pure comment annotation. See TerserJS documentation for details.
|
|
91
|
-
:switches => true # de-duplicate and remove unreachable switch branches
|
|
90
|
+
:switches => true, # de-duplicate and remove unreachable switch branches
|
|
91
|
+
:ecma => 5, # Pass `2015` or greater to enable `compress` options that will transform ES5 code into smaller ES6+ equivalent forms.
|
|
92
|
+
:builtins_ecma => 5, # An ES version number (like `ecma`). Tells Terser which well-known functions, constants, methods and classes are available in the global object. Does nothing by itself, but is used by `builtins_pure` and `unsafe`.
|
|
93
|
+
:builtins_pure => false # Pass `true` to assume that functions matched by the `builtins_ecma` option (such as `Math.sin` or `unescape`) are pure and calls to them can be removed.
|
|
92
94
|
}, # Apply transformations to code, set to false to skip
|
|
93
95
|
:parse => {
|
|
94
96
|
:bare_returns => false, # Allow top-level return statements.
|
|
@@ -102,7 +104,8 @@ class Terser
|
|
|
102
104
|
:keep_classnames => false, # Prevents discarding or mangling of class names. Sets both compress and mangle keep_classnames to true.
|
|
103
105
|
:toplevel => false,
|
|
104
106
|
:source_map => false, # Generate source map
|
|
105
|
-
:error_context_lines => 8 # How many lines surrounding the error line
|
|
107
|
+
:error_context_lines => 8, # How many lines surrounding the error line
|
|
108
|
+
:module => false # Use when minifying an ES6 module. "use strict" is implied and names can be mangled on the top scope
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
EXTRA_OPTIONS = [:comments, :mangle_properties]
|
|
@@ -163,7 +166,7 @@ class Terser
|
|
|
163
166
|
def compile(source, source_map_options = @options)
|
|
164
167
|
if source_map_options[:source_map]
|
|
165
168
|
compiled, source_map = run_terserjs(source, true, source_map_options)
|
|
166
|
-
source_map_uri =
|
|
169
|
+
source_map_uri = [source_map].pack("m0")
|
|
167
170
|
source_map_mime = "application/json;charset=utf-8;base64"
|
|
168
171
|
compiled + "\n//# sourceMappingURL=data:#{source_map_mime},#{source_map_uri}"
|
|
169
172
|
else
|
|
@@ -223,7 +226,8 @@ class Terser
|
|
|
223
226
|
:compress => compressor_options,
|
|
224
227
|
:mangle => mangle_options,
|
|
225
228
|
:parse => parse_options(source_map_options),
|
|
226
|
-
:sourceMap => source_map_options(input_map, source_map_options)
|
|
229
|
+
:sourceMap => source_map_options(input_map, source_map_options),
|
|
230
|
+
:module => @options[:module] || DEFAULTS[:module]
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
parse_result(context.call("terser_wrapper", options), generate_map, options, source_map_options)
|
|
@@ -506,9 +510,19 @@ class Terser
|
|
|
506
510
|
source_map_options = options[:source_map].is_a?(Hash) ? options[:source_map] : {}
|
|
507
511
|
sanitize_map_root(source_map_options.fetch(:input_source_map) do
|
|
508
512
|
url = extract_source_mapping_url(source)
|
|
509
|
-
|
|
513
|
+
base64_strict_decode64(url.split(",", 2)[-1]) if url && url.start_with?("data:")
|
|
510
514
|
end)
|
|
511
515
|
rescue ArgumentError, JSON::ParserError
|
|
512
516
|
nil
|
|
513
517
|
end
|
|
518
|
+
|
|
519
|
+
if "".respond_to?(:unpack1)
|
|
520
|
+
def base64_strict_decode64(str)
|
|
521
|
+
str.unpack1("m0")
|
|
522
|
+
end
|
|
523
|
+
else
|
|
524
|
+
def base64_strict_decode64(str)
|
|
525
|
+
str.unpack("m0")[0]
|
|
526
|
+
end
|
|
527
|
+
end
|
|
514
528
|
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.2.
|
|
4
|
+
version: 1.2.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pavel Rosicky
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: execjs
|