fix(require): interop with destructuring transform / preset-env #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
require()
destructuring becomes broken if usingpreset-env
when it transforms the destructure. Would also be a factor if anyone usedplugin-transform-destructuring
on its own and put it beforemacros
.Why:
The
transform-destructuring
Babel plugin uses theVariableDeclaration
visitor which comes beforeCallExpression
. So by the timemacros
got to therequire
call it had already been transformed and was no longer a properrequire()
, leading to the previously fixed 'cannot read propertyreferencePaths
of undefined' error.How:
To fix it we have to also use
VariableDeclaration
– plugin visitors are added before presets', sopreset-env
will also now work correctly.@kentcdodds FYI I'm also planning to do a separate PR to fix handling of macros that use ESM to do
export default createMacro(...)
rather thanmodule.exports = createMacro(...)
.