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
Create File class for babel helpers #10575
Conversation
packages/babel-helpers/src/index.js
Outdated
const ast = t.file(helper.ast()); | ||
return new File( | ||
{ | ||
filename: `babel-helper://${name}`, |
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.
babel-helper://
is used to denote that this file is a babel helper snippet thus does not physically exist.
packages/babel-helpers/package.json
Outdated
@@ -17,5 +17,8 @@ | |||
}, | |||
"devDependencies": { | |||
"@babel/helper-plugin-test-runner": "^7.0.0" | |||
}, | |||
"peerDependencies": { | |||
"@babel/core": "^7.0.0-0" |
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.
Adding (or updating) a peer dependency is a technically a breaking change. (semver/semver#502)
Maybe we could pass File
as a parameter to loadHelper
(from get
and ensure
), and only instantiate it if it is present?
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.
Good to know about that! Though I am not sure if, practically, there is anyone using @babel/helpers
7 with babel-core
6.
I end up revising helpers.ensure
to accept extra fileClass
because get
interface is complicated enough.
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.
Dependency injection feels hacky, at least in this case, but probably the only @babel/helper
direct users are us 😛
d7f76e3
to
e9111ff
Compare
* add test * fix: pass File to helper traverser * pass babel.File to helpers.ensure
e9111ff
to
2886e1e
Compare
In this PR we create a
File
instance for each helper snippets, by doing so we can ensure other visitors will have access to.hub
when visiting the inserted nodes from helpers.