Skip to content

Commit b94adb3

Browse files
committed
fix: production babel plugin might perform eager replacement, fixes #1388
1 parent 6707b4b commit b94adb3

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/babel.prod.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default function plugin() {
7474
// ensure that this is `hot` from RHL
7575
isImportedFromRHL(path, specifier.local) &&
7676
path.parent.type === 'CallExpression' &&
77+
path.parent.arguments.length === 1 &&
7778
path.parent.arguments[0] &&
7879
path.parent.arguments[0].type === 'Identifier'
7980
) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { hot } from 'react-hot-loader';
2+
import { hot as rootHot } from 'react-hot-loader/root';
3+
4+
const control = compose(
5+
withDebug,
6+
withDebug,
7+
)(App);
8+
9+
const targetCase1 = compose(
10+
withDebug,
11+
withDebug,
12+
hot(module),
13+
)(App);
14+
15+
const targetCase2 = compose(
16+
withDebug,
17+
withDebug,
18+
rootHot,
19+
)(App);
20+
21+
const removeHot1 = hot(control);
22+
const removeHot2 = hot(module)(control);
23+
const removeHot3 = rootHot(control);

test/__snapshots__/babel.test.js.snap

+32
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,24 @@ exports.default = _default;
10691069
})();"
10701070
`;
10711071

1072+
exports[`babel Targetting "es2015" tags potential React components drop hot half.prod.js 1`] = `
1073+
"'use strict';
1074+
1075+
var _reactHotLoader = require('react-hot-loader');
1076+
1077+
var _root = require('react-hot-loader/root');
1078+
1079+
var control = compose(withDebug, withDebug)(App);
1080+
1081+
var targetCase1 = compose(withDebug, withDebug, (0, _reactHotLoader.hot)(module))(App);
1082+
1083+
var targetCase2 = compose(withDebug, withDebug, _root.hot)(App);
1084+
1085+
var removeHot1 = (0, _reactHotLoader.hot)(control);
1086+
var removeHot2 = control;
1087+
var removeHot3 = control;"
1088+
`;
1089+
10721090
exports[`babel Targetting "es2015" tags potential React components drop hot.prod.js 1`] = `
10731091
"'use strict';
10741092
@@ -2179,6 +2197,20 @@ exports.default = _default;
21792197
})();"
21802198
`;
21812199
2200+
exports[`babel Targetting "modern" tags potential React components drop hot half.prod.js 1`] = `
2201+
"'use strict';
2202+
2203+
Object.defineProperty(exports, \\"__esModule\\", {
2204+
value: true
2205+
});
2206+
2207+
var _reactHotLoader = require('react-hot-loader');
2208+
2209+
var _root = require('react-hot-loader/root');
2210+
2211+
exports.default = withDebug(App);"
2212+
`;
2213+
21822214
exports[`babel Targetting "modern" tags potential React components drop hot.prod.js 1`] = `
21832215
"'use strict';
21842216

0 commit comments

Comments
 (0)