JavascriptHotModuleReplacement.runtime.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. // eslint-disable-next-line no-console
  105. console.warn(
  106. "[HMR] unexpected require(" + module.id + ") to disposed module"
  107. );
  108. };
  109. for (var moduleId in currentUpdate) {
  110. if ($hasOwnProperty$(currentUpdate, moduleId)) {
  111. var newModuleFactory = currentUpdate[moduleId];
  112. /** @type {TODO} */
  113. var result = newModuleFactory
  114. ? getAffectedModuleEffects(moduleId)
  115. : {
  116. type: "disposed",
  117. moduleId: moduleId
  118. };
  119. /** @type {Error|false} */
  120. var abortError = false;
  121. var doApply = false;
  122. var doDispose = false;
  123. var chainInfo = "";
  124. if (result.chain) {
  125. chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
  126. }
  127. switch (result.type) {
  128. case "self-declined":
  129. if (options.onDeclined) options.onDeclined(result);
  130. if (!options.ignoreDeclined)
  131. abortError = new Error(
  132. "Aborted because of self decline: " +
  133. result.moduleId +
  134. chainInfo
  135. );
  136. break;
  137. case "declined":
  138. if (options.onDeclined) options.onDeclined(result);
  139. if (!options.ignoreDeclined)
  140. abortError = new Error(
  141. "Aborted because of declined dependency: " +
  142. result.moduleId +
  143. " in " +
  144. result.parentId +
  145. chainInfo
  146. );
  147. break;
  148. case "unaccepted":
  149. if (options.onUnaccepted) options.onUnaccepted(result);
  150. if (!options.ignoreUnaccepted)
  151. abortError = new Error(
  152. "Aborted because " + moduleId + " is not accepted" + chainInfo
  153. );
  154. break;
  155. case "accepted":
  156. if (options.onAccepted) options.onAccepted(result);
  157. doApply = true;
  158. break;
  159. case "disposed":
  160. if (options.onDisposed) options.onDisposed(result);
  161. doDispose = true;
  162. break;
  163. default:
  164. throw new Error("Unexception type " + result.type);
  165. }
  166. if (abortError) {
  167. return {
  168. error: abortError
  169. };
  170. }
  171. if (doApply) {
  172. appliedUpdate[moduleId] = newModuleFactory;
  173. addAllToSet(outdatedModules, result.outdatedModules);
  174. for (moduleId in result.outdatedDependencies) {
  175. if ($hasOwnProperty$(result.outdatedDependencies, moduleId)) {
  176. if (!outdatedDependencies[moduleId])
  177. outdatedDependencies[moduleId] = [];
  178. addAllToSet(
  179. outdatedDependencies[moduleId],
  180. result.outdatedDependencies[moduleId]
  181. );
  182. }
  183. }
  184. }
  185. if (doDispose) {
  186. addAllToSet(outdatedModules, [result.moduleId]);
  187. appliedUpdate[moduleId] = warnUnexpectedRequire;
  188. }
  189. }
  190. }
  191. currentUpdate = undefined;
  192. // Store self accepted outdated modules to require them later by the module system
  193. var outdatedSelfAcceptedModules = [];
  194. for (var j = 0; j < outdatedModules.length; j++) {
  195. var outdatedModuleId = outdatedModules[j];
  196. var module = $moduleCache$[outdatedModuleId];
  197. if (
  198. module &&
  199. (module.hot._selfAccepted || module.hot._main) &&
  200. // removed self-accepted modules should not be required
  201. appliedUpdate[outdatedModuleId] !== warnUnexpectedRequire &&
  202. // when called invalidate self-accepting is not possible
  203. !module.hot._selfInvalidated
  204. ) {
  205. outdatedSelfAcceptedModules.push({
  206. module: outdatedModuleId,
  207. require: module.hot._requireSelf,
  208. errorHandler: module.hot._selfAccepted
  209. });
  210. }
  211. }
  212. var moduleOutdatedDependencies;
  213. return {
  214. dispose: function () {
  215. currentUpdateRemovedChunks.forEach(function (chunkId) {
  216. delete $installedChunks$[chunkId];
  217. });
  218. currentUpdateRemovedChunks = undefined;
  219. var idx;
  220. var queue = outdatedModules.slice();
  221. while (queue.length > 0) {
  222. var moduleId = queue.pop();
  223. var module = $moduleCache$[moduleId];
  224. if (!module) continue;
  225. var data = {};
  226. // Call dispose handlers
  227. var disposeHandlers = module.hot._disposeHandlers;
  228. for (j = 0; j < disposeHandlers.length; j++) {
  229. disposeHandlers[j].call(null, data);
  230. }
  231. $hmrModuleData$[moduleId] = data;
  232. // disable module (this disables requires from this module)
  233. module.hot.active = false;
  234. // remove module from cache
  235. delete $moduleCache$[moduleId];
  236. // when disposing there is no need to call dispose handler
  237. delete outdatedDependencies[moduleId];
  238. // remove "parents" references from all children
  239. for (j = 0; j < module.children.length; j++) {
  240. var child = $moduleCache$[module.children[j]];
  241. if (!child) continue;
  242. idx = child.parents.indexOf(moduleId);
  243. if (idx >= 0) {
  244. child.parents.splice(idx, 1);
  245. }
  246. }
  247. }
  248. // remove outdated dependency from module children
  249. var dependency;
  250. for (var outdatedModuleId in outdatedDependencies) {
  251. if ($hasOwnProperty$(outdatedDependencies, outdatedModuleId)) {
  252. module = $moduleCache$[outdatedModuleId];
  253. if (module) {
  254. moduleOutdatedDependencies =
  255. outdatedDependencies[outdatedModuleId];
  256. for (j = 0; j < moduleOutdatedDependencies.length; j++) {
  257. dependency = moduleOutdatedDependencies[j];
  258. idx = module.children.indexOf(dependency);
  259. if (idx >= 0) module.children.splice(idx, 1);
  260. }
  261. }
  262. }
  263. }
  264. },
  265. apply: function (reportError) {
  266. // insert new code
  267. for (var updateModuleId in appliedUpdate) {
  268. if ($hasOwnProperty$(appliedUpdate, updateModuleId)) {
  269. $moduleFactories$[updateModuleId] = appliedUpdate[updateModuleId];
  270. }
  271. }
  272. // run new runtime modules
  273. for (var i = 0; i < currentUpdateRuntime.length; i++) {
  274. currentUpdateRuntime[i](__webpack_require__);
  275. }
  276. // call accept handlers
  277. for (var outdatedModuleId in outdatedDependencies) {
  278. if ($hasOwnProperty$(outdatedDependencies, outdatedModuleId)) {
  279. var module = $moduleCache$[outdatedModuleId];
  280. if (module) {
  281. moduleOutdatedDependencies =
  282. outdatedDependencies[outdatedModuleId];
  283. var callbacks = [];
  284. var errorHandlers = [];
  285. var dependenciesForCallbacks = [];
  286. for (var j = 0; j < moduleOutdatedDependencies.length; j++) {
  287. var dependency = moduleOutdatedDependencies[j];
  288. var acceptCallback =
  289. module.hot._acceptedDependencies[dependency];
  290. var errorHandler =
  291. module.hot._acceptedErrorHandlers[dependency];
  292. if (acceptCallback) {
  293. if (callbacks.indexOf(acceptCallback) !== -1) continue;
  294. callbacks.push(acceptCallback);
  295. errorHandlers.push(errorHandler);
  296. dependenciesForCallbacks.push(dependency);
  297. }
  298. }
  299. for (var k = 0; k < callbacks.length; k++) {
  300. try {
  301. 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. }
  339. }
  340. }
  341. }
  342. // Load self accepted modules
  343. for (var o = 0; o < outdatedSelfAcceptedModules.length; o++) {
  344. var item = outdatedSelfAcceptedModules[o];
  345. var moduleId = item.module;
  346. try {
  347. item.require(moduleId);
  348. } catch (err) {
  349. if (typeof item.errorHandler === "function") {
  350. try {
  351. item.errorHandler(err, {
  352. moduleId: moduleId,
  353. module: $moduleCache$[moduleId]
  354. });
  355. } catch (err1) {
  356. if (options.onErrored) {
  357. options.onErrored({
  358. type: "self-accept-error-handler-errored",
  359. moduleId: moduleId,
  360. error: err1,
  361. originalError: err
  362. });
  363. }
  364. if (!options.ignoreErrored) {
  365. reportError(err1);
  366. reportError(err);
  367. }
  368. }
  369. } else {
  370. if (options.onErrored) {
  371. options.onErrored({
  372. type: "self-accept-errored",
  373. moduleId: moduleId,
  374. error: err
  375. });
  376. }
  377. if (!options.ignoreErrored) {
  378. reportError(err);
  379. }
  380. }
  381. }
  382. }
  383. return outdatedModules;
  384. }
  385. };
  386. }
  387. $hmrInvalidateModuleHandlers$.$key$ = function (moduleId, applyHandlers) {
  388. if (!currentUpdate) {
  389. currentUpdate = {};
  390. currentUpdateRuntime = [];
  391. currentUpdateRemovedChunks = [];
  392. applyHandlers.push(applyHandler);
  393. }
  394. if (!$hasOwnProperty$(currentUpdate, moduleId)) {
  395. currentUpdate[moduleId] = $moduleFactories$[moduleId];
  396. }
  397. };
  398. $hmrDownloadUpdateHandlers$.$key$ = function (
  399. chunkIds,
  400. removedChunks,
  401. removedModules,
  402. promises,
  403. applyHandlers,
  404. updatedModulesList
  405. ) {
  406. applyHandlers.push(applyHandler);
  407. currentUpdateChunks = {};
  408. currentUpdateRemovedChunks = removedChunks;
  409. currentUpdate = removedModules.reduce(function (obj, key) {
  410. obj[key] = false;
  411. return obj;
  412. }, {});
  413. currentUpdateRuntime = [];
  414. chunkIds.forEach(function (chunkId) {
  415. if (
  416. $hasOwnProperty$($installedChunks$, chunkId) &&
  417. $installedChunks$[chunkId] !== undefined
  418. ) {
  419. promises.push($loadUpdateChunk$(chunkId, updatedModulesList));
  420. currentUpdateChunks[chunkId] = true;
  421. } else {
  422. currentUpdateChunks[chunkId] = false;
  423. }
  424. });
  425. if ($ensureChunkHandlers$) {
  426. $ensureChunkHandlers$.$key$Hmr = function (chunkId, promises) {
  427. if (
  428. currentUpdateChunks &&
  429. $hasOwnProperty$(currentUpdateChunks, chunkId) &&
  430. !currentUpdateChunks[chunkId]
  431. ) {
  432. promises.push($loadUpdateChunk$(chunkId));
  433. currentUpdateChunks[chunkId] = true;
  434. }
  435. };
  436. }
  437. };
  438. };