JavascriptHotModuleReplacement.runtime.js 13 KB

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