Skip to content

Commit

Permalink
Merge pull request #40 from ahorek/teserer5165
Browse files Browse the repository at this point in the history
update terser to 5.16.5
  • Loading branch information
ahorek authored Feb 24, 2023
2 parents 58a4221 + 09b0954 commit db2353b
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- { ruby: '3.0', c-o-e: false }
- { ruby: 3.1, c-o-e: false }
- { ruby: 3.2, c-o-e: false }
- { ruby: jruby-9.4.0.0, c-o-e: false }
- { ruby: jruby-9.4.1.0, c-o-e: false }
- { ruby: ruby-head, c-o-e: true }
- { ruby: jruby-head, c-o-e: true }
- { ruby: truffleruby, c-o-e: true }
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased
## 1.1.14 (24 February 2023)
- update TerserJS to [5.16.5]
- update Rubocop

## 1.1.13 (03 December 2022)
Expand Down
2 changes: 1 addition & 1 deletion lib/terser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/terser/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

class Terser
# Current version of Terser.
VERSION = "1.1.13"
VERSION = "1.1.14"
end
150 changes: 51 additions & 99 deletions patches/revert-source-maps.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
diff --git a/lib/minify.js b/lib/minify.js
index aa3f73d8..0731d838 100644
index 725e3d96..4cef6bb1 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -297,15 +297,21 @@ async function minify(files, options, _fs_module) {
@@ -280,13 +280,10 @@ async function minify(files, options, _fs_module) {
if (options.format.spidermonkey) {
result.ast = toplevel.to_mozilla_ast();
}
- let format_options;
if (!HOP(options.format, "code") || options.format.code) {
- // Make a shallow copy so that we can modify without mutating the user's input.
- format_options = {...options.format};
- if (!format_options.ast) {
+ if (!options.format.ast) {
// Destroy stuff to save RAM. (unless the deprecated `ast` option is on)
- format_options._destroy_ast = true;
+ options.format._destroy_ast = true;

walk(toplevel, node => {
if (node instanceof AST_Scope) {
@@ -303,38 +300,34 @@ async function minify(files, options, _fs_module) {
}

if (options.sourceMap) {
Expand All @@ -11,7 +27,7 @@ index aa3f73d8..0731d838 100644
+ if (typeof options.sourceMap.content == "string") {
+ options.sourceMap.content = JSON.parse(options.sourceMap.content);
}
- options.format.source_map = await SourceMap({
- format_options.source_map = await SourceMap({
+ options.format.source_map = SourceMap({
file: options.sourceMap.filename,
orig: options.sourceMap.content,
Expand All @@ -27,17 +43,22 @@ index aa3f73d8..0731d838 100644
+ }
+ }
}
delete options.format.ast;
delete options.format.code;
@@ -314,21 +320,11 @@ async function minify(files, options, _fs_module) {
- delete format_options.ast;
- delete format_options.code;
- delete format_options.spidermonkey;
- var stream = OutputStream(format_options);
+ delete options.format.ast;
+ delete options.format.code;
+ delete options.format.spidermonkey;
+ var stream = OutputStream(options.format);
toplevel.print(stream);
result.code = stream.get();
if (options.sourceMap) {
- Object.defineProperty(result, "map", {
- configurable: true,
- enumerable: true,
- get() {
- const map = options.format.source_map.getEncoded();
- const map = format_options.source_map.getEncoded();
- return (result.map = options.sourceMap.asObject ? map : JSON.stringify(map));
- },
- set(value) {
Expand All @@ -47,7 +68,7 @@ index aa3f73d8..0731d838 100644
- });
- }
- });
- result.decoded_map = options.format.source_map.getDecoded();
- result.decoded_map = format_options.source_map.getDecoded();
+ if(options.sourceMap.asObject) {
+ result.map = options.format.source_map.get().toJSON();
+ } else {
Expand All @@ -56,12 +77,12 @@ index aa3f73d8..0731d838 100644
if (options.sourceMap.url == "inline") {
var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map;
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(sourceMap);
@@ -343,9 +339,6 @@ async function minify(files, options, _fs_module) {
@@ -349,9 +342,6 @@ async function minify(files, options, _fs_module) {
options.nameCache.props = cache_to_json(options.mangle.properties.cache);
}
}
- if (options.format && options.format.source_map) {
- options.format.source_map.destroy();
- if (format_options && format_options.source_map) {
- format_options.source_map.destroy();
- }
if (timings) {
timings.end = Date.now();
Expand Down Expand Up @@ -140,47 +161,23 @@ index f376ccc8..4fd32e84 100644
};
}

diff --git a/package-lock.json b/package-lock.json
index 7afb74f3..b9ab9960 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1536,28 +1536,17 @@
}
},
"source-map": {
- "version": "0.8.0-beta.0",
- "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz",
- "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==",
- "dev": true,
- "requires": {
- "whatwg-url": "^7.0.0"
- }
+ "version": "0.6.1",
+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
+ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
},
"source-map-support": {
- "version": "0.5.20",
- "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.20.tgz",
- "integrity": "sha512-n1lZZ8Ve4ksRqizaBQgxXDgKwttHDhyfQjA6YZZn8+AroHbsIz+JjwxQDxbp+7y5OYCI8t1Yk7etjD9CRd2hIw==",
+ "version": "0.5.13",
+ "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz",
+ "integrity": "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==",
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
- },
- "dependencies": {
- "source-map": {
- "version": "0.6.1",
- "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
- "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
- }
}
},
"spawn-sync": {
diff --git a/main.js b/main.js
index 0a10db5a..8eb0dc81 100644
--- a/main.js
+++ b/main.js
@@ -1,8 +1,8 @@
import "./lib/transform.js";
import "./lib/mozilla-ast.js";
-import { minify } from "./lib/minify.js";
+import { minify, minifySync } from "./lib/minify.js";

-export { minify } from "./lib/minify.js";
+export { minify, minifySync } from "./lib/minify.js";
export { run_cli as _run_cli } from "./lib/cli.js";

export async function _default_options() {
diff --git a/package.json b/package.json
index 0a29e443..8e1320f1 100644
index 9c37e699..ada2196e 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,8 @@
Expand All @@ -203,51 +200,6 @@ index 0a29e443..8e1320f1 100644
},
"scripts": {
"test": "node test/compress.js && mocha test/mocha",
diff --git a/test/benchmark.cjs b/test/benchmark.cjs
index aea0059b..45769600 100644
--- a/test/benchmark.cjs
+++ b/test/benchmark.cjs
@@ -4,11 +4,9 @@
"use strict";

var createHash = require("crypto").createHash;
+var fetch = require("./fetch");
var fork = require("child_process").fork;
var zlib = require("zlib");
-
-var fetch = require("./fetch.cjs");
-
var args = process.argv.slice(2);
if (!args.length) {
args.push("-mc");
diff --git a/test/input/issue-520/output.js b/test/input/issue-520/output.js
index 0aa3c963..f6d13804 100644
--- a/test/input/issue-520/output.js
+++ b/test/input/issue-520/output.js
@@ -1,2 +1,2 @@
new function(){console.log(3)};
-//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJjb25zb2xlIiwibG9nIl0sInNvdXJjZXMiOlsic3RkaW4iXSwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHsgY29uc3RydWN0b3IoKXtjb25zb2xlLmxvZygxKzIpO30gfSBuZXcgRm9vKCk7XG4iXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSJ9
+//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19
diff --git a/test/mocha/input-sourcemaps.js b/test/mocha/input-sourcemaps.js
index e0bffb43..ccdca452 100644
--- a/test/mocha/input-sourcemaps.js
+++ b/test/mocha/input-sourcemaps.js
@@ -32,7 +32,7 @@ describe("input sourcemaps", function() {
}
});

- map = await new SourceMapConsumer(result.map);
+ map = new SourceMapConsumer(result.map);
}

beforeEach(async function () {
diff --git a/test/mocha/utils.js b/test/mocha/utils.js
index 6e2ae714..e5cd8a26 100644
--- a/test/mocha/utils.js
+++ b/test/mocha/utils.js
@@ -1,5 +1,3 @@
-import assert from "assert";
-
function decodeMap(mapData) {
const buffer = new Buffer(mapData.replace('data:application/json;charset=utf-8;base64,', ''), 'base64');
return JSON.parse(buffer.toString());

warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory
6 changes: 3 additions & 3 deletions patches/terser-sync.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/lib/minify.js b/lib/minify.js
index aa3f73d8..1509bf33 100644
index 725e3d96..b256907c 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -100,6 +100,10 @@ function log_input(files, options, fs, debug_folder) {
@@ -103,6 +103,10 @@ function log_input(files, options, fs, debug_folder) {
}

async function minify(files, options, _fs_module) {
Expand All @@ -13,7 +13,7 @@ index aa3f73d8..1509bf33 100644
if (
_fs_module
&& typeof process === "object"
@@ -364,5 +368,6 @@ async function minify(files, options, _fs_module) {
@@ -370,5 +374,6 @@ async function minify(files, options, _fs_module) {

export {
minify,
Expand Down
6 changes: 6 additions & 0 deletions spec/terser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ class Bar {}
expect(compiled).to include("obj1<=obj2")
end

it 'does not loose equality with BigInt == number' do
code = 'if (-1 !== -1n) console.log("PASS");'
compiled = Terser.compile(code, :mangle => false, :compress => options)
expect(compiled).to include('-1!==-1n&&console.log("PASS");')
end

it 'optimises unsafe comparisons when unsafe_comps is enabled' do
compiled = Terser.compile(
code,
Expand Down
2 changes: 1 addition & 1 deletion terser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "execjs", [">= 0.3.0", "< 3"]
spec.add_development_dependency "bundler", ">= 1.3"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "sourcemap", "~> 0.1.1"
end

0 comments on commit db2353b

Please sign in to comment.