-
Notifications
You must be signed in to change notification settings - Fork 45.9k
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
Babel 7 #16297
Babel 7 #16297
Changes from 10 commits
ecd1734
ea8022d
988d630
d73c6eb
aecac62
fc409b6
c9c99fc
1c233d6
88eeb24
df8856c
79f3507
faa6e32
4b02b0f
2e07a65
348fae3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
presets: ['@babel/preset-react', '@babel/preset-flow'], | ||
plugins: [ | ||
['@babel/plugin-proposal-class-properties', {loose: true}], | ||
'syntax-trailing-function-commas', | ||
[ | ||
'@babel/plugin-proposal-object-rest-spread', | ||
{loose: true, useBuiltIns: true}, | ||
], | ||
['@babel/plugin-transform-template-literals', {loose: true}], | ||
'@babel/plugin-transform-literals', | ||
'@babel/plugin-transform-arrow-functions', | ||
'@babel/plugin-transform-block-scoped-functions', | ||
'@babel/plugin-transform-object-super', | ||
'@babel/plugin-transform-shorthand-properties', | ||
'@babel/plugin-transform-computed-properties', | ||
'@babel/plugin-transform-for-of', | ||
['@babel/plugin-transform-spread', {loose: true, useBuiltIns: true}], | ||
'@babel/plugin-transform-parameters', | ||
['@babel/plugin-transform-destructuring', {loose: true, useBuiltIns: true}], | ||
['@babel/plugin-transform-block-scoping', {throwIfClosureRequired: true}], | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,38 +4,38 @@ | |
"packages/*" | ||
], | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0", | ||
"@babel/code-frame": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/helper-module-imports": "^7.0.0", | ||
"@babel/plugin-external-helpers": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | ||
"@babel/plugin-syntax-dynamic-import": "^7.0.0", | ||
"@babel/plugin-transform-arrow-functions": "^7.0.0", | ||
"@babel/plugin-transform-async-to-generator": "^7.0.0", | ||
"@babel/plugin-transform-block-scoped-functions": "^7.0.0", | ||
"@babel/plugin-transform-block-scoping": "^7.0.0", | ||
"@babel/plugin-transform-classes": "^7.0.0", | ||
"@babel/plugin-transform-computed-properties": "^7.0.0", | ||
"@babel/plugin-transform-destructuring": "^7.0.0", | ||
"@babel/plugin-transform-for-of": "^7.0.0", | ||
"@babel/plugin-transform-literals": "^7.0.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.0.0", | ||
"@babel/plugin-transform-object-super": "^7.0.0", | ||
"@babel/plugin-transform-parameters": "^7.0.0", | ||
"@babel/plugin-transform-react-jsx-source": "^7.0.0", | ||
"@babel/plugin-transform-shorthand-properties": "^7.0.0", | ||
"@babel/plugin-transform-spread": "^7.0.0", | ||
"@babel/plugin-transform-template-literals": "^7.0.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/traverse": "^7.0.0", | ||
"@mattiasbuelens/web-streams-polyfill": "0.1.0", | ||
"art": "^0.10.1", | ||
"babel-cli": "^6.6.5", | ||
"babel-code-frame": "^6.26.0", | ||
"babel-core": "^6.0.0", | ||
"babel-eslint": "^10.0.0", | ||
"babel-jest": "^23.0.1", | ||
"babel-plugin-check-es2015-constants": "^6.5.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-syntax-dynamic-import": "^6.18.0", | ||
"babel-jest": "^24.8.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. Thanks! |
||
"babel-plugin-syntax-trailing-function-commas": "^6.5.0", | ||
"babel-plugin-transform-async-to-generator": "^6.22.0", | ||
"babel-plugin-transform-class-properties": "^6.11.5", | ||
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2", | ||
"babel-plugin-transform-es2015-block-scoped-functions": "^6.5.0", | ||
"babel-plugin-transform-es2015-block-scoping": "^6.23.0", | ||
"babel-plugin-transform-es2015-classes": "^6.5.2", | ||
"babel-plugin-transform-es2015-computed-properties": "^6.5.2", | ||
"babel-plugin-transform-es2015-destructuring": "^6.5.0", | ||
"babel-plugin-transform-es2015-for-of": "^6.5.2", | ||
"babel-plugin-transform-es2015-literals": "^6.5.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2", | ||
"babel-plugin-transform-es2015-object-super": "^6.5.0", | ||
"babel-plugin-transform-es2015-parameters": "^6.5.0", | ||
"babel-plugin-transform-es2015-shorthand-properties": "^6.5.0", | ||
"babel-plugin-transform-es2015-spread": "^6.5.2", | ||
"babel-plugin-transform-es2015-template-literals": "^6.5.2", | ||
"babel-plugin-transform-object-rest-spread": "^6.6.5", | ||
"babel-plugin-transform-react-jsx-source": "^6.8.0", | ||
"babel-plugin-transform-regenerator": "^6.26.0", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-traverse": "^6.9.0", | ||
"babylon": "6.18.0", | ||
"chalk": "^1.1.3", | ||
"cli-table": "^0.3.1", | ||
|
@@ -53,7 +53,7 @@ | |
"eslint-plugin-jest": "^21.6.1", | ||
"eslint-plugin-no-for-of-loops": "^1.0.0", | ||
"eslint-plugin-react": "^6.7.1", | ||
"eslint-plugin-react-internal": "link:./scripts/eslint-rules/", | ||
"eslint-plugin-react-internal": "link:./scripts/eslint-rules", | ||
"fbjs-scripts": "^0.8.3", | ||
"filesize": "^3.5.6", | ||
"flow-bin": "^0.72.0", | ||
|
@@ -76,7 +76,7 @@ | |
"react-lifecycles-compat": "^3.0.2", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.52.1", | ||
"rollup-plugin-babel": "^3.0.1", | ||
"rollup-plugin-babel": "^4.0.1", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
"rollup-plugin-node-resolve": "^2.1.1", | ||
"rollup-plugin-prettier": "^0.3.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,25 +7,54 @@ | |
|
||
'use strict'; | ||
|
||
let babel = require('babel-core'); | ||
let babel = require('@babel/core'); | ||
let {wrap} = require('jest-snapshot-serializer-raw'); | ||
let freshPlugin = require('react-refresh/babel'); | ||
|
||
function transform(input, options = {}) { | ||
return wrap( | ||
babel.transform(input, { | ||
babelrc: false, | ||
configFile: false, | ||
plugins: [ | ||
'syntax-jsx', | ||
'syntax-dynamic-import', | ||
'@babel/syntax-jsx', | ||
'@babel/syntax-dynamic-import', | ||
freshPlugin, | ||
...(options.plugins || []), | ||
], | ||
}).code, | ||
); | ||
} | ||
|
||
const oldEnv = babel.getEnv(); | ||
describe('ReactFreshBabelPlugin', () => { | ||
beforeEach(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason Fresh throws an error if you're not in development environment is because the production build of React does not support hot reloading. React uses a We should use if (__DEV__) {
// The tests
} else {
it('throw error if environment is not development', ...);
} |
||
process.env.BABEL_ENV = 'development'; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env.BABEL_ENV = oldEnv; | ||
}); | ||
|
||
it('thorw error if environment is not development', () => { | ||
process.env.BABEL_ENV = 'production'; | ||
|
||
let error; | ||
try { | ||
transform(`function Hello() {}`); | ||
} catch (transformError) { | ||
error = transformError; | ||
} | ||
expect(error).toEqual( | ||
new Error( | ||
'[BABEL] unknown: React Refresh Babel transform should only be enabled ' + | ||
'in development environment. Instead, the environment is: "' + | ||
process.env.BABEL_ENV + | ||
'". (While processing: "base$2")', | ||
), | ||
); | ||
}); | ||
|
||
it('registers top-level function declarations', () => { | ||
// Hello and Bar should be registered, handleClick shouldn't. | ||
expect( | ||
|
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 we remove these presets and use the plugins directly? That way unexpected stuff can't sneak in.