@@ -27,45 +27,44 @@ function makeRefreshRuntimeModule(webpack) {
2727 `${
2828 runtimeTemplate . supportsConst ( ) ? 'const' : 'var'
2929 } originalFactory = options.factory;`,
30- `options.factory = ${ runtimeTemplate . basicFunction (
31- 'moduleObject, moduleExports, webpackRequire' ,
32- [
33- `${ refreshGlobal } .setup(options.id);` ,
34- 'try {' ,
35- webpack . Template . indent (
36- 'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);'
37- ) ,
38- '} finally {' ,
30+ `options.factory = function (moduleObject, moduleExports, webpackRequire) {` ,
31+ webpack . Template . indent ( [
32+ `${ refreshGlobal } .setup(options.id);` ,
33+ 'try {' ,
34+ webpack . Template . indent (
35+ 'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);'
36+ ) ,
37+ '} finally {' ,
38+ webpack . Template . indent ( [
39+ `if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {` ,
3940 webpack . Template . indent ( [
40- `if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {` ,
41+ // The exports of the module are re-assigned -
42+ // this ensures anything coming after us would wait for `cleanup` to fire.
43+ // This is particularly important because `cleanup` restores the refresh global,
44+ // maintaining consistency for mutable variables like `moduleId`.
45+ // This `.then` clause is a ponyfill of the `Promise.finally` API -
46+ // it is only part of the spec after ES2018,
47+ // but Webpack's top level await implementation support engines down to ES2015.
48+ 'options.module.exports = options.module.exports.then(' ,
4149 webpack . Template . indent ( [
42- // The exports of the module are re-assigned -
43- // this ensures anything coming after us would wait for `cleanup` to fire.
44- // This is particularly important because `cleanup` restores the refresh global,
45- // maintaining consistency for mutable variables like `moduleId`.
46- // This `.then` clause is a ponyfill of the `Promise.finally` API -
47- // it is only part of the spec after ES2018,
48- // but Webpack's top level await implementation support engines down to ES2015.
49- 'options.module.exports = options.module.exports.then(' ,
50- webpack . Template . indent ( [
51- `${ runtimeTemplate . basicFunction ( 'result' , [
52- `${ refreshGlobal } .cleanup(options.id);` ,
53- 'return result;' ,
54- ] ) } ,`,
55- runtimeTemplate . basicFunction ( 'reason' , [
56- `${ refreshGlobal } .cleanup(options.id);` ,
57- 'return Promise.reject(reason);' ,
58- ] ) ,
50+ `${ runtimeTemplate . basicFunction ( 'result' , [
51+ `${ refreshGlobal } .cleanup(options.id);` ,
52+ 'return result;' ,
53+ ] ) } ,`,
54+ runtimeTemplate . basicFunction ( 'reason' , [
55+ `${ refreshGlobal } .cleanup(options.id);` ,
56+ 'return Promise.reject(reason);' ,
5957 ] ) ,
60- `);` ,
6158 ] ) ,
62- '} else {' ,
63- webpack . Template . indent ( `${ refreshGlobal } .cleanup(options.id)` ) ,
64- '}' ,
59+ `);` ,
6560 ] ) ,
61+ '} else {' ,
62+ webpack . Template . indent ( `${ refreshGlobal } .cleanup(options.id)` ) ,
6663 '}' ,
67- ]
68- ) } `,
64+ ] ) ,
65+ '}' ,
66+ ] ) ,
67+ `};` ,
6968 ]
7069 ) } )`,
7170 '' ,
0 commit comments