-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
[BUGFIX release] Fix uglification introduced bug with super wrapping. #12463
Conversation
Lgtm |
LGTM. The test will fail on platforms that don't support |
We could add a phantomjs detection to https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/environment.js#L27-L28, and wrap the test in a Thoughts? |
We check to see if a function contains `_super` / `.call` / `.apply` before attempting to super wrap a given method (this saves quite a bit of extra super wrapping for functions that do not need it). Unfortunately, a number of platforms that we support do not support calling `func.toString()` so we attempt to detect this and fall back to always super wrap everything mode. We have roughly this code (from [here](https://github.com/emberjs/ember.js/blob/b4718218dbe5ffe7736c485a594248b20977c621/packages/ember-metal/lib/utils.js#L257-L271)) to detect if we can call `toString()` and get the original source: ```javascript let sourceAvailable = (function() { return this; }).toString().indexOf('return this;') > -1; ``` This works perfectly for development builds, but unfortunately not when minified. Take a look at the minified source and you will see why: ```javascript var e=function(){return this}.toString().indexOf("return this;")>-1; ``` Note that minifier has stripped the trailing semicolon from the function body we are attempting to check against, but sadly our `indexOf` check still contains the semicolon! **tldr;** We super wrap every function in uglified builds. --- This commit removes the trailing semicolon from the source check, and adds a test that should hopefully allow us to detect if this is accidentally reintroduced.
7938a56
to
7894cae
Compare
Added the phantomjs check I mentioned above, the test suite should now continue to pass even on platforms that do not support function source. |
👍 |
[BUGFIX release] Fix uglification introduced bug with super wrapping.
Awesome, thanks! |
this is likely going to be a nice little perf post, since i suppose we where super wrapping many more things before. |
We check to see if a function contains
_super
/.call
/.apply
before attempting to super wrap a given method (this saves quite a bit of extra super wrapping for functions that do not need it). Unfortunately, a number of platforms that we support do not support callingfunc.toString()
so we attempt to detect this and fall back to always super wrap everything mode.We have roughly this code (from here) to detect if we can call
toString()
and get the original source:This works perfectly for development builds, but unfortunately not when minified. Take a look at the minified source and you will see why:
Note that minifier has stripped the trailing semicolon from the function body we are attempting to check against, but sadly our
indexOf
check still contains the semicolon!tldr; We super wrap every function in uglified builds.
This commit removes the trailing semicolon from the source check, and adds a test that should hopefully allow us to detect if this is accidentally reintroduced.
Fixes #12462.