From c31fec71778d2ad137ebf779c4a08bcc17a74fec Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Fri, 28 Apr 2017 14:26:46 +0900 Subject: [PATCH] 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 --- lib/scope.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/scope.js b/lib/scope.js index fc63f51d..ed69bef7 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -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; @@ -122,6 +123,11 @@ 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) { + for_scopes.push(scope); + } + } descend(); scope = save_scope; 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) { this.cname = options.cache.cname; }