Conversation
f608dbb to
178ffb1
Compare
4e6beea to
3dbaa20
Compare
| getOwnPropertyDescriptors: "es7.object.get-own-property-descriptors", | ||
| assign: "es.object.assign", | ||
| create: "es.object.create", | ||
| defineProperty: "es.object.define-property", |
There was a problem hiding this comment.
I wonder; will, in core-js 3, it be possible to omit including the polyfill for this if your target does not include a browser that needs it?
Right now, in core-js 2, even if you don't include it via preset-env, it'll be overwhelmingly likely that whatever feature you do include the polyfill of will indirectly require the defineProperty polyfill.
It's true that it's safer that way, but it's unfortunate that you can't get significantly smaller code size even when you're specifically being unsafe by using this instead of just loading all of core-js.
There was a problem hiding this comment.
No, if any polyfill requires this logic - it will be added as an internal module. And it's about almost all fundamental ES5 features.
It's related this issue. You talk about the second option from this comment. It's not hard for implementation, but it will cause too many problems.
For example, Array#fill from the issue. It requires not just Object.defineProperty for adding this polyfill, but, for example, Object.create for adding Array#[@@unscopables] where should be the name of this method. Object.create depends on Object.defineProperties, Object.defineProperties depends on Object.getOwnPropertyNames, etc.
So for working es.array.fill in IE8 we should add all of those dependencies. It's critically hard to determinate this list for manual adding. It's not so critical for babel-preset-env, but the list of internal dependencies could be changed in core-js, for example, after fixing any engine bug and it could be a breaking change for babel-preset-env.
I wanted to propose this issue to discuss before core-js@4. And it's the main problem which can be some time solved by dropping IE8 support in core-js.
|
@zloirock this is looking great, mind if I regen and push the test fixtures so we can see the effects? |
|
@existentialism makes sense, I wanted to add some more changes and after that work on stabilisation and tests. |
7465532 to
9fd9e11
Compare
83e4d40 to
8347eb9
Compare
d6a53a8 to
36c8160
Compare
|
I meet the same error like: |
|
@suarasaur support of getters and setters can't be polyfilled or transpiled in IE8-, so you can't use it or use transforms which use it. Webpack use it for modules, so, in this case, I recommend to use |
36c8160 to
986d8f8
Compare
986d8f8 to
265d18d
Compare
bb06bc8 to
cdfc668
Compare
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10523/ |
- [x] ./available-plugins.js - [x] ./filter-items.js - [x] ./index.js - [x] ./get-option-specific-excludes.js - [x] ./debug.js - [x] ./types.js - [x] ./utils.js - [x] ./options.js - [x] ./targets-parser.js - [x] ./normalize-options.js - [x] ./module-transformations.js - [x] ./polyfills/regenerator/entry-plugin.js - [x] ./polyfills/regenerator/usage-plugin.js - [x] ./polyfills/corejs2/entry-plugin.js - [x] ./polyfills/corejs2/get-platform-specific-default.js - [x] ./polyfills/corejs2/built-in-definitions.js - [x] ./polyfills/corejs2/usage-plugin.js - [x] ./polyfills/corejs3/entry-plugin.js - [x] ./polyfills/corejs3/shipped-proposals.js - [x] ./polyfills/corejs3/built-in-definitions.js - [x] ./polyfills/corejs3/usage-plugin.js
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10531/ |
Current state:
@babel/runtime@babel/runtime-corejs3package andcorejs: 3options to@babel/plugin-transform-runtime.proposals(incorejs: { version: 3, proposals: true }format) for support all proposals polyfills fromcore-js.core-jsentry points with proposals and without.get-iterator-methodhelper for getting iterators, fixes When using babel-runtime, Symbol.iterator is different in user code & in polyfills #2500.regenerator).@babel/polyfillcore-jsandregenerator-runtimewith an informative message.@babel/preset-envcore-js-compatinstead ofcompat-tablesince information fromcompat-tableis not enough.useBuilInsnow requires direct setting ofcorejsversion option, without it will be used2by default and shown deprecation warning.core-jsversions for simplify updating in the future.core-js@3plugins added onpoststage in the order ofcore-js-compatdata.preset-env, instead of 2 internal plugins for adding polyfills, we have 6: usage and entry versions of plugins forcore-js@2,core-js@3,regenerator-runtime.samsungtarget (for Samsung Internet) sincecore-js-compatandcompat-tablenow contains mapping for this, fixes Add support for Samsung Internet browser #6602.useBuilIns: entrywithcorejs: 3@babel/polyfill.core-jsentry points to import of related modules (based on data fromcore-js-compat).shippedProposals/proposalsflags withuseBuilIns: entry.regenerator-runtime/runtimeimport where it's not required.useBuilIns: usagewithcorejs: 3shippedProposals, added flagproposals(incorejs: { version: 3, proposals: true }format) for polyfill all proposals fromcore-js.MemberExpression,ObjectPattern,inoperator.for-of, destructuring, spread,yielddelegation, etc.).core-js@2stuffI didn't want to tough
core-js@2-related stuff, howeverObject.getOwnPropertySymbols,Symbol.toStringTaglogic,Promise#finally,Array#forEach, etc.Array#flatMapand trim methods moved to stable features as a part of ES2019 and loaded by deprecated@babel/polyfilland@babel/preset-envwithcorejs: 2option.2018.12.30 Explanation of the current situation:
@babel/runtimeHere we have no serious problems.
@babel/runtime-corejs3package andcorejs: 3options to@babel/plugin-transform-runtime.get-iterator-methodhelper for getting iterators, fixes When using babel-runtime, Symbol.iterator is different in user code & in polyfills #2500.regenerator).Breaking changes
@babel/runtimecan be updated without any problems by adding@babel/runtime-corejs3package. But not@babel/polyfilland@babel/preset-env.Updating
@babel/polyfilltocore-js@3will break@babel/preset-env.@babel/preset-envwithuseBuiltInstransforms import of@babel/polyfillto import of requiredcore-jsmodules. Most users don't addcore-jsdependency directly. In case of a minor update, even if@babel/polyfilldependency will be updated with@babel/preset-env, in the top level ofnode_moduleswe will havecore-js@2, notcore-js@3because a serious part of dependencies depends on packages withcore-js@2in dependencies.Updating
@babel/preset-envwill cause the same problem. More other,@babel/preset-envtransforms also imports ofcore-js. If someone hascore-js@2in dependencies, a minor update of@babel/preset-envwill break it.Before
babel@7release, I proposed to deprecate@babel/polyfillin favor of separate inclusion ofcore-jsandregenerator-runtime, but it was not done.So,
Options for
@babel/polyfill:@babel/polyfill.@babel/polyfillpackage in favor recommendation of separate inclusion of required parts ofcore-jsandbabel-runtime.Options for
@babel/preset-env:@babel/preset-env.core-jslike in@babel/plugin-transform-runtime. I'm not a fan of this way, because in this case, we will use a deprecated version ofcore-jsby default, will cause spaghetti in configs and the code base and will cause problems for other mentioned here changes, at least, seepolyfilling of proposalssection.useBuiltInsoption of@babel/preset-envin favor of creation plugin(s) / preset in the scope ofcore-jsfor polyfills only.@babel/preset-envSome of the improvements already added, some should be added.
compat-tableis not enough for correct detection of environments wherecore-jsmodules required. More info about it you could find here. So I madecore-js-compatpackage with required data which should be used here.babel@7release, some still not.Promisewith dependencies (@babel/preset-env not always polyfilling Promise #9250), etc.Polyfilling of proposals
In the final
babel@7versions, from all polyfilling-related stuff was removed polyfilling of proposals. Seems that it was a mistake.New babel plugins for proposals will rely on new standard library features. And, with the current approach to polyfilling of proposals, it's too problematic.
I can understand why polyfilling of proposals was removed from the default
@babel/polyfill. But in this case, we should have added entry points which include proposals.Adding polyfills of proposals from
core-jswhen the main part of polyfills loaded from@babel/polyfillis not a good solution because they could be loaded from another instance ofcore-jsand it will cause problems.Removing proposals from
runtimewill kill usage of new proposal plugins which depends on new standard library features with theruntime. They should be available in helpers. Even import of required part ofcore-jswithout global namespace pollution is rocket science for a serious part of developers. Also,@babel/runtime-corejsxis not@babel/runtime-stable-corejsx-features.The same for
@babel/preset-env, but not so critical.@babel/preset-envtransformscore-jsonly to import of stable ES features. But the maincore-jsentry point also contains proposals and someone can expect some of them.runtimeandpreset-envinject polyfills based on feature detection, only when they are used, so I don't see any arguments why polyfilling of proposals was removed from those tools.The
shippedProposalsoption of@babel/preset-envlooks like something strange. We haven't any equal incore-jsentry points, so I don't see what should be transformed. Implementing in browser definitely is not an indicator that it should be polyfilled, but non-implemented proposals should not. I don't think that it's something that should be supported.So, by my vision, the best approach is:
@babel/polyfillin favor recommendation of separate inclusion of required parts ofcore-jsandbabel-runtime. If someone needs polyfills of proposals - he will use polyfills of proposals, not - not.@babel/polyfillin@babel/preset-env.preset-envwithuseBuiltIns: entry(or a successor for polyfilling) transforms:core-jsto all modules,core-js/es,core-js/proposalsandcore-js/webto related parts ofcore-js.runtimeandpreset-envinject proposals polyfills. Maybe - with an option for that, but option will make it harder.--------------------
Before the next step, we should decide what should we do with
@babel/polyfill,@babel/preset-envbreaking changes and polyfilling of proposals. Thoughts?