diff --git a/CHANGELOG.md b/CHANGELOG.md index 245d60e90..10dda926b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v4.3.7 + + - Parsing of regex options in the CLI (which broke in v4.3.5) was fixed. + - typescript definition updates + +## v4.3.6 + +(crash hotfix) + ## v4.3.5 - Fixed an issue with DOS line endings strings separated by `\` and a new line. diff --git a/README.md b/README.md index 60278001f..ec2cc4412 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,7 @@ way to use this is to use the `regex` option like so: terser example.js -c -m --mangle-props regex=/_$/ ``` -This will mangle all properties that start with an +This will mangle all properties that end with an underscore. So you can use it to mangle internal methods. By default, it will mangle all properties in the @@ -289,32 +289,32 @@ console.log(x.calc()); ``` Mangle all properties (except for JavaScript `builtins`) (**very** unsafe): ```bash -$ terser example.js -c -m --mangle-props +$ terser example.js -c passes=2 -m --mangle-props ``` ```javascript -var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l()); +var x={o:3,t:1,i:function(){return this.t+this.o},s:2};console.log(x.i()); ``` Mangle all properties except for `reserved` properties (still very unsafe): ```bash -$ terser example.js -c -m --mangle-props reserved=[foo_,bar_] +$ terser example.js -c passes=2 -m --mangle-props reserved=[foo_,bar_] ``` ```javascript -var x={o:0,foo_:1,_:function(){return this.foo_+this.o}};x.bar_=2,x.o=3,console.log(x._()); +var x={o:3,foo_:1,t:function(){return this.foo_+this.o},bar_:2};console.log(x.t()); ``` Mangle all properties matching a `regex` (not as unsafe but still unsafe): ```bash -$ terser example.js -c -m --mangle-props regex=/_$/ +$ terser example.js -c passes=2 -m --mangle-props regex=/_$/ ``` ```javascript -var x={o:0,_:1,calc:function(){return this._+this.o}};x.l=2,x.o=3,console.log(x.calc()); +var x={o:3,t:1,calc:function(){return this.t+this.o},i:2};console.log(x.calc()); ``` Combining mangle properties options: ```bash -$ terser example.js -c -m --mangle-props regex=/_$/,reserved=[bar_] +$ terser example.js -c passes=2 -m --mangle-props regex=/_$/,reserved=[bar_] ``` ```javascript -var x={o:0,_:1,calc:function(){return this._+this.o}};x.bar_=2,x.o=3,console.log(x.calc()); +var x={o:3,t:1,calc:function(){return this.t+this.o},bar_:2};console.log(x.calc()); ``` In order for this to be of any use, we avoid mangling standard JS names by @@ -820,7 +820,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t case a value of `20` or less is recommended. - `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping - functions marked as "pure". A function call is marked as "pure" if a comment + function calls marked as "pure". A function call is marked as "pure" if a comment annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For example: `/*@__PURE__*/foo();` diff --git a/bin/terser b/bin/terser index fbc5e2850..bfcdd5dfc 100755 --- a/bin/terser +++ b/bin/terser @@ -368,6 +368,9 @@ function parse_js(flag) { options[name] = value; } else if (value instanceof Terser.AST_Array) { options[name] = value.elements.map(to_string); + } else if (value instanceof Terser.AST_RegExp) { + value = value.value; + options[name] = new RegExp(value.source, value.flags); } else { options[name] = to_string(value); } diff --git a/package-lock.json b/package-lock.json index 759fdf9f1..b0d634fa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "terser", - "version": "4.3.6", + "version": "4.3.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c7ff42928..a14c19f50 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "https://terser.org", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "4.3.6", + "version": "4.3.7", "engines": { "node": ">=6.0.0" }, diff --git a/test/input/issue-483/input.js b/test/input/issue-483/input.js new file mode 100644 index 000000000..167e503ec --- /dev/null +++ b/test/input/issue-483/input.js @@ -0,0 +1,7 @@ +function func1(obj) { + obj._somePrivateProperty = false; +} + +function func2(obj) { + obj.nonPrivateProperty = true; +} diff --git a/test/mocha/cli-2.js b/test/mocha/cli-2.js index cf9635c21..9834ee34c 100644 --- a/test/mocha/cli-2.js +++ b/test/mocha/cli-2.js @@ -167,4 +167,12 @@ describe("bin/terser (2)", function() { done(); }); }); + it("should parse regex options correctly", (done) => { + var command = tersercmd + " --toplevel -m keep_fnames=/1$/ --mangle-props regex=/^_/ test/input/issue-483/input.js"; + exec(command, function(err, stdout, stderr) { + if (err) throw err; + assert.strictEqual(stdout, "function func1(n){n.u=false}function n(n){n.nonPrivateProperty=true}\n"); + done(); + }); + }); }); diff --git a/tools/terser.d.ts b/tools/terser.d.ts index 7f8679809..3d94fde40 100644 --- a/tools/terser.d.ts +++ b/tools/terser.d.ts @@ -15,6 +15,7 @@ export interface CompressOptions { arguments?: boolean; arrows?: boolean; booleans?: boolean; + booleans_as_integers?: boolean; collapse_vars?: boolean; comparisons?: boolean; computed_props?: boolean; @@ -31,6 +32,7 @@ export interface CompressOptions { hoist_funs?: boolean; hoist_props?: boolean; hoist_vars?: boolean; + ie8?: boolean; if_return?: boolean; inline?: boolean | InlineFunctions; join_vars?: boolean; @@ -52,6 +54,7 @@ export interface CompressOptions { switches?: boolean; toplevel?: boolean; top_retain?: null | string | string[] | RegExp; + toplevel?: boolean; typeofs?: boolean; unsafe?: boolean; unsafe_arrows?: boolean;