fix safari syntax error - decalring twice
fix #1753. to mangle names properly - to avoid safari error, scope of for loop should enclose parent scope variables
This commit is contained in:
parent
e2888bdc43
commit
c31fec7177
19
lib/scope.js
19
lib/scope.js
|
|
@ -112,6 +112,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
var in_destructuring = null;
|
var in_destructuring = null;
|
||||||
var in_export = false;
|
var in_export = false;
|
||||||
var in_block = 0;
|
var in_block = 0;
|
||||||
|
var for_scopes = [];
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node.is_block_scope()) {
|
if (node.is_block_scope()) {
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
|
|
@ -122,6 +123,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
scope.uses_eval = save_scope.uses_eval;
|
scope.uses_eval = save_scope.uses_eval;
|
||||||
scope.directives = save_scope.directives;
|
scope.directives = save_scope.directives;
|
||||||
}
|
}
|
||||||
|
if (options.safari10) {
|
||||||
|
if (node instanceof AST_For || node instanceof AST_ForIn) {
|
||||||
|
for_scopes.push(scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -303,6 +309,19 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pass 4: add symbol definitions to loop scopes
|
||||||
|
// Safari/Webkit bug workaround - loop init let variable shadowing argument.
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/1753
|
||||||
|
// https://bugs.webkit.org/show_bug.cgi?id=171041
|
||||||
|
if (options.safari10) {
|
||||||
|
for (var i = 0; i < for_scopes.length; i++) {
|
||||||
|
var scope = for_scopes[i];
|
||||||
|
scope.parent_scope.variables.each(function(def) {
|
||||||
|
push_uniq(scope.enclosed, def);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.cname = options.cache.cname;
|
this.cname = options.cache.cname;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user