From 61985e15f20d8d1c0cea1489807c7078c39290a9 Mon Sep 17 00:00:00 2001 From: Michael Mok Date: Tue, 14 Sep 2021 00:03:17 +0200 Subject: [PATCH] fix: ensure signature function don't share identity with stubs (#505) --- lib/utils/getRefreshGlobal.js | 4 +++- test/unit/getRefreshGlobal.test.js | 4 ++-- test/unit/makeRefreshRuntimeModule.test.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/utils/getRefreshGlobal.js b/lib/utils/getRefreshGlobal.js index 66530e21..b61c4e0c 100644 --- a/lib/utils/getRefreshGlobal.js +++ b/lib/utils/getRefreshGlobal.js @@ -71,7 +71,9 @@ function getRefreshGlobal( `${refreshGlobal}.runtime.register(type, typeId);`, ])}`, '', - `${refreshGlobal}.signature = ${refreshGlobal}.runtime.createSignatureFunctionForTransform;`, + `${refreshGlobal}.signature = ${RuntimeTemplate.returningFunction( + `${refreshGlobal}.runtime.createSignatureFunctionForTransform()` + )};`, '', `${refreshGlobal}.cleanup = ${RuntimeTemplate.basicFunction('cleanupModuleId', [ // Only cleanup if the module IDs match. diff --git a/test/unit/getRefreshGlobal.test.js b/test/unit/getRefreshGlobal.test.js index e88242ff..f64f6128 100644 --- a/test/unit/getRefreshGlobal.test.js +++ b/test/unit/getRefreshGlobal.test.js @@ -33,7 +33,7 @@ describe('getRefreshGlobal', () => { __webpack_require__.$Refresh$.runtime.register(type, typeId); } - __webpack_require__.$Refresh$.signature = __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform; + __webpack_require__.$Refresh$.signature = function() { return __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform(); }; __webpack_require__.$Refresh$.cleanup = function(cleanupModuleId) { if (currentModuleId === cleanupModuleId) { @@ -94,7 +94,7 @@ describe('getRefreshGlobal', () => { __webpack_require__.$Refresh$.runtime.register(type, typeId); } - __webpack_require__.$Refresh$.signature = __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform; + __webpack_require__.$Refresh$.signature = () => (__webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform()); __webpack_require__.$Refresh$.cleanup = (cleanupModuleId) => { if (currentModuleId === cleanupModuleId) { diff --git a/test/unit/makeRefreshRuntimeModule.test.js b/test/unit/makeRefreshRuntimeModule.test.js index 73dd6f54..bfbfdcf9 100644 --- a/test/unit/makeRefreshRuntimeModule.test.js +++ b/test/unit/makeRefreshRuntimeModule.test.js @@ -83,7 +83,7 @@ __webpack_require__.$Refresh$ = { __webpack_require__.$Refresh$.runtime.register(type, typeId); } - __webpack_require__.$Refresh$.signature = __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform; + __webpack_require__.$Refresh$.signature = function() { return __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform(); }; __webpack_require__.$Refresh$.cleanup = function(cleanupModuleId) { if (currentModuleId === cleanupModuleId) { @@ -162,7 +162,7 @@ __webpack_require__.$Refresh$ = { __webpack_require__.$Refresh$.runtime.register(type, typeId); } - __webpack_require__.$Refresh$.signature = __webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform; + __webpack_require__.$Refresh$.signature = () => (__webpack_require__.$Refresh$.runtime.createSignatureFunctionForTransform()); __webpack_require__.$Refresh$.cleanup = (cleanupModuleId) => { if (currentModuleId === cleanupModuleId) {