Skip to content

Commit 7114965

Browse files
committed
Update to core-js@3
1 parent 91ddd61 commit 7114965

File tree

6 files changed

+69
-43
lines changed

6 files changed

+69
-43
lines changed

packages/babel-preset-react-app/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = function(api, opts, env) {
8383
useBuiltIns: 'entry',
8484
// Set the corejs version we are using to avoid warnings in console
8585
// This will need to change once we upgrade to corejs@3
86-
corejs: 2,
86+
corejs: 3,
8787
// Do not transform modules to CJS
8888
modules: false,
8989
// Exclude transforms that make all code slower

packages/react-app-polyfill/README.md

+46-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
This package includes polyfills for various browsers.
44
It includes minimum requirements and commonly used language features used by [Create React App](https://github.com/facebook/create-react-app) projects.
55

6-
### Features
7-
8-
Each polyfill ensures the following language features are present:
9-
10-
1. `Promise` (for `async` / `await` support)
11-
1. `window.fetch` (a Promise-based way to make web requests in the browser)
12-
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
13-
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
14-
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
15-
16-
*If you need more features, you must include them manually.*
17-
186
### Usage
197

208
First, install the package using Yarn or npm:
@@ -29,7 +17,19 @@ or
2917
yarn add react-app-polyfill
3018
```
3119

32-
Now, you can import the entry point for the minimal version you intend to support. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
20+
## Supporting Internet Explorer
21+
22+
You can import the entry point for the minimal version you intend to support to ensure that the minimum langauge features are present that are required to use Create React App. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
23+
24+
These modules ensures the following language features are present:
25+
26+
1. `Promise` (for `async` / `await` support)
27+
1. `window.fetch` (a Promise-based way to make web requests in the browser)
28+
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
29+
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
30+
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
31+
32+
_If you need more features, see the [Polyfilling other language features](#polyfilling-other-language-features) section below._
3333

3434
#### Internet Explorer 9
3535

@@ -48,3 +48,36 @@ import 'react-app-polyfill/ie11';
4848

4949
// ...
5050
```
51+
52+
## Polyfilling other language features
53+
54+
You can also polyfill stable language features not available in your target browsers. If you're using this in Create React App, it will automatically use the `browserslist` you've defined to only include polyfills needed by your target browsers when importing the `stable` polyfill. **Make sure to follow the Internet Explorer steps above if you need to support Internet Explorer in your application**.
55+
56+
```js
57+
// This must be the first line in src/index.js
58+
import 'react-app-polyfill/stable';
59+
60+
// ...
61+
```
62+
63+
If you are supporting Internet Explorer 9/11 you should include both the `ie9`/`ie11` and `stable` modules:
64+
65+
For IE9:
66+
67+
```js
68+
// These must be the first lines in src/index.js
69+
import 'react-app-polyfill/ie9';
70+
import 'react-app-polyfill/stable';
71+
72+
// ...
73+
```
74+
75+
For IE11:
76+
77+
```js
78+
// These must be the first lines in src/index.js
79+
import 'react-app-polyfill/ie11';
80+
import 'react-app-polyfill/stable';
81+
82+
// ...
83+
```

packages/react-app-polyfill/ie11.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ if (typeof window !== 'undefined') {
2626
Object.assign = require('object-assign');
2727

2828
// Support for...of (a commonly used syntax feature that requires Symbols)
29-
require('core-js/es6/symbol');
29+
require('core-js/features/symbol');
3030
// Support iterable spread (...Set, ...Map)
31-
require('core-js/fn/array/from');
31+
require('core-js/features/array/from');

packages/react-app-polyfill/ie9.js

+3-25
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,9 @@
66
*/
77
'use strict';
88

9-
if (typeof Promise === 'undefined') {
10-
// Rejection tracking prevents a common issue where React gets into an
11-
// inconsistent state due to an error, but it gets swallowed by a Promise,
12-
// and the user has no idea what causes React's erratic future behavior.
13-
require('promise/lib/rejection-tracking').enable();
14-
window.Promise = require('promise/lib/es6-extensions.js');
15-
}
16-
17-
// Make sure we're in a Browser-like environment before importing polyfills
18-
// This prevents `fetch()` from being imported in a Node test environment
19-
if (typeof window !== 'undefined') {
20-
// fetch() polyfill for making API calls.
21-
require('whatwg-fetch');
22-
}
23-
24-
// Object.assign() is commonly used with React.
25-
// It will use the native implementation if it's present and isn't buggy.
26-
Object.assign = require('object-assign');
27-
28-
// Support for...of (a commonly used syntax feature that requires Symbols)
29-
require('core-js/es6/symbol');
30-
// Support iterable spread (...Set, ...Map)
31-
require('core-js/fn/array/from');
9+
require('./ie11');
3210

3311
// React 16+ relies on Map, Set, and requestAnimationFrame
34-
require('core-js/es6/map');
35-
require('core-js/es6/set');
12+
require('core-js/features/map');
13+
require('core-js/features/set');
3614
require('raf').polyfill(window);

packages/react-app-polyfill/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
"files": [
1414
"ie9.js",
1515
"ie11.js",
16-
"jsdom.js"
16+
"jsdom.js",
17+
"stable.js"
1718
],
1819
"dependencies": {
19-
"core-js": "2.6.5",
20+
"core-js": "3.0.1",
2021
"object-assign": "4.1.1",
2122
"promise": "8.0.2",
2223
"raf": "3.4.1",
24+
"regenerator-runtime": "0.13.2",
2325
"whatwg-fetch": "3.0.0"
2426
}
2527
}

packages/react-app-polyfill/stable.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
// Polyfill stable language features.
10+
// It's recommended to use @babel/preset-env and browserslist
11+
// to only include the polyfills necessary for the target browsers.
12+
require('core-js/stable');
13+
require('regenerator-runtime/runtime');

0 commit comments

Comments
 (0)