-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 helper dependencies in babel runtime #6379
Fix helper dependencies in babel runtime #6379
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5405/ |
24cc237
to
539cfdd
Compare
@@ -1,7 +0,0 @@ | |||
var _Array$from = require("../core-js/array/from"); |
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 think it's helpful to have helpers that test this core-js injection behavior. Why don't we leave the toArray helper and just add the temporalRef one as well.
} | ||
|
||
addHelper(name: string): Object { | ||
const { declaration, reference } = this._loadHelper( |
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.
It seems like it has gotten pretty complicated in here.
This commit updates the getDependency callback passed to helpers.get(). That callback only used to return an Identifier or MemberExpression which represents the helper; now it can return both the reference and the code of the dependency
This is the primary reason for these changes, is that right?
Having the helpers.get
function return the dependencies too seems like it adds a lot of complexity to this logic and I'm not sure what is driving that change. Could you expand on that to help the discussion?
I'm wondering if we'd be better off changing the helper API into two parts, along the lines of a .getGraph(name: string)
that would return a list of all the dependencies with the expectation that if you need to insert the dependencies, you'd do
helpers.getGraph(name).forEach(helper => helpers.get(...
That way generating an individual helper can just assume that your getDependency
callback will always point at something that has already been inserted.
Thoughts?
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.
It seems like I have the tendency to make things way more complex than needed 😅
While writing an answer to your comment I realized that there was no reason to make the helpers.get
function inject the dependencies in the helper.
edcc3a8
to
f61944a
Compare
f61944a
to
e13d1ae
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.
One small comment to fix, but otherwise looks good to me.
packages/babel-helpers/src/index.js
Outdated
return loadHelper(name).build(getDependency, id, localBindings); | ||
} | ||
|
||
export function getDependencies(name: string): IterableIterator<string> { |
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.
How do you feel about exposing iterables as part of a public API? To me, I'd prefer to stick with an Array to make life easier for consumers still, so I'd vote to wrap this with Array.from()
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 was in doubt because just returing the iterable is faster than doing iterable -> array -> iterable
, but probably it can't be noticed since it is only run once per helper (premature optimizations 🚀 🤣)
e13d1ae
to
a3dd650
Compare
a3dd650
to
a740b28
Compare
Fixes #1, Fixes #2
I promise this will be the last iteration of helper dependencies 😆
Commit message:This PR extracts the handling of dependencies out of
babel-helpers/src/index.js
. That file now exports agetDependencies
function which returns a list containing the name of the dependencies used by an helper. It's up to the consumer to ensure that they are already available when the helper is included.This PR fixes a bug regarding the transpilation of imports inside babel-runtime.
Ref: #6366 (comment)