Skip to content

Commit 68d7985

Browse files
[core] Upgrade Babel 6 to Babel 7 (#10964)
1 parent f7af62f commit 68d7985

File tree

23 files changed

+1635
-815
lines changed

23 files changed

+1635
-815
lines changed

.babelrc

+38-41
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2-
"presets": ["./scripts/material-ui-babel-preset", "stage-1", "react"],
3-
"plugins": [
4-
"transform-object-assign"
5-
],
2+
"presets": ["./scripts/material-ui-babel-preset", "@babel/preset-stage-1", "@babel/preset-react"],
3+
"plugins": ["@babel/plugin-transform-object-assign"],
64
"env": {
75
"coverage": {
86
"plugins": [
97
"istanbul",
8+
"@babel/plugin-transform-flow-strip-types",
109
[
1110
"module-resolver",
1211
{
@@ -16,21 +15,17 @@
1615
"material-ui": "./packages/material-ui/src"
1716
}
1817
}
19-
],
18+
]
2019
]
2120
},
2221
"development": {
2322
"sourceMaps": "both",
24-
"plugins": [
25-
"transform-flow-strip-types"
26-
]
23+
"plugins": ["@babel/plugin-transform-flow-strip-types"]
2724
},
2825
"docs-development": {
29-
"presets": [
30-
"next/babel"
31-
],
26+
"presets": ["next/babel"],
3227
"plugins": [
33-
"preval",
28+
"./scripts/material-ui-babel-preval",
3429
[
3530
"module-resolver",
3631
{
@@ -44,15 +39,13 @@
4439
}
4540
}
4641
],
47-
"transform-flow-strip-types"
42+
"@babel/plugin-transform-flow-strip-types"
4843
]
4944
},
5045
"docs-production": {
51-
"presets": [
52-
"next/babel"
53-
],
46+
"presets": ["next/babel"],
5447
"plugins": [
55-
"preval",
48+
"./scripts/material-ui-babel-preval",
5649
[
5750
"module-resolver",
5851
{
@@ -68,43 +61,46 @@
6861
],
6962
"transform-react-constant-elements",
7063
"transform-dev-warning",
71-
"transform-runtime",
72-
["react-remove-properties", {"properties": ["data-mui-test"]}],
73-
["transform-react-remove-prop-types", {"mode": "remove"}]
64+
"@babel/transform-runtime",
65+
"@babel/plugin-transform-flow-strip-types",
66+
["react-remove-properties", { "properties": ["data-mui-test"] }],
67+
["transform-react-remove-prop-types", { "mode": "remove" }]
7468
]
7569
},
7670
"es": {
7771
"plugins": [
7872
"transform-react-constant-elements",
7973
"transform-dev-warning",
80-
"transform-runtime",
81-
["react-remove-properties", {"properties": ["data-mui-test"]}],
82-
["transform-react-remove-prop-types", {
83-
"mode": "wrap",
84-
"plugins": [
85-
"babel-plugin-transform-flow-strip-types"
86-
]
87-
}]
74+
"@babel/transform-runtime",
75+
"@babel/plugin-transform-flow-strip-types",
76+
["react-remove-properties", { "properties": ["data-mui-test"] }],
77+
[
78+
"transform-react-remove-prop-types",
79+
{
80+
"mode": "wrap"
81+
}
82+
]
8883
]
89-
},
84+
},
9085
"production": {
9186
"plugins": [
9287
"transform-react-constant-elements",
9388
"transform-dev-warning",
94-
"transform-runtime",
95-
["react-remove-properties", {"properties": ["data-mui-test"]}],
96-
["transform-react-remove-prop-types", {
97-
"mode": "wrap",
98-
"plugins": [
99-
"babel-plugin-transform-flow-strip-types"
100-
]
101-
}]
89+
"@babel/transform-runtime",
90+
"@babel/plugin-transform-flow-strip-types",
91+
["react-remove-properties", { "properties": ["data-mui-test"] }],
92+
[
93+
"transform-react-remove-prop-types",
94+
{
95+
"mode": "wrap"
96+
}
97+
]
10298
]
103-
},
99+
},
104100
"test": {
105101
"sourceMaps": "both",
106102
"plugins": [
107-
"transform-flow-strip-types",
103+
"@babel/plugin-transform-flow-strip-types",
108104
[
109105
"module-resolver",
110106
{
@@ -114,8 +110,9 @@
114110
"material-ui": "./packages/material-ui/src"
115111
}
116112
}
117-
],
113+
]
118114
]
119115
}
120-
}
116+
},
117+
"ignore": ["scripts/material-ui-babel-preset.js", "scripts/*.js"]
121118
}

.size-limit

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"name": "The initial cost people pay for using one component",
44
"webpack": true,
55
"path": "packages/material-ui/build/Paper/index.js",
6-
"limit": "25.4 KB"
6+
"limit": "26.0 KB"
77
},
88
{
99
"name": "The size of all the modules of material-ui.",
1010
"webpack": true,
1111
"path": "packages/material-ui/build/index.js",
12-
"limit": "101.4 KB"
12+
"limit": "102.3 KB"
1313
},
1414
{
1515
"name": "The main bundle of the docs",
1616
"webpack": false,
17-
"path": ".next/main.js",
17+
"path": ".next/bundles/pages/_app.js",
1818
"limit": "186 KB"
1919
},
2020
{

.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
network-timeout 150000

docs/src/modules/components/Link.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4+
import compose from 'recompose/compose';
5+
import { withRouter } from 'next/router';
46
import NextLink from 'next/link';
57
import { withStyles } from 'material-ui/styles';
68

@@ -50,17 +52,18 @@ OnClick.propTypes = {
5052
onCustomClick: PropTypes.func,
5153
};
5254

53-
function Link(props, context) {
55+
function Link(props) {
5456
const {
5557
activeClassName,
5658
children: childrenProp,
57-
component: ComponentProp,
5859
classes,
5960
className: classNameProp,
60-
variant,
61+
component: ComponentProp,
6162
href,
6263
onClick,
6364
prefetch,
65+
router,
66+
variant,
6467
...other
6568
} = props;
6669

@@ -82,12 +85,11 @@ function Link(props, context) {
8285
prefetch,
8386
passHref: true,
8487
};
85-
const active = context.url.pathname === href;
8688
children = (
8789
<OnClick
8890
component="a"
8991
className={classNames(className, {
90-
[activeClassName]: active && activeClassName,
92+
[activeClassName]: router.pathname === href && activeClassName,
9193
})}
9294
onCustomClick={onClick}
9395
{...other}
@@ -111,12 +113,6 @@ Link.defaultProps = {
111113
activeClassName: 'active',
112114
};
113115

114-
Link.contextTypes = {
115-
url: PropTypes.shape({
116-
pathname: PropTypes.string.isRequired,
117-
}).isRequired,
118-
};
119-
120116
Link.propTypes = {
121117
activeClassName: PropTypes.string,
122118
children: PropTypes.node.isRequired,
@@ -126,7 +122,10 @@ Link.propTypes = {
126122
href: PropTypes.string,
127123
onClick: PropTypes.func,
128124
prefetch: PropTypes.bool,
125+
router: PropTypes.shape({
126+
pathname: PropTypes.string.isRequired,
127+
}).isRequired,
129128
variant: PropTypes.oneOf(['default', 'primary', 'secondary', 'button']),
130129
};
131130

132-
export default withStyles(styles)(Link);
131+
export default compose(withRouter, withStyles(styles))(Link);

docs/src/modules/components/withRoot.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import find from 'lodash/find';
4+
import { withRouter } from 'next/router';
45
import { Provider } from 'react-redux';
56
import AppWrapper from 'docs/src/modules/components/AppWrapper';
67
import initRedux from 'docs/src/modules/redux/initRedux';
@@ -229,23 +230,23 @@ const pages = [
229230
},
230231
];
231232

232-
function findActivePage(currentPages, url) {
233+
function findActivePage(currentPages, router) {
233234
const activePage = find(currentPages, page => {
234235
if (page.children) {
235-
return url.pathname.indexOf(page.pathname) === 0;
236+
return router.pathname.indexOf(page.pathname) === 0;
236237
}
237238

238239
// Should be an exact match if no children
239-
return url.pathname === page.pathname;
240+
return router.pathname === page.pathname;
240241
});
241242

242243
if (!activePage) {
243244
return null;
244245
}
245246

246247
// We need to drill down
247-
if (activePage.pathname !== url.pathname) {
248-
return findActivePage(activePage.children, url);
248+
if (activePage.pathname !== router.pathname) {
249+
return findActivePage(activePage.children, router);
249250
}
250251

251252
return activePage;
@@ -260,19 +261,18 @@ function withRoot(Component) {
260261
}
261262

262263
getChildContext() {
263-
const url = this.props.url;
264+
const { router } = this.props;
264265

265-
let pathname = url.pathname;
266+
let pathname = router.pathname;
266267
if (pathname !== '/') {
267268
// The leading / is only added to support static hosting (resolve /index.html).
268269
// We remove it to normalize the pathname.
269270
pathname = pathname.replace(/\/$/, '');
270271
}
271272

272273
return {
273-
url,
274274
pages,
275-
activePage: findActivePage(pages, { ...url, pathname }),
275+
activePage: findActivePage(pages, { ...router, pathname }),
276276
};
277277
}
278278

@@ -296,11 +296,10 @@ function withRoot(Component) {
296296
WithRoot.propTypes = {
297297
pageContext: PropTypes.object,
298298
reduxServerState: PropTypes.object,
299-
url: PropTypes.object,
299+
router: PropTypes.object.isRequired,
300300
};
301301

302302
WithRoot.childContextTypes = {
303-
url: PropTypes.object,
304303
pages: PropTypes.array,
305304
activePage: PropTypes.object,
306305
};
@@ -329,7 +328,7 @@ function withRoot(Component) {
329328
};
330329
};
331330

332-
return WithRoot;
331+
return withRouter(WithRoot);
333332
}
334333

335334
export default withRoot;

docs/src/pages/customization/css-in-js/JssRegistry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import CssInJs from './CssInJs';
77
const sheetsRegistry = new SheetsRegistry();
88
const theme = createMuiTheme();
99

10-
class JssRegistry extends React.Component<any, any> {
10+
class JssRegistry extends React.Component {
1111
state = {
1212
length: 0,
1313
};

docs/src/pages/demos/dialogs/ConfirmationDialog.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ConfirmationDialog extends React.Component {
3535

3636
state = {};
3737

38+
// TODO
3839
componentWillReceiveProps(nextProps) {
3940
if (nextProps.value !== this.props.value) {
4041
this.setState({ value: nextProps.value });

next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module.exports = {
2929

3030
return Object.assign({}, config, {
3131
plugins,
32+
node: {
33+
fs: 'empty',
34+
},
3235
module: Object.assign({}, config.module, {
3336
rules: config.module.rules.concat([
3437
{

0 commit comments

Comments
 (0)