Skip to content
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

Merged
merged 6 commits into from
Apr 9, 2019
Merged

Conversation

nicolo-ribaudo
Copy link
Member

Babel PR: babel/babel#7646

@babel-bot
Copy link
Contributor

babel-bot commented Mar 14, 2019

Deploy preview for babel ready!

Built with commit 0a1c80e

https://deploy-preview-1987--babel.netlify.com

@@ -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`.
Copy link
Member

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.


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.
Copy link
Member

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.


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`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`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`).


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Member

@existentialism existentialism Mar 14, 2019

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

Copy link
Member Author

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

@@ -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.
Copy link
Member

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).


### `corejs`

`CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `2`.
Copy link
Member

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?

Suggested change
`CorejsVersion` or `{ version: CorejsVersion, proposals: boolean }`, defaults to `2`.
`2|3` or `{ version 2|3, proposals: boolean }`, defaults to `2`.


`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:
Copy link
Member

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.

Copy link
Member Author

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

`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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

`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`.
Copy link
Member

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`.
Copy link
Member

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.

Copy link

@radum radum Mar 27, 2019

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"`.
Copy link
Member

@zloirock zloirock Mar 18, 2019

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.

Copy link
Member

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.

Copy link
Member

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`)
Copy link
Member

@zloirock zloirock Mar 18, 2019

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.

docs/preset-env.md Outdated Show resolved Hide resolved
@zloirock
Copy link
Member

Seems also need to update preset-env options in the repl.

Co-Authored-By: nicolo-ribaudo <nicolo.ribaudo@gmail.com>
Copy link

@nstepien nstepien left a 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";

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 🙂

docs/polyfill.md Outdated Show resolved Hide resolved
Co-Authored-By: nicolo-ribaudo <nicolo.ribaudo@gmail.com>
@nicolo-ribaudo
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants