-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Update docs for core-js 3 #1987
Conversation
Deploy preview for babel ready! Built with commit 0a1c80e |
docs/plugin-transform-runtime.md
Outdated
@@ -88,16 +88,26 @@ require("@babel/core").transform("code", { | |||
|
|||
### `corejs` | |||
|
|||
`boolean` or `number` , defaults to `false`. | |||
`false`, `CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `false`. |
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.
Can possibly reduce the first 3 lines to:
false
, 2|3
, or { version: 2|3, proposals: boolean }
, defaults to false
.
docs/plugin-transform-runtime.md
Outdated
|
||
Specifying a number will rewrite the helpers that need polyfillable APIs to reference `core-js` instead. | ||
When this option is not false, all polyfillable API usages will be rewritten to reference helpers from `core-js` instead. |
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.
FWIW, I think the original sentence reads better, or maybe just:
Specifying a number will rewrite the helpers that need polyfillable APIs to reference helpers from that (major) version of
core-js
instead.
docs/plugin-transform-runtime.md
Outdated
|
||
Specifying a number will rewrite the helpers that need polyfillable APIs to reference `core-js` instead. | ||
When this option is not false, all polyfillable API usages will be rewritten to reference helpers from `core-js` instead. | ||
`corejs: 2` only supports global variables (e.g. `Promise`) and static properties (e.g. `Array.from`), while `corejs: 3` also supports instance properties (e.g. `[].includes`). |
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.
`corejs: 2` only supports global variables (e.g. `Promise`) and static properties (e.g. `Array.from`), while `corejs: 3` also supports instance properties (e.g. `[].includes`). | |
Please note that `corejs: 2` only supports global variables (e.g. `Promise`) and static properties (e.g. `Array.from`), while `corejs: 3` also supports instance properties (e.g. `[].includes`). |
docs/plugin-transform-runtime.md
Outdated
|
||
This requires changing the dependency used to be [`@babel/runtime-corejs2`](runtime-corejs2.md) instead of `@babel/runtime`. | ||
By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you are using `corejs: 3`, you can opt-in using the `proposals: true` boolean flag. |
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.
By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you are using `corejs: 3`, you can opt-in using the `proposals: true` boolean flag. | |
By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you are using `corejs: 3`, you can opt into this by enabling the `proposals: true` option. |
This requires changing the dependency used to be [`@babel/runtime-corejs2`](runtime-corejs2.md) instead of `@babel/runtime`. | ||
By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you are using `corejs: 3`, you can opt-in using the `proposals: true` boolean flag. | ||
|
||
This option requires changing the dependency used to provide the necessary runtime helpers: |
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.
Think it's too verbose to do? (On the fence, ignore if you think it's too much)
corejs option |
Install |
---|---|
false |
npm install --save @babel/runtime |
2 |
npm install --save @babel/runtime-corejs2 |
3 |
npm install --save @babel/runtime-corejs3 |
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.
Yeah it's better: people will only need to copy-paste
docs/preset-env.md
Outdated
@@ -302,7 +328,38 @@ var b = new Map(); | |||
|
|||
#### `useBuiltIns: false` | |||
|
|||
Don't add polyfills automatically per file, or transform `import "@babel/polyfill"` to individual polyfills. | |||
Don't add polyfills automatically per file, or transform `import "core-js"` to individual polyfills. |
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.
Again, I think we should be careful about wholesale removing @babel/polyfill
references as we don't want to give the impression that support is completely gone (breaking change).
docs/preset-env.md
Outdated
|
||
### `corejs` | ||
|
||
`CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `2`. |
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.
Thoughts on making this match an earlier edit?
`CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `2`. | |
`2|3` or `{ version 2|3, proposals: boolean }`, defaults to `2`. |
docs/preset-env.md
Outdated
|
||
`corejs: 2` only supports global variables (e.g. `Promise`) and static properties (e.g. `Array.from`), while `corejs: 3` also supports instance properties (e.g. `[].includes`). | ||
|
||
By default, `@babel/plugin-transform-runtime` doesn't polyfill proposals. If you are using `corejs: 3`, you can opt-in using the `proposals: true` boolean flag: |
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.
Seems unnecessary/redundant, we mention this above?
By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill them, you need to set
proposals: true
.
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.
Yeah, I think I accidentally copied these last two sentences from the transform-runtime docs
docs/preset-env.md
Outdated
`CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `2`. | ||
`CorejsVersion` can be either `2` or `3`. | ||
|
||
This option, which can only be used when `useBuiltIns` is not `false`, configures `@babel/preset-env` to inject imports to the correct `core-js` version. |
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.
This option, which can only be used when `useBuiltIns` is not `false`, configures `@babel/preset-env` to inject imports to the correct `core-js` version. | |
This option only has an effect when used alongside `useBuiltIns: usage` or `useBuiltIns: entry`, and ensures `@babel/preset-env` injects the correct imports for your `core-js` version. |
docs/preset-env.md
Outdated
`CorejsVersion` can be either `2` or `3`. | ||
|
||
This option, which can only be used when `useBuiltIns` is not `false`, configures `@babel/preset-env` to inject imports to the correct `core-js` version. | ||
By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill them, you need to set `proposals: true`. |
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.
We should explain why proposals: true
is necessary and is different than useShippedProposals
(which I'm still fuzzy on, personally).
@@ -88,17 +88,22 @@ require("@babel/core").transform("code", { | |||
|
|||
### `corejs` | |||
|
|||
`boolean` or `number` , defaults to `false`. | |||
`false`, `2`, `3` or `{ version: 2 | 3, proposals: boolean }`, defaults to `false`. |
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.
At the top of this page a note that runtime
does not support instance methods, now it's not correct.
Too many links to deprecated @babel/polyfill
as a global alternative.
This page does not contain a link to core-js
documentation. However, users should know what they are using. I think that we need to add it at least on the first core-js
entry.
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.
As part of this doc part I would also add a bit more clarity around how corejs
works in conjunction with the corejs
option from @babel/preset-env
.
If both options are set to something other than false then the corejs imports will be duplicated. One for preset-env and one for transform-runtime.
A bit more clarity that if you use preset-env with corejs option you should not use the same for transform runtime will help some developer understand what is going on.
This relates to some confusion from this issue #9728.
The same info could be added to the preset-env doc also for reference.
By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill them, you have three different options: | ||
- set the [`shippedProposals`](#shippedproposals) option to `true`. This will enable polyfills and transforms for proposal which have already been shipped in browsers for a while. | ||
- use `corejs: { version: 3, proposals: true }`. This will enable polyfilling of every proposal supported by `core-js`. | ||
- when using `useBuiltIns: "entry"`, you can directly import a [proposal polyfill](https://github.com/zloirock/core-js/tree/master/packages/core-js/proposals): `import "core-js/proposals/string-replace-all"`. |
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 am not sure that this is a clear enough wording. For polyfilling proposals, shippedProposals
and proposals
flags make sense only for usage
. For entry
, makes sense only the third option (and not only from proposals
path - for example, import "core-js"
includes import of all polyfills) without any flags.
This option configures how `@babel/preset-env` handles polyfills. | ||
|
||
When either the `usage` or `entry` options are used, `@babel-preset-env` will add direct references to `core-js` modules as bare imports (or requires). This means `core-js` will be resolved relative to the file itself and needs to be accessible. | ||
|
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.
The same as in runtime
docs - I don't see any links to core-js
documentation in this file.
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.
Built-ins
link in include
should be updated.
@@ -372,7 +414,8 @@ The following are currently supported: | |||
|
|||
**Builtins** | |||
|
|||
- [es7.array.flat-map](https://github.com/tc39/proposal-flatMap) | |||
- [esnext.global-this](https://github.com/tc39/proposal-global) (only supported by `core-js@3`) | |||
- [esnext.string.match-all](https://github.com/tc39/proposal-string-matchall) (only supported by `core-js@3`) |
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.
Makes sense specify that will be injected only with useBuiltIns: usage
.
Seems also need to update |
Co-Authored-By: nicolo-ribaudo <nicolo.ribaudo@gmail.com>
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.
Found a typo.
docs/polyfill.md
Outdated
> 🚨 As of Babel 7.4.0, this package has been deprecated in favor of directly including `core-js/stable` (to polyfill ECMAScript features) and `regenerator-runtime/runtime` (needed to use transpiled generator functions): | ||
> ```js | ||
> import "core-js/stable"; | ||
> import "renegerator-runtime/runtime"; |
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.
regenerator-runtime
instead of renegerator-runtime
🙂
Co-Authored-By: nicolo-ribaudo <nicolo.ribaudo@gmail.com>
I'm merging this PR with only one ✔️ since a lot of users are confused by the option not mentioned in the docs. If it needs to be changed it can be done in a folow-up PR. |
Babel PR: babel/babel#7646