-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc(build): fix mangling for tap-targets gatherer #11463
Conversation
getRectCenterPoint, | ||
getLargestRect, | ||
} = require('../../../lib/rect-helpers.js'); | ||
const RectHelpers = require('../../../lib/rect-helpers.js'); |
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.
This is how all other gatherers import this module. Only this one did destructuring, which results in the reference to getRectCenterPoint
in the "page function" below to (lexically) check out. but lexical scope is a damned lie 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.
Ah, so I found this confusing, because obviously it has to be in scope to be able to toString()
it, at which point it'll also be in scope on the browser side. The issue is the combo with keep_fnames: true
.
-
Destructuring ends up looking something like
{getRectCenterPoint: o} = e("../../../lib/rect-helpers.js")
sincegetRectCenterPoint
wasn't renamed as a function, but as a local variable terser thinks it can be renamed. -
o.toString
gives a function with the original name ('function getRectCenterPoint() {...}'
), though, so when code tries to callo()
it throws an error
Ideally we could eventually go the opposite way of this, having the toString()
and the function calls match, as that would let us do keep_fnames: false
and save 30KiB.
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 we add a smoketest to test-bundle
that ensures no audits throw an exception? seems like it would've been good to not have to manually catch this (and for future changes to bundlification)
I'm confused–our smoke testing doesn't support this. What do you mean? We could just run all the smoke tests instead of the subset we do. If just one of them asserts on |
Sure it does,
That works too. Just seems important to increase test coverage of our bundle as we increasingly do more things to it |
${getLargestRect.toString()}; | ||
${getRectCenterPoint.toString()}; | ||
${rectContains.toString()}; | ||
${RectHelpers.getRectArea.toString()}; |
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.
Nit: Can we remove these unused RectHelpers functions? Looks like only getRectCenterPoint() is used so the others aren't needed.
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.
nice catch
This seems really important, since it's not going to be obvious that writing normal JS might break when minified (same for the fix needed in d657e76). Since we're going all in on minification, it does seem like turning on all smoke tests for the bundle is necessary now.
But not caught in the devtools smoke tests, right? |
I'll open a PR now that runs every smoke test on the bundle.
Sorry, that was very vague, I updated the first comment. |
When minified for CDT, the tap-targets gatherer fails.
yarn test-devtools
didn't catch it because there is no layout test that exercise that particular code path in the page. Running it on other pages showed the problem. (yarn open-devtools
is so useful)overloading variables between Node/page-function contexts is bad, it causes tooling to make mistakes.