Skip to content
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

fix(require): interop with destructuring transform / preset-env #51

Merged
merged 1 commit into from
Jan 27, 2018
Merged

fix(require): interop with destructuring transform / preset-env #51

merged 1 commit into from
Jan 27, 2018

Conversation

haltcase
Copy link
Collaborator

What:

require() destructuring becomes broken if using preset-env when it transforms the destructure. Would also be a factor if anyone used plugin-transform-destructuring on its own and put it before macros.

Why:

The transform-destructuring Babel plugin uses the VariableDeclaration visitor which comes before CallExpression. So by the time macros got to the require call it had already been transformed and was no longer a proper require(), leading to the previously fixed 'cannot read property referencePaths of undefined' error.

How:

To fix it we have to also use VariableDeclaration – plugin visitors are added before presets', so preset-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 than module.exports = createMacro(...).

The `transform-destructuring` Babel plugin uses the `VariableDeclaration`
visitor which comes before `CallExpression`. So by the time `macros` got
to the `require` call it has already been transformed and no longer looks
like a `require`. Use `VariableDeclaration` to fix.
@codecov
Copy link

codecov bot commented Jan 27, 2018

Codecov Report

Merging #51 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #51   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          73     74    +1     
  Branches       18     17    -1     
=====================================
+ Hits           73     74    +1
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9438118...a9ddcc1. Read the comment docs.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful!

@kentcdodds kentcdodds merged commit ec116e4 into kentcdodds:master Jan 27, 2018
@kentcdodds
Copy link
Owner

Thanks!

@kentcdodds
Copy link
Owner

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@haltcase haltcase deleted the fix-env-destructure branch January 27, 2018 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants