Skip to content

Commit

Permalink
fix safari syntax error - decalring twice
Browse files Browse the repository at this point in the history
fix mishoo#1753.
to mangle names properly - to avoid safari error, scope of for loop should enclose parent scope variables
  • Loading branch information
Perlmint committed May 11, 2017
1 parent e2888bd commit 9f50a12
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
var in_destructuring = null;
var in_export = false;
var in_block = 0;
var for_scopes = [];
var tw = new TreeWalker(function(node, descend){
if (node.is_block_scope()) {
var save_scope = scope;
Expand All @@ -122,6 +123,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
scope.uses_eval = save_scope.uses_eval;
scope.directives = save_scope.directives;
}
if (options.safari10) {
if (node instanceof AST_For ||
node instanceof AST_ForIn ||
node instanceof AST_ForOf) {
for_scopes.push(scope);
}
}
descend();
scope = save_scope;
return true;
Expand Down Expand Up @@ -303,6 +311,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) {
this.cname = options.cache.cname;
}
Expand Down

0 comments on commit 9f50a12

Please sign in to comment.