-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded from Babel 6 to Babel 7. The only significant change seems to be the way `@babel/plugin-transform-classes` handles classes differently from `babel-plugin-transform-es2015-classes`. In regular mode, the former injects a `_createClass` function that increases the bundle size, and in the latter it removes the safeguard checks. However, this is okay because we don't all classes in new features, and we want to deprecate class usage in the future in the react repo. Co-authored-by: Luna Ruan <[email protected]> Co-authored-by: Abdul Rauf <[email protected]> Co-authored-by: Maksim Markelov <[email protected]>
- Loading branch information
1 parent
d77c623
commit b12a982
Showing
20 changed files
with
1,027 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
plugins: [ | ||
'@babel/plugin-syntax-jsx', | ||
'@babel/plugin-transform-react-jsx', | ||
'@babel/plugin-transform-flow-strip-types', | ||
['@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}], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/react-refresh/src/__tests__/ReactFreshBabelPluginProd-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
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: [ | ||
'@babel/syntax-jsx', | ||
'@babel/syntax-dynamic-import', | ||
freshPlugin, | ||
...(options.plugins || []), | ||
], | ||
}).code, | ||
); | ||
} | ||
|
||
describe('ReactFreshBabelPlugin Prod', () => { | ||
it('thorw error if environment is not development', () => { | ||
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.NODE_ENV + | ||
'". (While processing: "base$2")', | ||
), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.