JavascriptHotModuleReplacement.runtime.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. // insert new code
  265. for (var updateModuleId in appliedUpdate) {
  266. if ($hasOwnProperty$(appliedUpdate, updateModuleId)) {
  267. $moduleFactories$[updateModuleId] = appliedUpdate[updateModuleId];
  268. }
  269. }
  270. // run new runtime modules
  271. for (var i = 0; i < currentUpdateRuntime.length; i++) {
  272. currentUpdateRuntime[i](__webpack_require__);
  273. }
  274. // call accept handlers
  275. for (var outdatedModuleId in outdatedDependencies) {
  276. if ($hasOwnProperty$(outdatedDependencies, outdatedModuleId)) {
  277. var module = $moduleCache$[outdatedModuleId];
  278. if (module) {
  279. moduleOutdatedDependencies =
  280. outdatedDependencies[outdatedModuleId];
  281. var callbacks = [];
  282. var errorHandlers = [];
  283. var dependenciesForCallbacks = [];
  284. for (var j = 0; j < moduleOutdatedDependencies.length; j++) {
  285. var dependency = moduleOutdatedDependencies[j];
  286. var acceptCallback =
  287. module.hot._acceptedDependencies[dependency];
  288. var errorHandler =
  289. module.hot._acceptedErrorHandlers[dependency];
  290. if (acceptCallback) {
  291. if (callbacks.indexOf(acceptCallback) !== -1) continue;
  292. callbacks.push(acceptCallback);
  293. errorHandlers.push(errorHandler);
  294. dependenciesForCallbacks.push(dependency);
  295. }
  296. }
  297. for (var k = 0; k < callbacks.length; k++) {
  298. try {
  299. callbacks[k].call(null, moduleOutdatedDependencies);
  300. } catch (err) {
  301. if (typeof errorHandlers[k] === "function") {
  302. try {
  303. errorHandlers[k](err, {
  304. moduleId: outdatedModuleId,
  305. dependencyId: dependenciesForCallbacks[k]
  306. });
  307. } catch (err2) {
  308. if (options.onErrored) {
  309. options.onErrored({
  310. type: "accept-error-handler-errored",
  311. moduleId: outdatedModuleId,
  312. dependencyId: dependenciesForCallbacks[k],
  313. error: err2,
  314. originalError: err
  315. });
  316. }
  317. if (!options.ignoreErrored) {
  318. reportError(err2);
  319. reportError(err);
  320. }
  321. }
  322. } else {
  323. if (options.onErrored) {
  324. options.onErrored({
  325. type: "accept-errored",
  326. moduleId: outdatedModuleId,
  327. dependencyId: dependenciesForCallbacks[k],
  328. error: err
  329. });
  330. }
  331. if (!options.ignoreErrored) {
  332. reportError(err);
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. // Load self accepted modules
  341. for (var o = 0; o < outdatedSelfAcceptedModules.length; o++) {
  342. var item = outdatedSelfAcceptedModules[o];
  343. var moduleId = item.module;
  344. try {
  345. item.require(moduleId);
  346. } catch (err) {
  347. if (typeof item.errorHandler === "function") {
  348. try {
  349. item.errorHandler(err, {
  350. moduleId: moduleId,
  351. module: $moduleCache$[moduleId]
  352. });
  353. } catch (err1) {
  354. if (options.onErrored) {
  355. options.onErrored({
  356. type: "self-accept-error-handler-errored",
  357. moduleId: moduleId,
  358. error: err1,
  359. originalError: err
  360. });
  361. }
  362. if (!options.ignoreErrored) {
  363. reportError(err1);
  364. reportError(err);
  365. }
  366. }
  367. } else {
  368. if (options.onErrored) {
  369. options.onErrored({
  370. type: "self-accept-errored",
  371. moduleId: moduleId,
  372. error: err
  373. });
  374. }
  375. if (!options.ignoreErrored) {
  376. reportError(err);
  377. }
  378. }
  379. }
  380. }
  381. return outdatedModules;
  382. }
  383. };
  384. }
  385. $hmrInvalidateModuleHandlers$.$key$ = function (moduleId, applyHandlers) {
  386. if (!currentUpdate) {
  387. currentUpdate = {};
  388. currentUpdateRuntime = [];
  389. currentUpdateRemovedChunks = [];
  390. applyHandlers.push(applyHandler);
  391. }
  392. if (!$hasOwnProperty$(currentUpdate, moduleId)) {
  393. currentUpdate[moduleId] = $moduleFactories$[moduleId];
  394. }
  395. };
  396. $hmrDownloadUpdateHandlers$.$key$ = function (
  397. chunkIds,
  398. removedChunks,
  399. removedModules,
  400. promises,
  401. applyHandlers,
  402. updatedModulesList
  403. ) {
  404. applyHandlers.push(applyHandler);
  405. currentUpdateChunks = {};
  406. currentUpdateRemovedChunks = removedChunks;
  407. currentUpdate = removedModules.reduce(function (obj, key) {
  408. obj[key] = false;
  409. return obj;
  410. }, {});
  411. currentUpdateRuntime = [];
  412. chunkIds.forEach(function (chunkId) {
  413. if (
  414. $hasOwnProperty$($installedChunks$, chunkId) &&
  415. $installedChunks$[chunkId] !== undefined
  416. ) {
  417. promises.push($loadUpdateChunk$(chunkId, updatedModulesList));
  418. currentUpdateChunks[chunkId] = true;
  419. } else {
  420. currentUpdateChunks[chunkId] = false;
  421. }
  422. });
  423. if ($ensureChunkHandlers$) {
  424. $ensureChunkHandlers$.$key$Hmr = function (chunkId, promises) {
  425. if (
  426. currentUpdateChunks &&
  427. $hasOwnProperty$(currentUpdateChunks, chunkId) &&
  428. !currentUpdateChunks[chunkId]
  429. ) {
  430. promises.push($loadUpdateChunk$(chunkId));
  431. currentUpdateChunks[chunkId] = true;
  432. }
  433. };
  434. }
  435. };
  436. };