-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ES6] fix safari syntax error - declare twice #1851
Conversation
lib/scope.js
Outdated
@@ -122,6 +122,14 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ | |||
scope.uses_eval = save_scope.uses_eval; | |||
scope.directives = save_scope.directives; | |||
} | |||
// issue 1753 - name mangling in for loop scope should consider parent scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention:
// Safari/Webkit bug workaround - loop init let variable shadowing argument.
For bonus points if you have the webkit bug URL, please add it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "issue 1753" please include complete URL of issue:
// https://github.com/mishoo/UglifyJS2/issues/1753
With this PR:
|
If I understand correctly, this PR:
I'd prefer this special workaround to be gated by a new flag similar Please refer to the existing |
@alexlamsl I have the same concerns. Also, I don't see any code specific to function arguments and let/const variables which is apparently the source of the problem. I'd also like to see a reference to the Safari/WebKit bug to understand the true nature of the issue. The Safari/WebKit bug does not appear to be well understood. |
7e16b9c
to
0d3f94c
Compare
First of all, thanks to fast and specific reviews. @kzc I edited comments like you wrote. Codes you wrote doesn't occur error on Safari10(OSX). @alexlamsl I tried to deal with this issue by editing only I just added flag |
Putting aside where the logic should reside, the latest changes still doesn't look right because Also note that |
@Perlmint Thanks for including the Webkit bug link: |
Want this PR |
@alexlamsl Thanks to precise comment. I just committed fixed one. I'm sorry to late response. but My macbook was broken, I couldn't work fewdays. |
@Perlmint no worries and take your time 😉 I think you need to rebase this PR before pushing those changes, as it is currently still based on 2.x and I can't merge at all due to conflicts. |
lib/compress.js
Outdated
pure_getters : !false_by_default && "strict", | ||
pure_funcs : null, | ||
reduce_vars : !false_by_default, | ||
support_safari10 : true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change support_safari10
to safari10
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and revert all the row formatting of options unrelated to this PR.
lib/scope.js
Outdated
// 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 | ||
// related webkit bug ticket: https://bugs.webkit.org/show_bug.cgi?id=171041 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change line above to simply:
// https://bugs.webkit.org/show_bug.cgi?id=171041
@alexlamsl rebased. |
bin/uglifyjs
Outdated
@@ -35,6 +35,7 @@ program.option("--comments [filter]", "Preserve copyright comments in the output | |||
program.option("--config-file <file>", "Read minify() options from JSON file."); | |||
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define")); | |||
program.option("--ie8", "Support non-standard Internet Explorer 8."); | |||
program.option("--no-safari10", "Do not support Safari 10 by not applying patch about For loop related scope issue.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--safari10
?
lib/minify.js
Outdated
@@ -17,7 +17,7 @@ function read_source_map(code) { | |||
} | |||
|
|||
function set_shorthand(name, options, keys) { | |||
if (options[name]) { | |||
if (options[name] != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for changing this?
lib/minify.js
Outdated
@@ -36,6 +36,7 @@ function minify(files, options) { | |||
options = defaults(options, { | |||
compress: {}, | |||
ie8: false, | |||
safari10: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default should be false
, just like ie8
. These are special case options, so don't force it upon everyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought that safari10 option should be enabled default because it is latest version. so I made changes -you commented previous- in same reason.
if default should be false
, other changes are also not needed.
I'll change it to false
lib/minify.js
Outdated
@@ -46,6 +47,7 @@ function minify(files, options) { | |||
wrap: false, | |||
}, true); | |||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]); | |||
set_shorthand("safari10", options, [ "mangle" ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, why should it even be a toplevel option, if only mangle
is affected?
Just keep it under options.mangle.safari10
for now. If it turns out Safari becomes the next IE6 in terms of quirks, we can add a toplevel option then. Right now it just add noise to the global namespace.
lib/scope.js
Outdated
// Safari/Webkit bug workaround - loop init let variable shadowing argument. | ||
// https://github.com/mishoo/UglifyJS2/issues/1753 | ||
// related webkit bug ticket: https://bugs.webkit.org/show_bug.cgi?id=171041 | ||
if (node instanceof AST_For || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap this if
with:
if (options.safari10) {
...
}
lib/scope.js
Outdated
@@ -122,6 +124,14 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ | |||
scope.uses_eval = save_scope.uses_eval; | |||
scope.directives = save_scope.directives; | |||
} | |||
// Safari/Webkit bug workaround - loop init let variable shadowing argument. | |||
// https://github.com/mishoo/UglifyJS2/issues/1753 | |||
// related webkit bug ticket: https://bugs.webkit.org/show_bug.cgi?id=171041 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this 3 line comment here as it's repeated below.
cbd14d6
to
9621b0c
Compare
Edit: sorry I missed your latest commits - it looks fine now 👍 |
Even without understanding the fine points, all the code is behind LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more minor nits, and we are good to go!
lib/minify.js
Outdated
@@ -54,6 +54,7 @@ function minify(files, options) { | |||
cache: null, | |||
eval: false, | |||
ie8: false, | |||
safari10: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this down above toplevel
so as to keep this section in alphabetical order?
lib/scope.js
Outdated
@@ -102,6 +102,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ | |||
options = defaults(options, { | |||
cache: null, | |||
ie8: false, | |||
safari10: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comma here so as to minimise diff in future expansions.
@alexlamsl fixed! Thanks. |
lib/minify.js
Outdated
@@ -58,6 +58,7 @@ function minify(files, options) { | |||
properties: false, | |||
reserved: [], | |||
toplevel: false, | |||
safari10: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above, not below... 😅
Between reserved
and toplevel
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... sorry. I'll fix it now.
lib/scope.js
Outdated
if (options.safari10) { | ||
if (node instanceof AST_For || | ||
node instanceof AST_ForIn || | ||
node instanceof AST_ForOf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since:
var AST_ForOf = DEFNODE("ForOf", null, {
$documentation: "A `for ... of` statement",
}, AST_ForIn);
you can remove the AST_ForOf
condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the if
can be a single line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, suggest merging two if statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer keeping the if (options.safari10)
separate to better show that code is definitely not run if the option is not in effect without any thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a big fan of not thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Perlmint Thank you for contributing this patch and your patience in this review exercise. |
fix mishoo#1753. to mangle names properly - to avoid safari error, scope of for loop should enclose parent scope variables
@kzc looks better. Thanks. |
@alexlamsl @kzc @Perlmint quick question guys.. |
The Safari 10 loop bug workaround is disabled by default:
Safari 10 loop bug workaround enabled:
|
* Build: Add work-around for safari 10 let bug See mishoo/UglifyJS#1851 * Add the mangle option to the right minifier. Remove the redundant one. * change the opt extension to min to cache break the uglify change
Hi everyone, can I ask why this option was not enabled by default? |
is this fix apply on master branch ? |
fix issue #1753
by enclosing variables of parent scope, avoid safari error.