Skip to content

Hoist functions when reversing if (x) return; ... vs. if (!x) ...#1053

Merged
mishoo merged 3 commits intomishoo:masterfrom
rvanvelzen:hoist_if_return_funs
Apr 26, 2016
Merged

Hoist functions when reversing if (x) return; ... vs. if (!x) ...#1053
mishoo merged 3 commits intomishoo:masterfrom
rvanvelzen:hoist_if_return_funs

Conversation

@rvanvelzen
Copy link
Copy Markdown
Collaborator

Fixes #1052

@mgol
Copy link
Copy Markdown
Contributor

mgol commented Apr 25, 2016

This PR unbreaks the jQuery code I mentioned #1052 and adds only 6 bytes gzipped, looks good to me from that perspective. 👍

@gibson042 you had some doubts about this approach, could you elaborate?

@mgol
Copy link
Copy Markdown
Contributor

mgol commented Apr 25, 2016

Actually, as @kzc pointed out in jquery/jquery#3075 (comment), it'd be good to have test cases with a single function declaration as well as then the braces are stripped which may result in a different output.

Could you add such test cases?

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 25, 2016

@mgol Actually my point was that uglify's parser is not nearly as strict as a full-fledged JS linter, and generally would not be able to catch errors in parsing its own output. An independent parser would be better to validate the output.

$ echo '"use strict";!function(){if(window)function i(){}}();' | uglifyjs | uglifyjs 
"use strict";!function(){if(window)function i(){}}();

Just to be clear are you asking for an uglify parser change to fail the parse if functions are declared within blocks of statements? If so, a new issue should be opened for that.

@mgol
Copy link
Copy Markdown
Contributor

mgol commented Apr 26, 2016

@kzc I meand that I'd like another test case where the original source has only one function declarations to make sure that it's not converted to if(!sth)function f(){}. With two functions braces couldn't have been lost so it might be behaving differently.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Apr 26, 2016

PR looks good to me.

@mgol
Copy link
Copy Markdown
Contributor

mgol commented Apr 26, 2016

LGTM!

@mishoo mishoo merged commit 65887d9 into mishoo:master Apr 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants