feat(transform-object-rest-spread): add polyfill=false option to avoid extends helper#3327
Conversation
Current coverage is
|
| } | ||
| ``` | ||
|
|
||
| This plugin will polyfill `Object.assign` by default. If you want to prevent that use config this |
There was a problem hiding this comment.
use a config like this instead or something else like that
There was a problem hiding this comment.
Hi @hzoo, thanks for your comment, I'm not exactly following though, how would you like it to read? Thanks :)
There was a problem hiding this comment.
Was just saying maybe If you want to prevent that use config this instead:
could be something like If you want to prevent that use a config like this instead
|
Are there other transforms that could take this option as well? cc @amasad thoughts? Sounds fine to me |
|
I think the use of polyfill here is confusing. Polyfill usually means that we are extending builtins which is not the case here, we are just using a babel helper. How about changing the wording and the option to |
|
Ok, and do we want to be more general like |
|
I'm not crazy about const helper = file.opts.useNative && file.opts.useNative.objectAssign ?
t.memberExpression(t.identifier('Object'), t.identifier('assign')) :
file.addHelper("extends"); |
|
+1 for |
|
I'm ok with any of those. Being more specific feels definitely much better
|
|
That would be #3331 - we would still do the option per plugin though |
|
Good stuff! Want me to update the PR accordingly then? |
|
Maybe we can get some more opinions @loganfsmyth? Sounds like either Although we can always override it later so you can do both? I say just |
I hear you 😃 I thought we should consider what might be the case in other plugins before deciding what to do here, since the point of the name change is to generalize it for all plugins. Personally it wouldn't bother me to be more explicit + future proof, but if you all don't think that's likely to be an issue, that's cool. And as you noted @hzoo, yep, there's an escape hatch if it turns out to be necessary:
|
|
|
||
| path.replaceWith(t.callExpression(file.addHelper("extends"), args)); | ||
| const helper = file.opts.polyfill === false ? | ||
| t.memberExpression(t.identifier('Object'), t.identifier('assign')) : |
|
I'd be in favor of |
|
ping @dariocravero - if you're busy I can finish up the changes |
|
Although now that I look at the helper.. it already checks for Object.assign? babel/packages/babel-helpers/src/helpers.js Lines 167 to 179 in 93e5c0e Or do you just not want to include the helper, since this option doesn't seem necessary then? |
| } | ||
|
|
||
| path.replaceWith(t.callExpression(file.addHelper("extends"), args)); | ||
| const helper = file.opts.polyfill === false ? |
There was a problem hiding this comment.
Can we make this throw if it is passed the wrong type? E.g.
if (polyfill === undefined) polyfill = true;
if (typeof polyfill !== 'boolean') throw new Error
|
Moving to #4491 since I can't modify this PR |
This PR follows the same spirit of transform-runtime and allows a user to use
Object.assigndirectly instead of theextendshelper.EDIT by @hzoo: referenced issue is #3934