Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Babel 7 (#16297)
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
Showing
with
1,027 additions
and 417 deletions.
- +0 −23 .babelrc
- +27 −0 babel.config.js
- +29 −30 package.json
- +4 −3 packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
- +46 −0 packages/react-refresh/src/__tests__/ReactFreshBabelPluginProd-test.js
- +4 −4 packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js
- +67 −63 packages/react-refresh/src/__tests__/__snapshots__/ReactFreshBabelPlugin-test.js.snap
- +7 −3 packages/react/src/__tests__/createReactClassIntegration-test.js
- +1 −1 scripts/babel/__tests__/wrap-warning-with-env-check-test.js
- +5 −1 scripts/babel/transform-object-assign-require.js
- +23 −46 scripts/error-codes/__tests__/__snapshots__/transform-error-messages.js.snap
- +1 −11 scripts/error-codes/__tests__/transform-error-messages.js
- +1 −1 scripts/error-codes/extract-errors.js
- +9 −7 scripts/error-codes/transform-error-messages.js
- +6 −0 scripts/jest/config.base.js
- +6 −0 scripts/jest/config.source-persistent.js
- +7 −8 scripts/jest/preprocessor.js
- +1 −1 scripts/print-warnings/print-warnings.js
- +70 −1 scripts/rollup/bundles.js
- +713 −214 yarn.lock
| @@ -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}], | ||
| ], | ||
| }; |
| @@ -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")', | ||
| ), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.

