JavascriptHotModuleReplacement.runtime.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // @ts-nocheck
  2. /*
  3. MIT License http://www.opensource.org/licenses/mit-license.php
  4. Author Tobias Koppers @sokra
  5. */
  6. "use strict";
  7. var $installedChunks$ = undefined;
  8. var $loadUpdateChunk$ = undefined;
  9. var $moduleCache$ = undefined;
  10. var $moduleFactories$ = undefined;
  11. var $ensureChunkHandlers$ = undefined;
  12. var $hasOwnProperty$ = undefined;
  13. var $hmrModuleData$ = undefined;
  14. var $hmrDownloadUpdateHandlers$ = undefined;
  15. var $hmrInvalidateModuleHandlers$ = undefined;
  16. var __webpack_require__ = undefined;
  17. module.exports = function () {
  18. var currentUpdateChunks;
  19. var currentUpdate;
  20. var currentUpdateRemovedChunks;
  21. var currentUpdateRuntime;
  22. function applyHandler(options) {
  23. if ($ensureChunkHandlers$) delete $ensureChunkHandlers$.$key$Hmr;
  24. currentUpdateChunks = undefined;
  25. function getAffectedModuleEffects(updateModuleId) {
  26. var outdatedModules = [updateModuleId];
  27. var outdatedDependencies = {};
  28. var queue = outdatedModules.map(function (id) {
  29. return {
  30. chain: [id],
  31. id: id
  32. };
  33. });
  34. while (queue.length > 0) {
  35. var queueItem = queue.pop();
  36. var moduleId = queueItem.id;
  37. var chain = queueItem.chain;
  38. var module = $moduleCache$[moduleId];
  39. if (
  40. !module ||
  41. (module.hot._selfAccepted && !module.hot._selfInvalidated)
  42. )
  43. continue;
  44. if (module.hot._selfDeclined) {
  45. return {
  46. type: "self-declined",
  47. chain: chain,
  48. moduleId: moduleId
  49. };
  50. }
  51. if (module.hot._main) {
  52. return {
  53. type: "unaccepted",
  54. chain: chain,
  55. moduleId: moduleId
  56. };
  57. }
  58. for (var i = 0; i < module.parents.length; i++) {
  59. var parentId = module.parents[i];
  60. var parent = $moduleCache$[parentId];
  61. if (!parent) continue;
  62. if (parent.hot._declinedDependencies[moduleId]) {
  63. return {
  64. type: "declined",
  65. chain: chain.concat([parentId]),
  66. moduleId: moduleId,
  67. parentId: parentId
  68. };
  69. }
  70. if (outdatedModules.indexOf(parentId) !== -1) continue;
  71. if (parent.hot._acceptedDependencies[moduleId]) {
  72. if (!outdatedDependencies[parentId])
  73. outdatedDependencies[parentId] = [];
  74. addAllToSet(outdatedDependencies[parentId], [moduleId]);
  75. continue;
  76. }
  77. delete outdatedDependencies[parentId];
  78. outdatedModules.push(parentId);
  79. queue.push({
  80. chain: chain.concat([parentId]),
  81. id: parentId
  82. });
  83. }
  84. }
  85. return {
  86. type: "accepted",
  87. moduleId: updateModuleId,
  88. outdatedModules: outdatedModules,
  89. outdatedDependencies: outdatedDependencies
  90. };
  91. }
  92. function addAllToSet(a, b) {
  93. for (var i = 0; i < b.length; i++) {
  94. var item = b[i];
  95. if (a.indexOf(item) === -1) a.push(item);
  96. }
  97. }
  98. // at begin all updates modules are outdated
  99. // the "outdated" status can propagate to parents if they don't accept the children
  100. var outdatedDependencies = {};
  101. var outdatedModules = [];
  102. var appliedUpdate = {};
  103. var warnUnexpectedRequire = function warnUnexpectedRequire(module) {
  104. console.warn(
  105. "[HMR] unexpected require(" + module.id + ") to disposed module"
  106. );
  107. };
  108. for (var moduleId in currentUpdate) {
  109. if ($hasOwnProperty$(currentUpdate, moduleId)) {
  110. var newModuleFactory = currentUpdate[moduleId];
  111. var result = newModuleFactory
  112. ? getAffectedModuleEffects(moduleId)
  113. : {
  114. type: "disposed",
  115. moduleId: moduleId
  116. };
  117. /** @type {Error|false} */
  118. var abortError = false;
  119. var doApply = false;
  120. var doDispose = false;
  121. var chainInfo = "";
  122. if (result.chain) {
  123. chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
  124. }
  125. switch (result.type) {
  126. case "self-declined":
  127. if (options.onDeclined) options.onDeclined(result);
  128. if (!options.ignoreDeclined)
  129. abortError = new Error(
  130. "Aborted because of self decline: " +
  131. result.moduleId +
  132. chainInfo
  133. );
  134. break;
  135. case "declined":
  136. if (options.onDeclined) options.onDeclined(result);
  137. if (!options.ignoreDeclined)
  138. abortError = new Error(
  139. "Aborted because of declined dependency: " +
  140. result.moduleId +
  141. " in " +
  142. result.parentId +
  143. chainInfo
  144. );
  145. break;
  146. case "unaccepted":
  147. if (options.onUnaccepted) options.onUnaccepted(result);
  148. if (!options.ignoreUnaccepted)
  149. abortError = new Error(
  150. "Aborted because " + moduleId + " is not accepted" + chainInfo
  151. );
  152. break;
  153. case "accepted":
  154. if (options.onAccepted) options.onAccepted(result);
  155. doApply = true;
  156. break;
  157. case "disposed":
  158. if (options.onDisposed) options.onDisposed(result);
  159. doDispose = true;
  160. break;
  161. default:
  162. throw new Error("Unexception type " + result.type);
  163. }
  164. if (abortError) {
  165. return {
  166. error: abortError
  167. };
  168. }
  169. if (doApply) {
  170. appliedUpdate[moduleId] = newModuleFactory;
  171. addAllToSet(outdatedModules, result.outdatedModules);
  172. for (moduleId in result.outdatedDependencies) {
  173. if ($hasOwnProperty$(result.outdatedDependencies, moduleId)) {
  174. if (!outdatedDependencies[moduleId])
  175. outdatedDependencies[moduleId] = [];
  176. addAllToSet(
  177. outdatedDependencies[moduleId],
  178. result.outdatedDependencies[moduleId]
  179. );
  180. }
  181. }
  182. }
  183. if (doDispose) {
  184. addAllToSet(outdatedModules, [result.moduleId]);
  185. appliedUpdate[moduleId] = warnUnexpectedRequire;
  186. }
  187. }
  188. }
  189. currentUpdate = undefined;
  190. // Store self accepted outdated modules to require them later by the module system
  191. var outdatedSelfAcceptedModules = [];
  192. for (var j = 0; j < outdatedModules.length; j++) {
  193. var outdatedModuleId = outdatedModules[j];
  194. var module = $moduleCache$[outdatedModuleId];
  195. if (
  196. module &&
  197. (module.hot._selfAccepted || module.hot._main) &&
  198. // removed self-accepted modules should not be required
  199. appliedUpdate[outdatedModuleId] !== warnUnexpectedRequire &&
  200. // when called invalidate self-accepting is not possible
  201. !module.hot._selfInvalidated
  202. ) {
  203. outdatedSelfAcceptedModules.push({
  204. module: outdatedModuleId,
  205. require: module.hot._requireSelf,
  206. errorHandler: module.hot._selfAccepted
  207. });
  208. }
  209. }
  210. var moduleOutdatedDependencies;
  211. return {
  212. dispose: function () {
  213. currentUpdateRemovedChunks.forEach(function (chunkId) {
  214. delete $installedChunks$[chunkId];
  215. });
  216. currentUpdateRemovedChunks = undefined;
  217. var idx;
  218. var queue = outdatedModules.slice();
  219. while (queue.length > 0) {
  220. var moduleId = queue.pop();
  221. var module = $moduleCache$[moduleId];
  222. if (!module) continue;
  223. var data = {};
  224. // Call dispose handlers
  225. var disposeHandlers = module.hot._disposeHandlers;
  226. for (j = 0; j < disposeHandlers.length; j++) {
  227. disposeHandlers[j].call(null, data);
  228. }
  229. $hmrModuleData$[moduleId] = data;
  230. // disable module (this disables requires from this module)
  231. module.hot.active = false;
  232. // remove module from cache
  233. delete $moduleCache$[moduleId];
  234. // when disposing there is no need to call dispose handler
  235. delete outdatedDependencies[moduleId];
  236. // remove "parents" references from all children
  237. for (j = 0; j < module.children.length; j++) {
  238. var child = $moduleCache$[module.children[j]];
  239. if (!child) continue;
  240. idx = child.parents.indexOf(moduleId);
  241. if (idx >= 0) {
  242. child.parents.splice(idx, 1);
  243. }
  244. }
  245. }
  246. // remove outdated dependency from module children
  247. var dependency;
  248. for (var outdatedModuleId in outdatedDependencies) {
  249. if ($hasOwnProperty$(outdatedDependencies, outdatedModuleId)) {
  250. module = $moduleCache$[outdatedModuleId];
  251. if (module) {
  252. moduleOutdatedDependencies =
  253. outdatedDependencies[outdatedModuleId];
  254. for (j = 0; j < moduleOutdatedDependencies.length; j++) {
  255. dependency = moduleOutdatedDependencies[j];
  256. idx = module.children.indexOf(dependency);
  257. if (idx >= 0) module.children.splice(idx, 1);
  258. }
  259. }
  260. }
  261. }
  262. },
  263. apply: function (reportError) {
  264. var acceptPromises = [];
  265. // insert new code
  266. for (var updateModuleId in appliedUpdate) {
  267. if ($hasOwnProperty$(appliedUpdate, updateModuleId)) {
  268. $moduleFactories$[updateModuleId] = appliedUpdate[updateModuleId];
  269. }
  270. }
  271. // run new runtime modules
  272. for (var i = 0; i < currentUpdateRuntime.length; i++) {
  273. currentUpdateRuntime[i](__webpack_require__);
  274. }
  275. // call accept handlers
  276. for (var outdatedModuleId in outdatedDependencies) {
  277. if ($hasOwnProperty$(outdatedDependencies, outdatedModuleId)) {
  278. var module = $moduleCache$[outdatedModuleId];
  279. if (module) {
  280. moduleOutdatedDependencies =
  281. outdatedDependencies[outdatedModuleId];
  282. var callbacks = [];
  283. var errorHandlers = [];
  284. var dependenciesForCallbacks = [];
  285. for (var j = 0; j < moduleOutdatedDependencies.length; j++) {
  286. var dependency = moduleOutdatedDependencies[j];
  287. var acceptCallback =
  288. module.hot._acceptedDependencies[dependency];
  289. var errorHandler =
  290. module.hot._acceptedErrorHandlers[dependency];
  291. if (acceptCallback) {
  292. if (callbacks.indexOf(acceptCallback) !== -1) continue;
  293. callbacks.push(acceptCallback);
  294. errorHandlers.push(errorHandler);
  295. dependenciesForCallbacks.push(dependency);
  296. }
  297. }
  298. for (var k = 0; k < callbacks.length; k++) {
  299. var result;
  300. try {
  301. result = callbacks[k].call(null, moduleOutdatedDependencies);
  302. } catch (err) {
  303. if (typeof errorHandlers[k] === "function") {
  304. try {
  305. errorHandlers[k](err, {
  306. moduleId: outdatedModuleId,
  307. dependencyId: dependenciesForCallbacks[k]
  308. });
  309. } catch (err2) {
  310. if (options.onErrored) {
  311. options.onErrored({
  312. type: "accept-error-handler-errored",
  313. moduleId: outdatedModuleId,
  314. dependencyId: dependenciesForCallbacks[k],
  315. error: err2,
  316. originalError: err
  317. });
  318. }
  319. if (!options.ignoreErrored) {
  320. reportError(err2);
  321. reportError(err);
  322. }
  323. }
  324. } else {
  325. if (options.onErrored) {
  326. options.onErrored({
  327. type: "accept-errored",
  328. moduleId: outdatedModuleId,
  329. dependencyId: dependenciesForCallbacks[k],
  330. error: err
  331. });
  332. }
  333. if (!options.ignoreErrored) {
  334. reportError(err);
  335. }
  336. }
  337. }
  338. if (result && typeof result.then === "function") {
  339. acceptPromises.push(result);
  340. }
  341. }
  342. }
  343. }
  344. }
  345. var onAccepted = function () {
  346. // Load self accepted modules
  347. for (var o = 0; o < outdatedSelfAcceptedModules.length; o++) {
  348. var item = outdatedSelfAcceptedModules[o];
  349. var moduleId = item.module;
  350. try {
  351. item.require(moduleId);
  352. } catch (err) {
  353. if (typeof item.errorHandler === "function") {
  354. try {
  355. item.errorHandler(err, {
  356. moduleId: moduleId,
  357. module: $moduleCache$[moduleId]
  358. });
  359. } catch (err1) {
  360. if (options.onErrored) {
  361. options.onErrored({
  362. type: "self-accept-error-handler-errored",
  363. moduleId: moduleId,
  364. error: err1,
  365. originalError: err
  366. });
  367. }
  368. if (!options.ignoreErrored) {
  369. reportError(err1);
  370. reportError(err);
  371. }
  372. }
  373. } else {
  374. if (options.onErrored) {
  375. options.onErrored({
  376. type: "self-accept-errored",
  377. moduleId: moduleId,
  378. error: err
  379. });
  380. }
  381. if (!options.ignoreErrored) {
  382. reportError(err);
  383. }
  384. }
  385. }
  386. }
  387. };
  388. return Promise.all(acceptPromises)
  389. .then(onAccepted)
  390. .then(function () {
  391. return outdatedModules;
  392. });
  393. }
  394. };
  395. }
  396. $hmrInvalidateModuleHandlers$.$key$ = function (moduleId, applyHandlers) {
  397. if (!currentUpdate) {
  398. currentUpdate = {};
  399. currentUpdateRuntime = [];
  400. currentUpdateRemovedChunks = [];
  401. applyHandlers.push(applyHandler);
  402. }
  403. if (!$hasOwnProperty$(currentUpdate, moduleId)) {
  404. currentUpdate[moduleId] = $moduleFactories$[moduleId];
  405. }
  406. };
  407. $hmrDownloadUpdateHandlers$.$key$ = function (
  408. chunkIds,
  409. removedChunks,
  410. removedModules,
  411. promises,
  412. applyHandlers,
  413. updatedModulesList
  414. ) {
  415. applyHandlers.push(applyHandler);
  416. currentUpdateChunks = {};
  417. currentUpdateRemovedChunks = removedChunks;
  418. currentUpdate = removedModules.reduce(function (obj, key) {
  419. obj[key] = false;
  420. return obj;
  421. }, {});
  422. currentUpdateRuntime = [];
  423. chunkIds.forEach(function (chunkId) {
  424. if (
  425. $hasOwnProperty$($installedChunks$, chunkId) &&
  426. $installedChunks$[chunkId] !== undefined
  427. ) {
  428. promises.push($loadUpdateChunk$(chunkId, updatedModulesList));
  429. currentUpdateChunks[chunkId] = true;
  430. } else {
  431. currentUpdateChunks[chunkId] = false;
  432. }
  433. });
  434. if ($ensureChunkHandlers$) {
  435. $ensureChunkHandlers$.$key$Hmr = function (chunkId, promises) {
  436. if (
  437. currentUpdateChunks &&
  438. $hasOwnProperty$(currentUpdateChunks, chunkId) &&
  439. !currentUpdateChunks[chunkId]
  440. ) {
  441. promises.push($loadUpdateChunk$(chunkId));
  442. currentUpdateChunks[chunkId] = true;
  443. }
  444. };
  445. }
  446. };
  447. };