-
Notifications
You must be signed in to change notification settings - Fork 103
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
Webpack-specific fix for issue #7 #33
Conversation
…dds ability to wrap functions that are elements of an array literal in an argument list
…ack patterns rather than all array literal function parameters.
I tend to agree that this is a better fix! I prefer targeted solutions that look for existing patterns (e.g. Webpack) because that increases the likelihood that we will add parentheses where it really matters, and not just willy-nilly for any function in the code. I'd be happy to merge this in favor of #28. BTW I have merged #31 because I wanted to get ES6 support in, but unfortunately it seems to cause merge conflicts with the other PRs. 😕 So perhaps I was too hasty to merge. What do you think is the best course moving forward? Should I have chosen another es-walker library or would it not be too much work to merge your fixes into the new master? |
Glancing at the changes, I think it shouldn't be too hard to merge in, but those are famous last words. The key is going to be if estree-walker and walk-ast produce significantly different ASTs in any real way. Let me give it a stab. |
…e from walk-ast to estree-walker
Updated! The only wacky part was that All tests pass, including several new negative test cases, and coverage is still 100%. (And as an added enticement to merge, I have a branch on top of this waiting in the wings which implements a browserify-specific solution to #29. ;) ) |
// estree-walker does not follow the link. | ||
node.parent = function () { | ||
return parent | ||
} |
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.
agree this is a weird hack, but at least you marked it as such and added a lot of explanation :)
node.parent().parent() && // CallExpression | ||
node.parent().parent().callee && // function that is being called | ||
node.parent().parent().callee.type === 'FunctionExpression' | ||
} |
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.
love the name of this function! 😂
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.
@aickin you're a legend; this is a great PR and I especially love the new test cases. I was worried that the change to estree-walker would add a lot of headaches, but it seems we're all good for the most part. Very happy to merge this.
BTW @aickin I've gone ahead and made you a contributor to optimize-js so you have the power to merge PRs, commit to master, etc. My typical policy is to wait for at least one other contributor to +1 a PR, but if you don't get a response within 24 hours or so feel free to timebomb and merge it yourself. Your Webpack-specific fixes are awesome, and what I'd like to do next is:
|
Awesome, thanks for both the invite and the clear guidance on how it is to be used! I've posted the browserify fix as PR #36. Have at it! As for the benchmark, I agree that it should be re-run, but I have some concerns that it may not be entirely fair to unoptimized code. I wrote those concerns up as issue #37. Let me know what you think. Onwards! |
This is a more webpack-specific fix for issue #7 than the solution presented in PR #28. Rather than optimize every function expression that is an element of an array literal param, this PR only optimizes function expressions that are elements of an array literal param of a function expression call.
So, unlike PR #28, this PR will not transform this code:
because
foo
is not a function expression.I think that this version is probably better than PR #28, but I'm happy to hear dissenting views!