aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-11-21 02:30:46 +0000
committerGitHub <noreply@github.com>2020-11-21 10:30:46 +0800
commit645d5a348bced192907176876b9e46c942e7d0ae (patch)
treeff51af3a2a307ddc6186ccc857ebbc5250a5e3b5
parentcf120c7cea2721626caa67767d720431becf7f62 (diff)
downloadtracifyjs-645d5a348bced192907176876b9e46c942e7d0ae.tar.gz
tracifyjs-645d5a348bced192907176876b9e46c942e7d0ae.zip
workaround Safari quirks (#4314)
fixes #1753
-rw-r--r--README.md10
-rwxr-xr-xbin/uglifyjs2
-rw-r--r--lib/minify.js3
-rw-r--r--lib/scope.js16
-rw-r--r--test/compress/let.js42
5 files changed, 70 insertions, 3 deletions
diff --git a/README.md b/README.md
index 0bfad01a..bda1f02b 100644
--- a/README.md
+++ b/README.md
@@ -135,6 +135,10 @@ a double dash to prevent input files being used as option arguments:
--toplevel Compress and/or mangle variables in top level scope.
--verbose Print diagnostic messages.
--warn Print warning messages.
+ --webkit Support non-standard Safari/Webkit.
+ Equivalent to setting `webkit: true` in `minify()`
+ for `mangle` and `output` options.
+ By default UglifyJS will not try to be Safari-proof.
--wrap <name> Embed everything in a big function, making the
“exports” and “global” variables available. You
need to pass an argument to this option to
@@ -519,6 +523,9 @@ if (result.error) throw result.error;
- `warnings` (default `false`) — pass `true` to return compressor warnings
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
+- `webkit` (default `false`) -- enable workarounds for Safari/WebKit bugs.
+ PhantomJS users should set this option to `true`.
+
## Minify options structure
```javascript
@@ -910,9 +917,6 @@ can pass additional arguments that control the code output:
- `v8` (default `false`) -- enable workarounds for Chrome & Node.js bugs
-- `webkit` (default `false`) -- enable workarounds for WebKit bugs.
- PhantomJS users should set this option to `true`.
-
- `width` (default `80`) -- only takes effect when beautification is on, this
specifies an (orientative) line width that the beautifier will try to
obey. It refers to the width of the line text (excluding indentation).
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 618b88da..4d1fb5a2 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -111,6 +111,7 @@ function process_option(name, no_value) {
" --validate Perform validation during AST manipulations.",
" --verbose Print diagnostic messages.",
" --warn Print warning messages.",
+ " --webkit Support non-standard Safari/Webkit.",
" --wrap <name> Embed everything as a function with “exports” corresponding to “name” globally.",
" --reduce-test Reduce a standalone test case (assumes cloned repository).",
].join("\n"));
@@ -142,6 +143,7 @@ function process_option(name, no_value) {
case "timings":
case "toplevel":
case "validate":
+ case "webkit":
options[name] = true;
break;
case "keep-fnames":
diff --git a/lib/minify.js b/lib/minify.js
index 5f363989..678fbca9 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -89,6 +89,7 @@ function minify(files, options) {
toplevel: false,
validate: false,
warnings: false,
+ webkit: false,
wrap: false,
}, true);
if (options.validate) AST_Node.enable_validation();
@@ -101,6 +102,7 @@ function minify(files, options) {
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
+ set_shorthand("webkit", options, [ "mangle", "output" ]);
var quoted_props;
if (options.mangle) {
options.mangle = defaults(options.mangle, {
@@ -111,6 +113,7 @@ function minify(files, options) {
properties: false,
reserved: [],
toplevel: false,
+ webkit: false,
}, true);
if (options.mangle.properties) {
if (typeof options.mangle.properties != "object") {
diff --git a/lib/scope.js b/lib/scope.js
index 4cc65c75..4d080fee 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -486,6 +486,7 @@ function _default_mangler_options(options) {
keep_fnames : false,
reserved : [],
toplevel : false,
+ webkit : false,
});
if (!Array.isArray(options.reserved)) options.reserved = [];
// Never mangle arguments
@@ -520,6 +521,21 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
return true;
}
if (node instanceof AST_BlockScope) {
+ if (options.webkit && node instanceof AST_IterationStatement && node.init instanceof AST_Let) {
+ node.init.definitions.forEach(function(defn) {
+ defn.name.match_symbol(function(sym) {
+ if (!(sym instanceof AST_SymbolLet)) return;
+ var def = sym.definition();
+ var scope = sym.scope.parent_scope;
+ var redef = scope.def_variable(sym);
+ sym.thedef = def;
+ scope.to_mangle.push(redef);
+ def.redefined = function() {
+ return redef;
+ };
+ });
+ }, true);
+ }
node.to_mangle = [];
node.variables.each(function(def) {
if (!defer_redef(def)) node.to_mangle.push(def);
diff --git a/test/compress/let.js b/test/compress/let.js
index 76641c3f..fc323320 100644
--- a/test/compress/let.js
+++ b/test/compress/let.js
@@ -1186,3 +1186,45 @@ issue_4305_2: {
expect_stdout: true
node_version: ">=4"
}
+
+issue_1753: {
+ mangle = {
+ toplevel: false,
+ webkit: true,
+ }
+ input: {
+ "use strict";
+ let l = null;
+ for (let i = 0; i < 1; i++)
+ console.log(i);
+ }
+ expect: {
+ "use strict";
+ let l = null;
+ for (let i = 0; i < 1; i++)
+ console.log(i);
+ }
+ expect_stdout: "0"
+ node_version: ">=4"
+}
+
+issue_1753_toplevel: {
+ mangle = {
+ toplevel: true,
+ webkit: true,
+ }
+ input: {
+ "use strict";
+ let l = null;
+ for (let i = 0; i < 1; i++)
+ console.log(i);
+ }
+ expect: {
+ "use strict";
+ let l = null;
+ for (let e = 0; e < 1; e++)
+ console.log(e);
+ }
+ expect_stdout: "0"
+ node_version: ">=4"
+}