Skip to content
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

Merged
merged 15 commits into from
Aug 9, 2019
Merged

Babel 7 #16297

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

module.exports = {
presets: ['@babel/preset-react', '@babel/preset-flow'],
plugins: [
'@babel/plugin-syntax-jsx',
'@babel/plugin-transform-react-jsx',
'@babel/plugin-transform-react-display-name',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this one. Don't need it.

'@babel/plugin-transform-flow-strip-types',
['@babel/plugin-proposal-class-properties', {loose: true}],
'syntax-trailing-function-commas',
[
Expand Down
28 changes: 0 additions & 28 deletions packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,7 @@ function transform(input, options = {}) {
);
}

const oldEnv = babel.getEnv();
describe('ReactFreshBabelPlugin', () => {
beforeEach(() => {
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(
Expand Down
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")',
),
);
});
});
6 changes: 6 additions & 0 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = {
modulePathIgnorePatterns: [
'<rootDir>/scripts/rollup/shims/',
'<rootDir>/scripts/bench/',
// ReactFreshBabelPlugin is only available for dev.
// We need two tests here because otherwise, ReactFreshBabelPlugin-test will
// fail due to obsolete snapshots
process.env.NODE_ENV !== 'development'
? '<rootDir>/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js'
: '<rootDir>/packages/react-refresh/src/__tests__/ReactFreshBabelPluginProd-test.js',
],
transform: {
'.*': require.resolve('./preprocessor.js'),
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3210,6 +3210,7 @@ inquirer@^3.0.6:
invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"

Expand Down Expand Up @@ -6151,6 +6152,7 @@ w3c-hr-time@^1.0.1:
walker@^1.0.7, walker@~1.0.5:
version "1.0.7"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
integrity sha1-L3+bj9ENZ3JisYqITijRlhjgKPs=
dependencies:
makeerror "1.0.x"

Expand Down