aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-07-17 13:20:56 +0100
committerGitHub <noreply@github.com>2021-07-17 20:20:56 +0800
commitef5f7fc25e93833396540cf7479685b241bd1b8f (patch)
tree22233bb2d8587a43e9bb34633dcdd89fdc88da2a /lib
parent902997b73dd0a6f3a8ada67f5e8bbfed000f5282 (diff)
downloadtracifyjs-ef5f7fc25e93833396540cf7479685b241bd1b8f.tar.gz
tracifyjs-ef5f7fc25e93833396540cf7479685b241bd1b8f.zip
workaround various IE quirks (#5084)
fixes #5081
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js42
-rw-r--r--lib/minify.js5
-rw-r--r--lib/output.js10
-rw-r--r--lib/scope.js8
4 files changed, 38 insertions, 27 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fa684339..27fcacb0 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -70,7 +70,7 @@ function Compressor(options, false_by_default) {
hoist_funs : false,
hoist_props : !false_by_default,
hoist_vars : false,
- ie8 : false,
+ ie : false,
if_return : !false_by_default,
imports : !false_by_default,
inline : !false_by_default,
@@ -206,7 +206,7 @@ merge(Compressor.prototype, {
var passes = +this.options.passes || 1;
var min_count = 1 / 0;
var stopping = false;
- var mangle = { ie8: this.option("ie8") };
+ var mangle = { ie: this.option("ie") };
for (var pass = 0; pass < passes; pass++) {
node.figure_out_scope(mangle);
if (pass > 0 || this.option("reduce_vars"))
@@ -513,7 +513,7 @@ merge(Compressor.prototype, {
if (scope.uses_arguments) scope.each_argname(function(node) {
node.definition().last_ref = false;
});
- if (compressor.option("ie8")) scope.variables.each(function(def) {
+ if (compressor.option("ie")) scope.variables.each(function(def) {
var d = def.orig[0].definition();
if (d !== def) d.fixed = false;
});
@@ -2249,7 +2249,7 @@ merge(Compressor.prototype, {
return side_effects || lhs instanceof AST_PropAccess || may_modify(lhs);
}
if (node instanceof AST_Function) {
- return compressor.option("ie8") && node.name && lvalues.has(node.name.name);
+ return compressor.option("ie") && node.name && lvalues.has(node.name.name);
}
if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node, parent);
if (node instanceof AST_PropAccess) {
@@ -4208,7 +4208,7 @@ merge(Compressor.prototype, {
AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) {
if (!compressor.option("global_defs")) return this;
- this.figure_out_scope({ ie8: compressor.option("ie8") });
+ this.figure_out_scope({ ie: compressor.option("ie") });
return this.transform(new TreeTransformer(function(node) {
var def = node._find_defs(compressor, "");
if (!def) return;
@@ -5672,7 +5672,7 @@ merge(Compressor.prototype, {
if (node instanceof AST_Call) {
var exp = node.expression;
var tail = exp.tail_node();
- if (!(tail instanceof AST_LambdaExpression)) return;
+ if (!(tail instanceof AST_LambdaExpression)) return walk_node_with_expr(node);
if (exp !== tail) exp.expressions.slice(0, -1).forEach(function(node) {
node.walk(tw);
});
@@ -5788,6 +5788,7 @@ merge(Compressor.prototype, {
pop();
return true;
}
+ if (node instanceof AST_Sub) return walk_node_with_expr(node);
if (node instanceof AST_Switch) {
node.expression.walk(tw);
var save = segment;
@@ -5886,6 +5887,15 @@ merge(Compressor.prototype, {
pop();
return true;
}
+
+ function walk_node_with_expr(node) {
+ descend();
+ if (compressor.option("ie")) {
+ var sym = root_expr(node.expression);
+ if (sym instanceof AST_SymbolRef) sym.walk(tw);
+ }
+ return true;
+ }
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
@@ -6235,7 +6245,7 @@ merge(Compressor.prototype, {
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
- var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) {
+ var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie") ? function(def) {
return !compressor.exposed(def) && def.references.length == def.replaced;
} : function(def) {
if (!(def.id in in_use_ids)) return true;
@@ -6247,7 +6257,7 @@ merge(Compressor.prototype, {
return !ref.in_arg;
});
};
- if (compressor.option("ie8")) initializations.each(function(init, id) {
+ if (compressor.option("ie")) initializations.each(function(init, id) {
if (id in in_use_ids) return;
init.forEach(function(init) {
init.walk(new TreeWalker(function(node) {
@@ -6535,7 +6545,7 @@ merge(Compressor.prototype, {
head.push(def);
}
} else if (compressor.option("functions")
- && !compressor.option("ie8")
+ && !compressor.option("ie")
&& drop_sym
&& var_defs[sym.id] == 1
&& sym.assignments == 0
@@ -7652,7 +7662,7 @@ merge(Compressor.prototype, {
});
function fn_name_unused(fn, compressor) {
- if (!fn.name || !compressor.option("ie8")) return true;
+ if (!fn.name || !compressor.option("ie")) return true;
var def = fn.name.definition();
if (compressor.exposed(def)) return false;
return all(def.references, function(sym) {
@@ -7969,7 +7979,7 @@ merge(Compressor.prototype, {
var alternative = this.alternative.drop_side_effect_free(compressor);
if (consequent === this.consequent && alternative === this.alternative) return this;
var exprs;
- if (compressor.option("ie8")) {
+ if (compressor.option("ie")) {
exprs = [];
if (consequent instanceof AST_Function) {
exprs.push(consequent);
@@ -7998,7 +8008,7 @@ merge(Compressor.prototype, {
node.consequent = consequent;
node.alternative = alternative;
}
- if (!compressor.option("ie8")) return node;
+ if (!compressor.option("ie")) return node;
if (node) exprs.push(node);
return exprs.length == 0 ? null : make_sequence(this, exprs);
});
@@ -9411,7 +9421,7 @@ merge(Compressor.prototype, {
return arg.value;
}).join() + "){" + self.args[self.args.length - 1].value + "})";
var ast = parse(code);
- var mangle = { ie8: compressor.option("ie8") };
+ var mangle = { ie: compressor.option("ie") };
ast.figure_out_scope(mangle);
var comp = new Compressor(compressor.options);
ast = ast.transform(comp);
@@ -10465,7 +10475,7 @@ merge(Compressor.prototype, {
&& self.right.operator == "typeof") {
var expr = self.right.expression;
if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
- : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
+ : !(expr instanceof AST_PropAccess && compressor.option("ie"))) {
self.right = expr;
self.left = make_node(AST_Undefined, self.left).optimize(compressor);
if (self.operator.length == 2) self.operator += "=";
@@ -11079,7 +11089,7 @@ merge(Compressor.prototype, {
}
OPT(AST_SymbolRef, function(self, compressor) {
- if (!compressor.option("ie8")
+ if (!compressor.option("ie")
&& is_undeclared_ref(self)
// testing against `self.scope.uses_with` is an optimization
&& !(self.scope.resolve().uses_with && compressor.find_parent(AST_With))) {
@@ -11121,7 +11131,7 @@ merge(Compressor.prototype, {
single_use = false;
} else if (fixed.has_side_effects(compressor)) {
single_use = false;
- } else if (compressor.option("ie8") && fixed instanceof AST_Class) {
+ } else if (compressor.option("ie") && fixed instanceof AST_Class) {
single_use = false;
}
if (single_use) fixed.parent_scope = self.scope;
diff --git a/lib/minify.js b/lib/minify.js
index e85adb1f..d3394b42 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -76,6 +76,7 @@ function minify(files, options) {
annotations: undefined,
compress: {},
enclose: false,
+ ie: false,
ie8: false,
keep_fnames: false,
mangle: {},
@@ -96,7 +97,7 @@ function minify(files, options) {
var timings = options.timings && { start: Date.now() };
if (options.rename === undefined) options.rename = options.compress && options.mangle;
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
- if (options.ie8) set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
+ if (options.ie || options.ie8) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
@@ -106,7 +107,7 @@ function minify(files, options) {
options.mangle = defaults(options.mangle, {
cache: options.nameCache && (options.nameCache.vars || {}),
eval: false,
- ie8: false,
+ ie: false,
keep_fnames: false,
properties: false,
reserved: [],
diff --git a/lib/output.js b/lib/output.js
index c57ff2ed..afc89055 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -56,7 +56,7 @@ function OutputStream(options) {
braces : false,
comments : false,
galio : false,
- ie8 : false,
+ ie : false,
indent_level : 4,
indent_start : 0,
inline_script : true,
@@ -193,7 +193,7 @@ function OutputStream(options) {
case "\t": return "\\t";
case "\b": return "\\b";
case "\f": return "\\f";
- case "\x0B": return options.ie8 ? "\\x0B" : "\\v";
+ case "\x0B": return options.ie ? "\\x0B" : "\\v";
case "\u2028": return "\\u2028";
case "\u2029": return "\\u2029";
case "\ufeff": return "\\ufeff";
@@ -1290,7 +1290,7 @@ function OutputStream(options) {
function make_then(self, output) {
var b = self.body;
if (output.option("braces") && !(b instanceof AST_Const || b instanceof AST_Let)
- || output.option("ie8") && b instanceof AST_Do)
+ || output.option("ie") && b instanceof AST_Do)
return make_block(b, output);
// The squeezer replaces "block"-s that contain only a single
// statement with the statement itself; technically, the AST
@@ -1515,7 +1515,7 @@ function OutputStream(options) {
var expr = self.expression;
expr.print(output);
var prop = self.property;
- if (output.option("ie8") && RESERVED_WORDS[prop]) {
+ if (output.option("ie") && RESERVED_WORDS[prop]) {
output.print(self.optional ? "?.[" : "[");
output.add_mapping(self.end);
output.print_string(prop);
@@ -1702,7 +1702,7 @@ function OutputStream(options) {
var quote = self.start && self.start.quote;
if (self.private) {
output.print_name(key);
- } else if (RESERVED_WORDS[key] ? !output.option("ie8") : is_identifier_string(key)) {
+ } else if (RESERVED_WORDS[key] ? !output.option("ie") : is_identifier_string(key)) {
if (quote && output.option("keep_quoted_props")) {
output.print_string(key, quote);
} else {
diff --git a/lib/scope.js b/lib/scope.js
index 3de59b99..2219b89a 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -118,7 +118,7 @@ function is_lhs(node, parent) {
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
options = defaults(options, {
cache: null,
- ie8: false,
+ ie: false,
});
// pass 1: setup scope chaining and handle definitions
@@ -211,7 +211,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
entangle(defun, scope);
} else if (node instanceof AST_SymbolLambda) {
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
- if (options.ie8) def.defun = defun.parent_scope.resolve();
+ if (options.ie) def.defun = defun.parent_scope.resolve();
} else if (node instanceof AST_SymbolLet) {
var def = scope.def_variable(node);
if (exported) def.exported = true;
@@ -351,7 +351,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
self.walk(tw);
// pass 3: fix up any scoping issue with IE8
- if (options.ie8) self.walk(new TreeWalker(function(node) {
+ if (options.ie) self.walk(new TreeWalker(function(node) {
if (node instanceof AST_SymbolCatch) {
var scope = node.thedef.defun;
if (scope.name instanceof AST_SymbolLambda && scope.name.name == node.name) {
@@ -572,7 +572,7 @@ AST_Symbol.DEFMETHOD("definition", function() {
function _default_mangler_options(options) {
options = defaults(options, {
eval : false,
- ie8 : false,
+ ie : false,
keep_fnames : false,
reserved : [],
toplevel : false,