-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: throw error when targets are used with regenerator #119
feat: throw error when targets are used with regenerator #119
Conversation
1dc84e6
to
ab4cd85
Compare
@agilgur5 I was thinking that we could just completely remove the We would still need a way to pass it as an internal API to the |
As a shorter term solution (that one is a bigger breakig change), we can modify the check like this: export default defineProvider(({ debug, targets, babel }, options) => {
if (!shallowEqual(targets, babel.targets())) {
throw new Error(
"This plugin does not use the targets option. Only preset-env's targets" +
" or top-level targets need to be configured for this plugin to work." +
" See https://github.com/babel/babel-polyfills/issues/36 for more" +
" details",
);
} where This doesn't catch the case where you explicitly specify the same top-level targets and plugin targets, but it catches the "common error" which is to specify only plugin-level targets (thus not using top-level targets). |
ab4cd85
to
c279f77
Compare
- the polyfill-regenerator plugin actually does not support targets and does not use them - it instead detects whether the `regeneratorRuntime` variable has been injected by `transform-regenerator`, which already supports targets - so targets are not needed twice in that sense - instead of silently ignoring the targets option, error out when it is given as it is an unsupported option - this should hopefully make it easier for developers to realize what's going on when debugging issues with this (as I did) - but it shouldn't error if top-level targets are configured, as those aren't specific to this plugin - caveat: if a user specifies both and they are the same, there's currently no way to tell, so it won't error in that case - but will catch the common mistake - add a test for this new error as well as a basic "harness" based on the one in `define-polyfill-provider` - remove `targets` from any fixtures that had them for this polyfill so that this test passes - and because they didn't do anything previously anyway - also add a test that ensures that top-level targets still work - and change some fixtures to use top-level targets instead, ensuring that those fixture tests still pass as well
c279f77
to
e1760f0
Compare
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.
Rebased & updated with latest changes and added the shallow equality fix for top-level targets. Tests now pass!
@@ -39,3 +48,7 @@ export default defineProvider<Options>(({ debug }, options) => { | |||
|
|||
const isRegenerator = meta => | |||
meta.kind === "global" && meta.name === "regeneratorRuntime"; | |||
|
|||
function shallowEqual(obj1: any, obj2: any) { | |||
return JSON.stringify(obj1) === JSON.stringify(obj2); |
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 obviously a pretty naive implementation of shallow equality, but it has no deps and is very short. Let me know if that's okay or if you'd prefer something less naive
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.
I don't like it, but it's ok in this case since it's comparing very small serializable objects.
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.
Yep that was kind of my thought process too 👍 Equality algos can get bulky real fast, so kinda went with "smallest viable option" here
Thanks! |
Summary
adds an error when
polyfill-regenerator
is supplied withtargets
, as those are unsupported for this polyfill per #36Details
the
polyfill-regenerator
plugin actually does not support targets anddoes not use them
regeneratorRuntime
variable hasbeen injected by
transform-regenerator
, which already supportstargets
instead of silently ignoring the targets option, error out when it is
given as it is an unsupported option
what's going on when debugging issues with this (as I did)
add a test for this new error as well as a basic "harness" based on
the one in
define-polyfill-provider
targets
from any fixtures that had them for this polyfillso that this test passes
Review Notes
define-polyfill-provider
's error testing with a similaroptions.js
test fileReferences
Fixes #36