Skip to content

Commit

Permalink
fix: production babel plugin might perform eager replacement, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Nov 15, 2019
1 parent 6707b4b commit b94adb3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/babel.prod.js
Expand Up @@ -74,6 +74,7 @@ export default function plugin() {
// ensure that this is `hot` from RHL
isImportedFromRHL(path, specifier.local) &&
path.parent.type === 'CallExpression' &&
path.parent.arguments.length === 1 &&
path.parent.arguments[0] &&
path.parent.arguments[0].type === 'Identifier'
) {
Expand Down
23 changes: 23 additions & 0 deletions test/__babel_fixtures__/drop-hot-half.prod.js
@@ -0,0 +1,23 @@
import { hot } from 'react-hot-loader';
import { hot as rootHot } from 'react-hot-loader/root';

const control = compose(
withDebug,
withDebug,
)(App);

const targetCase1 = compose(
withDebug,
withDebug,
hot(module),
)(App);

const targetCase2 = compose(
withDebug,
withDebug,
rootHot,
)(App);

const removeHot1 = hot(control);
const removeHot2 = hot(module)(control);
const removeHot3 = rootHot(control);
32 changes: 32 additions & 0 deletions test/__snapshots__/babel.test.js.snap
Expand Up @@ -1069,6 +1069,24 @@ exports.default = _default;
})();"
`;

exports[`babel Targetting "es2015" tags potential React components drop hot half.prod.js 1`] = `
"'use strict';
var _reactHotLoader = require('react-hot-loader');
var _root = require('react-hot-loader/root');
var control = compose(withDebug, withDebug)(App);
var targetCase1 = compose(withDebug, withDebug, (0, _reactHotLoader.hot)(module))(App);
var targetCase2 = compose(withDebug, withDebug, _root.hot)(App);
var removeHot1 = (0, _reactHotLoader.hot)(control);
var removeHot2 = control;
var removeHot3 = control;"
`;

exports[`babel Targetting "es2015" tags potential React components drop hot.prod.js 1`] = `
"'use strict';
Expand Down Expand Up @@ -2179,6 +2197,20 @@ exports.default = _default;
})();"
`;
exports[`babel Targetting "modern" tags potential React components drop hot half.prod.js 1`] = `
"'use strict';
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
var _reactHotLoader = require('react-hot-loader');
var _root = require('react-hot-loader/root');
exports.default = withDebug(App);"
`;
exports[`babel Targetting "modern" tags potential React components drop hot.prod.js 1`] = `
"'use strict';
Expand Down

0 comments on commit b94adb3

Please sign in to comment.