What do we need to make usage-global
injection work with @babel/runtime
?
#16391
Labels
usage-global
injection work with @babel/runtime
?
#16391
馃捇
What problem are you trying to solve?
@nyngwang has been going around a bit checking how our polyfill injection works (thank you very much!), and after going through their comments I realized that our injection story for
usage-global
is pretty bad when it comes to helpers.If you have this config:
Babel will inject imports for helpers like
import _typeof from "@babel/runtime/helpers/typeof"
.Then you decide that you want to inject global polyfills through
core-js
, so you update your config to this:now Babel will inject imports like
import "core-js/modules/es.array.flat.js";
, but suddently your imports for helpers will becomeimport "@babel/runtime-corejs3/helpers/typeof"
(which depends oncore-js-pure
). This is to make sure that the helpers are also polyfilled, but:core-js
andcore-js-pure
If you still want to use
@babel/runtime
(because@babel/runtime-corejs3
includes polyfills down to ES5), you have to instead use this config:Describe the solution you'd like
What if for each helper we maintained the list of built-ins that it relies on, and when injecting a
import "@babel/runtime/typeof/helpers"
we called the polyfill provider saying "hey, we included a helper that usesSymbol
andArray.prototype.flat
: if needed for the configured target, consider injecting imports to these polyfills".Then, when compiling
typeof foo
and using["babel-plugin-polyfill-corejs3", { "method": "usage-global" }]
, we would generate some code likerather than
This list would probably need to be manually-maintained by us for each helper, and:
@babel/runtime
versionsDescribe alternatives you've considered
Do nothing
Documentation, Adoption, Migration Strategy
No response
The text was updated successfully, but these errors were encountered: