-
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
Keep fparens #1371
Keep fparens #1371
Conversation
Hmmm... not really sure if relying on AST_Node.start is a good idea, especially given the lack of tests we have (I didn't saw many mocha tests on this and mocha tests are relative new) on them and the likelihood of AST_Node.start not being consistent. |
There is some guarantee that this code will work if these code involving tokens got locked into tests. |
@@ -69,6 +69,7 @@ function OutputStream(options) { | |||
quote_style : 0, | |||
keep_quoted_props: false, | |||
wrap_iife : false, | |||
keep_fparens : 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.
add trailing comma
describe("Keep wrapping parentheses", function() { | ||
it("Should keep wrapping parentheses if keep-fparens option is turned on", function() { | ||
var originalCode = "define(\"module\",(function() {module.exports = 42;}));"; | ||
var expectedCode = "define(\"module\",(function(){module.exports=42}));"; |
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.
use outer single quoted string to avoid need for escaping
|
||
it("Should strip wrapping parentheses if keep-fparens option is turned off or not set", function() { | ||
var originalCode = "define(\"module\",(function() {module.exports = 42;}));"; | ||
var expectedCode = "define(\"module\",function(){module.exports=42});"; |
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.
use outer single quoted string to avoid need for escaping
Something to be aware of - this PR would not work for Crockford style IIFEs:
PR would also need to update README. |
if (output.option('keep_fparens')) { | ||
if (this.start && this.start instanceof AST_Token && this.start.value === '(' && | ||
this.end && this.end instanceof AST_Token && this.end.value === ')') { | ||
return 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.
indent by 4
Hmm.. not sure how much this test overlaps with this issue. UglifyJS seems to be struggling on this test: https://github.com/tc39/test262/blob/master/test/language/statements/variable/fn-name-cover.js |
I would prefer looking data gathering on parser level personally. Then store that data in the AST tree. |
avdg, do you mean the approach like:
right? |
avdg, smth like that while parsing:
|
yeah, that would be more stable long term I believe. The only obstacle would be implementation. If that fails (preferably the parser still needs to be fast, but that should be possible if the checks are simple as it is the case now), we can stick to this method for now I guess... |
Don't forget to update the AST definitions when adding properties here: https://github.com/mishoo/UglifyJS2/blob/master/lib/ast.js |
Ok, i'll take this approach then. Thanks! |
Use snake_case rather than camelCase for data members.
|
kzc, ok, thanx! will pay attention to all code-style issues |
This does basically the same as proposed in #1307
Main benefit of this implementation is that it allows you to keep parentheses where you want,
without wrapping every function. So to wrap or not to wrap is up to user.