Projekt

Obecné

Profil

Stáhnout (17 KB) Statistiky
| Větev: | Revize:
1
/*
2
	MIT License http://www.opensource.org/licenses/mit-license.php
3
	Author Tobias Koppers @sokra
4
*/
5
// eslint-disable no-unused-vars
6
var $hash$ = undefined;
7
var $requestTimeout$ = undefined;
8
var installedModules = undefined;
9
var $require$ = undefined;
10
var hotDownloadManifest = undefined;
11
var hotDownloadUpdateChunk = undefined;
12
var hotDisposeChunk = undefined;
13
var modules = undefined;
14
var chunkId = undefined;
15

    
16
module.exports = function() {
17
	var hotApplyOnUpdate = true;
18
	// eslint-disable-next-line no-unused-vars
19
	var hotCurrentHash = $hash$;
20
	var hotRequestTimeout = $requestTimeout$;
21
	var hotCurrentModuleData = {};
22
	var hotCurrentChildModule;
23
	// eslint-disable-next-line no-unused-vars
24
	var hotCurrentParents = [];
25
	// eslint-disable-next-line no-unused-vars
26
	var hotCurrentParentsTemp = [];
27

    
28
	// eslint-disable-next-line no-unused-vars
29
	function hotCreateRequire(moduleId) {
30
		var me = installedModules[moduleId];
31
		if (!me) return $require$;
32
		var fn = function(request) {
33
			if (me.hot.active) {
34
				if (installedModules[request]) {
35
					if (installedModules[request].parents.indexOf(moduleId) === -1) {
36
						installedModules[request].parents.push(moduleId);
37
					}
38
				} else {
39
					hotCurrentParents = [moduleId];
40
					hotCurrentChildModule = request;
41
				}
42
				if (me.children.indexOf(request) === -1) {
43
					me.children.push(request);
44
				}
45
			} else {
46
				console.warn(
47
					"[HMR] unexpected require(" +
48
						request +
49
						") from disposed module " +
50
						moduleId
51
				);
52
				hotCurrentParents = [];
53
			}
54
			return $require$(request);
55
		};
56
		var ObjectFactory = function ObjectFactory(name) {
57
			return {
58
				configurable: true,
59
				enumerable: true,
60
				get: function() {
61
					return $require$[name];
62
				},
63
				set: function(value) {
64
					$require$[name] = value;
65
				}
66
			};
67
		};
68
		for (var name in $require$) {
69
			if (
70
				Object.prototype.hasOwnProperty.call($require$, name) &&
71
				name !== "e" &&
72
				name !== "t"
73
			) {
74
				Object.defineProperty(fn, name, ObjectFactory(name));
75
			}
76
		}
77
		fn.e = function(chunkId) {
78
			if (hotStatus === "ready") hotSetStatus("prepare");
79
			hotChunksLoading++;
80
			return $require$.e(chunkId).then(finishChunkLoading, function(err) {
81
				finishChunkLoading();
82
				throw err;
83
			});
84

    
85
			function finishChunkLoading() {
86
				hotChunksLoading--;
87
				if (hotStatus === "prepare") {
88
					if (!hotWaitingFilesMap[chunkId]) {
89
						hotEnsureUpdateChunk(chunkId);
90
					}
91
					if (hotChunksLoading === 0 && hotWaitingFiles === 0) {
92
						hotUpdateDownloaded();
93
					}
94
				}
95
			}
96
		};
97
		fn.t = function(value, mode) {
98
			if (mode & 1) value = fn(value);
99
			return $require$.t(value, mode & ~1);
100
		};
101
		return fn;
102
	}
103

    
104
	// eslint-disable-next-line no-unused-vars
105
	function hotCreateModule(moduleId) {
106
		var hot = {
107
			// private stuff
108
			_acceptedDependencies: {},
109
			_declinedDependencies: {},
110
			_selfAccepted: false,
111
			_selfDeclined: false,
112
			_disposeHandlers: [],
113
			_main: hotCurrentChildModule !== moduleId,
114

    
115
			// Module API
116
			active: true,
117
			accept: function(dep, callback) {
118
				if (dep === undefined) hot._selfAccepted = true;
119
				else if (typeof dep === "function") hot._selfAccepted = dep;
120
				else if (typeof dep === "object")
121
					for (var i = 0; i < dep.length; i++)
122
						hot._acceptedDependencies[dep[i]] = callback || function() {};
123
				else hot._acceptedDependencies[dep] = callback || function() {};
124
			},
125
			decline: function(dep) {
126
				if (dep === undefined) hot._selfDeclined = true;
127
				else if (typeof dep === "object")
128
					for (var i = 0; i < dep.length; i++)
129
						hot._declinedDependencies[dep[i]] = true;
130
				else hot._declinedDependencies[dep] = true;
131
			},
132
			dispose: function(callback) {
133
				hot._disposeHandlers.push(callback);
134
			},
135
			addDisposeHandler: function(callback) {
136
				hot._disposeHandlers.push(callback);
137
			},
138
			removeDisposeHandler: function(callback) {
139
				var idx = hot._disposeHandlers.indexOf(callback);
140
				if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
141
			},
142

    
143
			// Management API
144
			check: hotCheck,
145
			apply: hotApply,
146
			status: function(l) {
147
				if (!l) return hotStatus;
148
				hotStatusHandlers.push(l);
149
			},
150
			addStatusHandler: function(l) {
151
				hotStatusHandlers.push(l);
152
			},
153
			removeStatusHandler: function(l) {
154
				var idx = hotStatusHandlers.indexOf(l);
155
				if (idx >= 0) hotStatusHandlers.splice(idx, 1);
156
			},
157

    
158
			//inherit from previous dispose call
159
			data: hotCurrentModuleData[moduleId]
160
		};
161
		hotCurrentChildModule = undefined;
162
		return hot;
163
	}
164

    
165
	var hotStatusHandlers = [];
166
	var hotStatus = "idle";
167

    
168
	function hotSetStatus(newStatus) {
169
		hotStatus = newStatus;
170
		for (var i = 0; i < hotStatusHandlers.length; i++)
171
			hotStatusHandlers[i].call(null, newStatus);
172
	}
173

    
174
	// while downloading
175
	var hotWaitingFiles = 0;
176
	var hotChunksLoading = 0;
177
	var hotWaitingFilesMap = {};
178
	var hotRequestedFilesMap = {};
179
	var hotAvailableFilesMap = {};
180
	var hotDeferred;
181

    
182
	// The update info
183
	var hotUpdate, hotUpdateNewHash;
184

    
185
	function toModuleId(id) {
186
		var isNumber = +id + "" === id;
187
		return isNumber ? +id : id;
188
	}
189

    
190
	function hotCheck(apply) {
191
		if (hotStatus !== "idle") {
192
			throw new Error("check() is only allowed in idle status");
193
		}
194
		hotApplyOnUpdate = apply;
195
		hotSetStatus("check");
196
		return hotDownloadManifest(hotRequestTimeout).then(function(update) {
197
			if (!update) {
198
				hotSetStatus("idle");
199
				return null;
200
			}
201
			hotRequestedFilesMap = {};
202
			hotWaitingFilesMap = {};
203
			hotAvailableFilesMap = update.c;
204
			hotUpdateNewHash = update.h;
205

    
206
			hotSetStatus("prepare");
207
			var promise = new Promise(function(resolve, reject) {
208
				hotDeferred = {
209
					resolve: resolve,
210
					reject: reject
211
				};
212
			});
213
			hotUpdate = {};
214
			/*foreachInstalledChunks*/
215
			// eslint-disable-next-line no-lone-blocks
216
			{
217
				hotEnsureUpdateChunk(chunkId);
218
			}
219
			if (
220
				hotStatus === "prepare" &&
221
				hotChunksLoading === 0 &&
222
				hotWaitingFiles === 0
223
			) {
224
				hotUpdateDownloaded();
225
			}
226
			return promise;
227
		});
228
	}
229

    
230
	// eslint-disable-next-line no-unused-vars
231
	function hotAddUpdateChunk(chunkId, moreModules) {
232
		if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
233
			return;
234
		hotRequestedFilesMap[chunkId] = false;
235
		for (var moduleId in moreModules) {
236
			if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
237
				hotUpdate[moduleId] = moreModules[moduleId];
238
			}
239
		}
240
		if (--hotWaitingFiles === 0 && hotChunksLoading === 0) {
241
			hotUpdateDownloaded();
242
		}
243
	}
244

    
245
	function hotEnsureUpdateChunk(chunkId) {
246
		if (!hotAvailableFilesMap[chunkId]) {
247
			hotWaitingFilesMap[chunkId] = true;
248
		} else {
249
			hotRequestedFilesMap[chunkId] = true;
250
			hotWaitingFiles++;
251
			hotDownloadUpdateChunk(chunkId);
252
		}
253
	}
254

    
255
	function hotUpdateDownloaded() {
256
		hotSetStatus("ready");
257
		var deferred = hotDeferred;
258
		hotDeferred = null;
259
		if (!deferred) return;
260
		if (hotApplyOnUpdate) {
261
			// Wrap deferred object in Promise to mark it as a well-handled Promise to
262
			// avoid triggering uncaught exception warning in Chrome.
263
			// See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
264
			Promise.resolve()
265
				.then(function() {
266
					return hotApply(hotApplyOnUpdate);
267
				})
268
				.then(
269
					function(result) {
270
						deferred.resolve(result);
271
					},
272
					function(err) {
273
						deferred.reject(err);
274
					}
275
				);
276
		} else {
277
			var outdatedModules = [];
278
			for (var id in hotUpdate) {
279
				if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
280
					outdatedModules.push(toModuleId(id));
281
				}
282
			}
283
			deferred.resolve(outdatedModules);
284
		}
285
	}
286

    
287
	function hotApply(options) {
288
		if (hotStatus !== "ready")
289
			throw new Error("apply() is only allowed in ready status");
290
		options = options || {};
291

    
292
		var cb;
293
		var i;
294
		var j;
295
		var module;
296
		var moduleId;
297

    
298
		function getAffectedStuff(updateModuleId) {
299
			var outdatedModules = [updateModuleId];
300
			var outdatedDependencies = {};
301

    
302
			var queue = outdatedModules.map(function(id) {
303
				return {
304
					chain: [id],
305
					id: id
306
				};
307
			});
308
			while (queue.length > 0) {
309
				var queueItem = queue.pop();
310
				var moduleId = queueItem.id;
311
				var chain = queueItem.chain;
312
				module = installedModules[moduleId];
313
				if (!module || module.hot._selfAccepted) continue;
314
				if (module.hot._selfDeclined) {
315
					return {
316
						type: "self-declined",
317
						chain: chain,
318
						moduleId: moduleId
319
					};
320
				}
321
				if (module.hot._main) {
322
					return {
323
						type: "unaccepted",
324
						chain: chain,
325
						moduleId: moduleId
326
					};
327
				}
328
				for (var i = 0; i < module.parents.length; i++) {
329
					var parentId = module.parents[i];
330
					var parent = installedModules[parentId];
331
					if (!parent) continue;
332
					if (parent.hot._declinedDependencies[moduleId]) {
333
						return {
334
							type: "declined",
335
							chain: chain.concat([parentId]),
336
							moduleId: moduleId,
337
							parentId: parentId
338
						};
339
					}
340
					if (outdatedModules.indexOf(parentId) !== -1) continue;
341
					if (parent.hot._acceptedDependencies[moduleId]) {
342
						if (!outdatedDependencies[parentId])
343
							outdatedDependencies[parentId] = [];
344
						addAllToSet(outdatedDependencies[parentId], [moduleId]);
345
						continue;
346
					}
347
					delete outdatedDependencies[parentId];
348
					outdatedModules.push(parentId);
349
					queue.push({
350
						chain: chain.concat([parentId]),
351
						id: parentId
352
					});
353
				}
354
			}
355

    
356
			return {
357
				type: "accepted",
358
				moduleId: updateModuleId,
359
				outdatedModules: outdatedModules,
360
				outdatedDependencies: outdatedDependencies
361
			};
362
		}
363

    
364
		function addAllToSet(a, b) {
365
			for (var i = 0; i < b.length; i++) {
366
				var item = b[i];
367
				if (a.indexOf(item) === -1) a.push(item);
368
			}
369
		}
370

    
371
		// at begin all updates modules are outdated
372
		// the "outdated" status can propagate to parents if they don't accept the children
373
		var outdatedDependencies = {};
374
		var outdatedModules = [];
375
		var appliedUpdate = {};
376

    
377
		var warnUnexpectedRequire = function warnUnexpectedRequire() {
378
			console.warn(
379
				"[HMR] unexpected require(" + result.moduleId + ") to disposed module"
380
			);
381
		};
382

    
383
		for (var id in hotUpdate) {
384
			if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
385
				moduleId = toModuleId(id);
386
				/** @type {TODO} */
387
				var result;
388
				if (hotUpdate[id]) {
389
					result = getAffectedStuff(moduleId);
390
				} else {
391
					result = {
392
						type: "disposed",
393
						moduleId: id
394
					};
395
				}
396
				/** @type {Error|false} */
397
				var abortError = false;
398
				var doApply = false;
399
				var doDispose = false;
400
				var chainInfo = "";
401
				if (result.chain) {
402
					chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
403
				}
404
				switch (result.type) {
405
					case "self-declined":
406
						if (options.onDeclined) options.onDeclined(result);
407
						if (!options.ignoreDeclined)
408
							abortError = new Error(
409
								"Aborted because of self decline: " +
410
									result.moduleId +
411
									chainInfo
412
							);
413
						break;
414
					case "declined":
415
						if (options.onDeclined) options.onDeclined(result);
416
						if (!options.ignoreDeclined)
417
							abortError = new Error(
418
								"Aborted because of declined dependency: " +
419
									result.moduleId +
420
									" in " +
421
									result.parentId +
422
									chainInfo
423
							);
424
						break;
425
					case "unaccepted":
426
						if (options.onUnaccepted) options.onUnaccepted(result);
427
						if (!options.ignoreUnaccepted)
428
							abortError = new Error(
429
								"Aborted because " + moduleId + " is not accepted" + chainInfo
430
							);
431
						break;
432
					case "accepted":
433
						if (options.onAccepted) options.onAccepted(result);
434
						doApply = true;
435
						break;
436
					case "disposed":
437
						if (options.onDisposed) options.onDisposed(result);
438
						doDispose = true;
439
						break;
440
					default:
441
						throw new Error("Unexception type " + result.type);
442
				}
443
				if (abortError) {
444
					hotSetStatus("abort");
445
					return Promise.reject(abortError);
446
				}
447
				if (doApply) {
448
					appliedUpdate[moduleId] = hotUpdate[moduleId];
449
					addAllToSet(outdatedModules, result.outdatedModules);
450
					for (moduleId in result.outdatedDependencies) {
451
						if (
452
							Object.prototype.hasOwnProperty.call(
453
								result.outdatedDependencies,
454
								moduleId
455
							)
456
						) {
457
							if (!outdatedDependencies[moduleId])
458
								outdatedDependencies[moduleId] = [];
459
							addAllToSet(
460
								outdatedDependencies[moduleId],
461
								result.outdatedDependencies[moduleId]
462
							);
463
						}
464
					}
465
				}
466
				if (doDispose) {
467
					addAllToSet(outdatedModules, [result.moduleId]);
468
					appliedUpdate[moduleId] = warnUnexpectedRequire;
469
				}
470
			}
471
		}
472

    
473
		// Store self accepted outdated modules to require them later by the module system
474
		var outdatedSelfAcceptedModules = [];
475
		for (i = 0; i < outdatedModules.length; i++) {
476
			moduleId = outdatedModules[i];
477
			if (
478
				installedModules[moduleId] &&
479
				installedModules[moduleId].hot._selfAccepted &&
480
				// removed self-accepted modules should not be required
481
				appliedUpdate[moduleId] !== warnUnexpectedRequire
482
			) {
483
				outdatedSelfAcceptedModules.push({
484
					module: moduleId,
485
					errorHandler: installedModules[moduleId].hot._selfAccepted
486
				});
487
			}
488
		}
489

    
490
		// Now in "dispose" phase
491
		hotSetStatus("dispose");
492
		Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
493
			if (hotAvailableFilesMap[chunkId] === false) {
494
				hotDisposeChunk(chunkId);
495
			}
496
		});
497

    
498
		var idx;
499
		var queue = outdatedModules.slice();
500
		while (queue.length > 0) {
501
			moduleId = queue.pop();
502
			module = installedModules[moduleId];
503
			if (!module) continue;
504

    
505
			var data = {};
506

    
507
			// Call dispose handlers
508
			var disposeHandlers = module.hot._disposeHandlers;
509
			for (j = 0; j < disposeHandlers.length; j++) {
510
				cb = disposeHandlers[j];
511
				cb(data);
512
			}
513
			hotCurrentModuleData[moduleId] = data;
514

    
515
			// disable module (this disables requires from this module)
516
			module.hot.active = false;
517

    
518
			// remove module from cache
519
			delete installedModules[moduleId];
520

    
521
			// when disposing there is no need to call dispose handler
522
			delete outdatedDependencies[moduleId];
523

    
524
			// remove "parents" references from all children
525
			for (j = 0; j < module.children.length; j++) {
526
				var child = installedModules[module.children[j]];
527
				if (!child) continue;
528
				idx = child.parents.indexOf(moduleId);
529
				if (idx >= 0) {
530
					child.parents.splice(idx, 1);
531
				}
532
			}
533
		}
534

    
535
		// remove outdated dependency from module children
536
		var dependency;
537
		var moduleOutdatedDependencies;
538
		for (moduleId in outdatedDependencies) {
539
			if (
540
				Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
541
			) {
542
				module = installedModules[moduleId];
543
				if (module) {
544
					moduleOutdatedDependencies = outdatedDependencies[moduleId];
545
					for (j = 0; j < moduleOutdatedDependencies.length; j++) {
546
						dependency = moduleOutdatedDependencies[j];
547
						idx = module.children.indexOf(dependency);
548
						if (idx >= 0) module.children.splice(idx, 1);
549
					}
550
				}
551
			}
552
		}
553

    
554
		// Now in "apply" phase
555
		hotSetStatus("apply");
556

    
557
		hotCurrentHash = hotUpdateNewHash;
558

    
559
		// insert new code
560
		for (moduleId in appliedUpdate) {
561
			if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
562
				modules[moduleId] = appliedUpdate[moduleId];
563
			}
564
		}
565

    
566
		// call accept handlers
567
		var error = null;
568
		for (moduleId in outdatedDependencies) {
569
			if (
570
				Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
571
			) {
572
				module = installedModules[moduleId];
573
				if (module) {
574
					moduleOutdatedDependencies = outdatedDependencies[moduleId];
575
					var callbacks = [];
576
					for (i = 0; i < moduleOutdatedDependencies.length; i++) {
577
						dependency = moduleOutdatedDependencies[i];
578
						cb = module.hot._acceptedDependencies[dependency];
579
						if (cb) {
580
							if (callbacks.indexOf(cb) !== -1) continue;
581
							callbacks.push(cb);
582
						}
583
					}
584
					for (i = 0; i < callbacks.length; i++) {
585
						cb = callbacks[i];
586
						try {
587
							cb(moduleOutdatedDependencies);
588
						} catch (err) {
589
							if (options.onErrored) {
590
								options.onErrored({
591
									type: "accept-errored",
592
									moduleId: moduleId,
593
									dependencyId: moduleOutdatedDependencies[i],
594
									error: err
595
								});
596
							}
597
							if (!options.ignoreErrored) {
598
								if (!error) error = err;
599
							}
600
						}
601
					}
602
				}
603
			}
604
		}
605

    
606
		// Load self accepted modules
607
		for (i = 0; i < outdatedSelfAcceptedModules.length; i++) {
608
			var item = outdatedSelfAcceptedModules[i];
609
			moduleId = item.module;
610
			hotCurrentParents = [moduleId];
611
			try {
612
				$require$(moduleId);
613
			} catch (err) {
614
				if (typeof item.errorHandler === "function") {
615
					try {
616
						item.errorHandler(err);
617
					} catch (err2) {
618
						if (options.onErrored) {
619
							options.onErrored({
620
								type: "self-accept-error-handler-errored",
621
								moduleId: moduleId,
622
								error: err2,
623
								originalError: err
624
							});
625
						}
626
						if (!options.ignoreErrored) {
627
							if (!error) error = err2;
628
						}
629
						if (!error) error = err;
630
					}
631
				} else {
632
					if (options.onErrored) {
633
						options.onErrored({
634
							type: "self-accept-errored",
635
							moduleId: moduleId,
636
							error: err
637
						});
638
					}
639
					if (!options.ignoreErrored) {
640
						if (!error) error = err;
641
					}
642
				}
643
			}
644
		}
645

    
646
		// handle errors in accept handlers and self accepted module load
647
		if (error) {
648
			hotSetStatus("fail");
649
			return Promise.reject(error);
650
		}
651

    
652
		hotSetStatus("idle");
653
		return new Promise(function(resolve) {
654
			resolve(outdatedModules);
655
		});
656
	}
657
};
(63-63/145)