diff --git a/packages/react-refresh/src/ReactFreshBabelPlugin.js b/packages/react-refresh/src/ReactFreshBabelPlugin.js
index f1a92e9da8e07..567a96d853ccc 100644
--- a/packages/react-refresh/src/ReactFreshBabelPlugin.js
+++ b/packages/react-refresh/src/ReactFreshBabelPlugin.js
@@ -22,6 +22,8 @@ export default function(babel, opts = {}) {
}
const {types: t} = babel;
+ const refreshReg = t.identifier(opts.refreshReg || '$RefreshReg$');
+ const refreshSig = t.identifier(opts.refreshSig || '$RefreshSig$');
const registrationsByProgramPath = new Map();
function createRegistration(programPath, persistentID) {
@@ -517,7 +519,7 @@ export default function(babel, opts = {}) {
const sigCallID = path.scope.generateUidIdentifier('_s');
path.scope.parent.push({
id: sigCallID,
- init: t.callExpression(t.identifier('$RefreshSig$'), []),
+ init: t.callExpression(refreshSig, []),
});
// The signature call is split in two parts. One part is called inside the function.
@@ -579,7 +581,7 @@ export default function(babel, opts = {}) {
const sigCallID = path.scope.generateUidIdentifier('_s');
path.scope.parent.push({
id: sigCallID,
- init: t.callExpression(t.identifier('$RefreshSig$'), []),
+ init: t.callExpression(refreshSig, []),
});
// The signature call is split in two parts. One part is called inside the function.
@@ -743,7 +745,7 @@ export default function(babel, opts = {}) {
path.pushContainer(
'body',
t.expressionStatement(
- t.callExpression(t.identifier('$RefreshReg$'), [
+ t.callExpression(refreshReg, [
handle,
t.stringLiteral(persistentID),
]),
diff --git a/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js b/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
index ed7bd8cd15c45..8c2cc3b0a139f 100644
--- a/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
+++ b/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
@@ -25,6 +25,7 @@ function transform(input, options = {}) {
skipEnvCheck: true,
// To simplify debugging tests:
emitFullSignatures: true,
+ ...options.freshOptions,
},
],
...(options.plugins || []),
@@ -480,4 +481,21 @@ describe('ReactFreshBabelPlugin', () => {
`),
).toMatchSnapshot();
});
+
+ it('uses custom identifiers for $RefreshReg$ and $RefreshSig$', () => {
+ expect(
+ transform(
+ `export default function Bar () {
+ useContext(X)
+ return