terser 1.2.4 → 1.2.7

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
@@ -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"
@@ -102,7 +101,8 @@ class Terser
102
101
  :keep_classnames => false, # Prevents discarding or mangling of class names. Sets both compress and mangle keep_classnames to true.
103
102
  :toplevel => false,
104
103
  :source_map => false, # Generate source map
105
- :error_context_lines => 8 # How many lines surrounding the error line
104
+ :error_context_lines => 8, # How many lines surrounding the error line
105
+ :module => false # Use when minifying an ES6 module. "use strict" is implied and names can be mangled on the top scope
106
106
  }
107
107
 
108
108
  EXTRA_OPTIONS = [:comments, :mangle_properties]
@@ -163,7 +163,7 @@ class Terser
163
163
  def compile(source, source_map_options = @options)
164
164
  if source_map_options[:source_map]
165
165
  compiled, source_map = run_terserjs(source, true, source_map_options)
166
- source_map_uri = Base64.strict_encode64(source_map)
166
+ source_map_uri = [source_map].pack("m0")
167
167
  source_map_mime = "application/json;charset=utf-8;base64"
168
168
  compiled + "\n//# sourceMappingURL=data:#{source_map_mime},#{source_map_uri}"
169
169
  else
@@ -223,7 +223,8 @@ class Terser
223
223
  :compress => compressor_options,
224
224
  :mangle => mangle_options,
225
225
  :parse => parse_options(source_map_options),
226
- :sourceMap => source_map_options(input_map, source_map_options)
226
+ :sourceMap => source_map_options(input_map, source_map_options),
227
+ :module => @options[:module] || DEFAULTS[:module]
227
228
  }
228
229
 
229
230
  parse_result(context.call("terser_wrapper", options), generate_map, options, source_map_options)
@@ -506,9 +507,19 @@ class Terser
506
507
  source_map_options = options[:source_map].is_a?(Hash) ? options[:source_map] : {}
507
508
  sanitize_map_root(source_map_options.fetch(:input_source_map) do
508
509
  url = extract_source_mapping_url(source)
509
- Base64.strict_decode64(url.split(",", 2)[-1]) if url && url.start_with?("data:")
510
+ base64_strict_decode64(url.split(",", 2)[-1]) if url && url.start_with?("data:")
510
511
  end)
511
512
  rescue ArgumentError, JSON::ParserError
512
513
  nil
513
514
  end
515
+
516
+ if "".respond_to?(:unpack1)
517
+ def base64_strict_decode64(str)
518
+ str.unpack1("m0")
519
+ end
520
+ else
521
+ def base64_strict_decode64(str)
522
+ str.unpack("m0")[0]
523
+ end
524
+ end
514
525
  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
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Rosicky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-07 00:00:00.000000000 Z
11
+ date: 2026-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs