webpack 3.5.6 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,602 +1,602 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
6
- module.exports = function() {
7
-
8
- var hotApplyOnUpdate = true;
9
- var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
10
- var hotRequestTimeout = $requestTimeout$;
11
- var hotCurrentModuleData = {};
12
- var hotCurrentChildModule; // eslint-disable-line no-unused-vars
13
- var hotCurrentParents = []; // eslint-disable-line no-unused-vars
14
- var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
15
-
16
- function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
17
- var me = installedModules[moduleId];
18
- if(!me) return $require$;
19
- var fn = function(request) {
20
- if(me.hot.active) {
21
- if(installedModules[request]) {
22
- if(installedModules[request].parents.indexOf(moduleId) < 0)
23
- installedModules[request].parents.push(moduleId);
24
- } else {
25
- hotCurrentParents = [moduleId];
26
- hotCurrentChildModule = request;
27
- }
28
- if(me.children.indexOf(request) < 0)
29
- me.children.push(request);
30
- } else {
31
- console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
32
- hotCurrentParents = [];
33
- }
34
- return $require$(request);
35
- };
36
- var ObjectFactory = function ObjectFactory(name) {
37
- return {
38
- configurable: true,
39
- enumerable: true,
40
- get: function() {
41
- return $require$[name];
42
- },
43
- set: function(value) {
44
- $require$[name] = value;
45
- }
46
- };
47
- };
48
- for(var name in $require$) {
49
- if(Object.prototype.hasOwnProperty.call($require$, name) && name !== "e") {
50
- Object.defineProperty(fn, name, ObjectFactory(name));
51
- }
52
- }
53
- fn.e = function(chunkId) {
54
- if(hotStatus === "ready")
55
- hotSetStatus("prepare");
56
- hotChunksLoading++;
57
- return $require$.e(chunkId).then(finishChunkLoading, function(err) {
58
- finishChunkLoading();
59
- throw err;
60
- });
61
-
62
- function finishChunkLoading() {
63
- hotChunksLoading--;
64
- if(hotStatus === "prepare") {
65
- if(!hotWaitingFilesMap[chunkId]) {
66
- hotEnsureUpdateChunk(chunkId);
67
- }
68
- if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
69
- hotUpdateDownloaded();
70
- }
71
- }
72
- }
73
- };
74
- return fn;
75
- }
76
-
77
- function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars
78
- var hot = {
79
- // private stuff
80
- _acceptedDependencies: {},
81
- _declinedDependencies: {},
82
- _selfAccepted: false,
83
- _selfDeclined: false,
84
- _disposeHandlers: [],
85
- _main: hotCurrentChildModule !== moduleId,
86
-
87
- // Module API
88
- active: true,
89
- accept: function(dep, callback) {
90
- if(typeof dep === "undefined")
91
- hot._selfAccepted = true;
92
- else if(typeof dep === "function")
93
- hot._selfAccepted = dep;
94
- else if(typeof dep === "object")
95
- for(var i = 0; i < dep.length; i++)
96
- hot._acceptedDependencies[dep[i]] = callback || function() {};
97
- else
98
- hot._acceptedDependencies[dep] = callback || function() {};
99
- },
100
- decline: function(dep) {
101
- if(typeof dep === "undefined")
102
- hot._selfDeclined = true;
103
- else if(typeof dep === "object")
104
- for(var i = 0; i < dep.length; i++)
105
- hot._declinedDependencies[dep[i]] = true;
106
- else
107
- hot._declinedDependencies[dep] = true;
108
- },
109
- dispose: function(callback) {
110
- hot._disposeHandlers.push(callback);
111
- },
112
- addDisposeHandler: function(callback) {
113
- hot._disposeHandlers.push(callback);
114
- },
115
- removeDisposeHandler: function(callback) {
116
- var idx = hot._disposeHandlers.indexOf(callback);
117
- if(idx >= 0) hot._disposeHandlers.splice(idx, 1);
118
- },
119
-
120
- // Management API
121
- check: hotCheck,
122
- apply: hotApply,
123
- status: function(l) {
124
- if(!l) return hotStatus;
125
- hotStatusHandlers.push(l);
126
- },
127
- addStatusHandler: function(l) {
128
- hotStatusHandlers.push(l);
129
- },
130
- removeStatusHandler: function(l) {
131
- var idx = hotStatusHandlers.indexOf(l);
132
- if(idx >= 0) hotStatusHandlers.splice(idx, 1);
133
- },
134
-
135
- //inherit from previous dispose call
136
- data: hotCurrentModuleData[moduleId]
137
- };
138
- hotCurrentChildModule = undefined;
139
- return hot;
140
- }
141
-
142
- var hotStatusHandlers = [];
143
- var hotStatus = "idle";
144
-
145
- function hotSetStatus(newStatus) {
146
- hotStatus = newStatus;
147
- for(var i = 0; i < hotStatusHandlers.length; i++)
148
- hotStatusHandlers[i].call(null, newStatus);
149
- }
150
-
151
- // while downloading
152
- var hotWaitingFiles = 0;
153
- var hotChunksLoading = 0;
154
- var hotWaitingFilesMap = {};
155
- var hotRequestedFilesMap = {};
156
- var hotAvailableFilesMap = {};
157
- var hotDeferred;
158
-
159
- // The update info
160
- var hotUpdate, hotUpdateNewHash;
161
-
162
- function toModuleId(id) {
163
- var isNumber = (+id) + "" === id;
164
- return isNumber ? +id : id;
165
- }
166
-
167
- function hotCheck(apply) {
168
- if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
169
- hotApplyOnUpdate = apply;
170
- hotSetStatus("check");
171
- return hotDownloadManifest(hotRequestTimeout).then(function(update) {
172
- if(!update) {
173
- hotSetStatus("idle");
174
- return null;
175
- }
176
- hotRequestedFilesMap = {};
177
- hotWaitingFilesMap = {};
178
- hotAvailableFilesMap = update.c;
179
- hotUpdateNewHash = update.h;
180
-
181
- hotSetStatus("prepare");
182
- var promise = new Promise(function(resolve, reject) {
183
- hotDeferred = {
184
- resolve: resolve,
185
- reject: reject
186
- };
187
- });
188
- hotUpdate = {};
189
- /*foreachInstalledChunks*/
190
- { // eslint-disable-line no-lone-blocks
191
- /*globals chunkId */
192
- hotEnsureUpdateChunk(chunkId);
193
- }
194
- if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
195
- hotUpdateDownloaded();
196
- }
197
- return promise;
198
- });
199
- }
200
-
201
- function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars
202
- if(!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
203
- return;
204
- hotRequestedFilesMap[chunkId] = false;
205
- for(var moduleId in moreModules) {
206
- if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
207
- hotUpdate[moduleId] = moreModules[moduleId];
208
- }
209
- }
210
- if(--hotWaitingFiles === 0 && hotChunksLoading === 0) {
211
- hotUpdateDownloaded();
212
- }
213
- }
214
-
215
- function hotEnsureUpdateChunk(chunkId) {
216
- if(!hotAvailableFilesMap[chunkId]) {
217
- hotWaitingFilesMap[chunkId] = true;
218
- } else {
219
- hotRequestedFilesMap[chunkId] = true;
220
- hotWaitingFiles++;
221
- hotDownloadUpdateChunk(chunkId);
222
- }
223
- }
224
-
225
- function hotUpdateDownloaded() {
226
- hotSetStatus("ready");
227
- var deferred = hotDeferred;
228
- hotDeferred = null;
229
- if(!deferred) return;
230
- if(hotApplyOnUpdate) {
231
- // Wrap deferred object in Promise to mark it as a well-handled Promise to
232
- // avoid triggering uncaught exception warning in Chrome.
233
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
234
- Promise.resolve().then(function() {
235
- return hotApply(hotApplyOnUpdate);
236
- }).then(
237
- function(result) {
238
- deferred.resolve(result);
239
- },
240
- function(err) {
241
- deferred.reject(err);
242
- }
243
- );
244
- } else {
245
- var outdatedModules = [];
246
- for(var id in hotUpdate) {
247
- if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
248
- outdatedModules.push(toModuleId(id));
249
- }
250
- }
251
- deferred.resolve(outdatedModules);
252
- }
253
- }
254
-
255
- function hotApply(options) {
256
- if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
257
- options = options || {};
258
-
259
- var cb;
260
- var i;
261
- var j;
262
- var module;
263
- var moduleId;
264
-
265
- function getAffectedStuff(updateModuleId) {
266
- var outdatedModules = [updateModuleId];
267
- var outdatedDependencies = {};
268
-
269
- var queue = outdatedModules.slice().map(function(id) {
270
- return {
271
- chain: [id],
272
- id: id
273
- };
274
- });
275
- while(queue.length > 0) {
276
- var queueItem = queue.pop();
277
- var moduleId = queueItem.id;
278
- var chain = queueItem.chain;
279
- module = installedModules[moduleId];
280
- if(!module || module.hot._selfAccepted)
281
- continue;
282
- if(module.hot._selfDeclined) {
283
- return {
284
- type: "self-declined",
285
- chain: chain,
286
- moduleId: moduleId
287
- };
288
- }
289
- if(module.hot._main) {
290
- return {
291
- type: "unaccepted",
292
- chain: chain,
293
- moduleId: moduleId
294
- };
295
- }
296
- for(var i = 0; i < module.parents.length; i++) {
297
- var parentId = module.parents[i];
298
- var parent = installedModules[parentId];
299
- if(!parent) continue;
300
- if(parent.hot._declinedDependencies[moduleId]) {
301
- return {
302
- type: "declined",
303
- chain: chain.concat([parentId]),
304
- moduleId: moduleId,
305
- parentId: parentId
306
- };
307
- }
308
- if(outdatedModules.indexOf(parentId) >= 0) continue;
309
- if(parent.hot._acceptedDependencies[moduleId]) {
310
- if(!outdatedDependencies[parentId])
311
- outdatedDependencies[parentId] = [];
312
- addAllToSet(outdatedDependencies[parentId], [moduleId]);
313
- continue;
314
- }
315
- delete outdatedDependencies[parentId];
316
- outdatedModules.push(parentId);
317
- queue.push({
318
- chain: chain.concat([parentId]),
319
- id: parentId
320
- });
321
- }
322
- }
323
-
324
- return {
325
- type: "accepted",
326
- moduleId: updateModuleId,
327
- outdatedModules: outdatedModules,
328
- outdatedDependencies: outdatedDependencies
329
- };
330
- }
331
-
332
- function addAllToSet(a, b) {
333
- for(var i = 0; i < b.length; i++) {
334
- var item = b[i];
335
- if(a.indexOf(item) < 0)
336
- a.push(item);
337
- }
338
- }
339
-
340
- // at begin all updates modules are outdated
341
- // the "outdated" status can propagate to parents if they don't accept the children
342
- var outdatedDependencies = {};
343
- var outdatedModules = [];
344
- var appliedUpdate = {};
345
-
346
- var warnUnexpectedRequire = function warnUnexpectedRequire() {
347
- console.warn("[HMR] unexpected require(" + result.moduleId + ") to disposed module");
348
- };
349
-
350
- for(var id in hotUpdate) {
351
- if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
352
- moduleId = toModuleId(id);
353
- var result;
354
- if(hotUpdate[id]) {
355
- result = getAffectedStuff(moduleId);
356
- } else {
357
- result = {
358
- type: "disposed",
359
- moduleId: id
360
- };
361
- }
362
- var abortError = false;
363
- var doApply = false;
364
- var doDispose = false;
365
- var chainInfo = "";
366
- if(result.chain) {
367
- chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
368
- }
369
- switch(result.type) {
370
- case "self-declined":
371
- if(options.onDeclined)
372
- options.onDeclined(result);
373
- if(!options.ignoreDeclined)
374
- abortError = new Error("Aborted because of self decline: " + result.moduleId + chainInfo);
375
- break;
376
- case "declined":
377
- if(options.onDeclined)
378
- options.onDeclined(result);
379
- if(!options.ignoreDeclined)
380
- abortError = new Error("Aborted because of declined dependency: " + result.moduleId + " in " + result.parentId + chainInfo);
381
- break;
382
- case "unaccepted":
383
- if(options.onUnaccepted)
384
- options.onUnaccepted(result);
385
- if(!options.ignoreUnaccepted)
386
- abortError = new Error("Aborted because " + moduleId + " is not accepted" + chainInfo);
387
- break;
388
- case "accepted":
389
- if(options.onAccepted)
390
- options.onAccepted(result);
391
- doApply = true;
392
- break;
393
- case "disposed":
394
- if(options.onDisposed)
395
- options.onDisposed(result);
396
- doDispose = true;
397
- break;
398
- default:
399
- throw new Error("Unexception type " + result.type);
400
- }
401
- if(abortError) {
402
- hotSetStatus("abort");
403
- return Promise.reject(abortError);
404
- }
405
- if(doApply) {
406
- appliedUpdate[moduleId] = hotUpdate[moduleId];
407
- addAllToSet(outdatedModules, result.outdatedModules);
408
- for(moduleId in result.outdatedDependencies) {
409
- if(Object.prototype.hasOwnProperty.call(result.outdatedDependencies, moduleId)) {
410
- if(!outdatedDependencies[moduleId])
411
- outdatedDependencies[moduleId] = [];
412
- addAllToSet(outdatedDependencies[moduleId], result.outdatedDependencies[moduleId]);
413
- }
414
- }
415
- }
416
- if(doDispose) {
417
- addAllToSet(outdatedModules, [result.moduleId]);
418
- appliedUpdate[moduleId] = warnUnexpectedRequire;
419
- }
420
- }
421
- }
422
-
423
- // Store self accepted outdated modules to require them later by the module system
424
- var outdatedSelfAcceptedModules = [];
425
- for(i = 0; i < outdatedModules.length; i++) {
426
- moduleId = outdatedModules[i];
427
- if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
428
- outdatedSelfAcceptedModules.push({
429
- module: moduleId,
430
- errorHandler: installedModules[moduleId].hot._selfAccepted
431
- });
432
- }
433
-
434
- // Now in "dispose" phase
435
- hotSetStatus("dispose");
436
- Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
437
- if(hotAvailableFilesMap[chunkId] === false) {
438
- hotDisposeChunk(chunkId);
439
- }
440
- });
441
-
442
- var idx;
443
- var queue = outdatedModules.slice();
444
- while(queue.length > 0) {
445
- moduleId = queue.pop();
446
- module = installedModules[moduleId];
447
- if(!module) continue;
448
-
449
- var data = {};
450
-
451
- // Call dispose handlers
452
- var disposeHandlers = module.hot._disposeHandlers;
453
- for(j = 0; j < disposeHandlers.length; j++) {
454
- cb = disposeHandlers[j];
455
- cb(data);
456
- }
457
- hotCurrentModuleData[moduleId] = data;
458
-
459
- // disable module (this disables requires from this module)
460
- module.hot.active = false;
461
-
462
- // remove module from cache
463
- delete installedModules[moduleId];
464
-
465
- // when disposing there is no need to call dispose handler
466
- delete outdatedDependencies[moduleId];
467
-
468
- // remove "parents" references from all children
469
- for(j = 0; j < module.children.length; j++) {
470
- var child = installedModules[module.children[j]];
471
- if(!child) continue;
472
- idx = child.parents.indexOf(moduleId);
473
- if(idx >= 0) {
474
- child.parents.splice(idx, 1);
475
- }
476
- }
477
- }
478
-
479
- // remove outdated dependency from module children
480
- var dependency;
481
- var moduleOutdatedDependencies;
482
- for(moduleId in outdatedDependencies) {
483
- if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
484
- module = installedModules[moduleId];
485
- if(module) {
486
- moduleOutdatedDependencies = outdatedDependencies[moduleId];
487
- for(j = 0; j < moduleOutdatedDependencies.length; j++) {
488
- dependency = moduleOutdatedDependencies[j];
489
- idx = module.children.indexOf(dependency);
490
- if(idx >= 0) module.children.splice(idx, 1);
491
- }
492
- }
493
- }
494
- }
495
-
496
- // Not in "apply" phase
497
- hotSetStatus("apply");
498
-
499
- hotCurrentHash = hotUpdateNewHash;
500
-
501
- // insert new code
502
- for(moduleId in appliedUpdate) {
503
- if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
504
- modules[moduleId] = appliedUpdate[moduleId];
505
- }
506
- }
507
-
508
- // call accept handlers
509
- var error = null;
510
- for(moduleId in outdatedDependencies) {
511
- if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
512
- module = installedModules[moduleId];
513
- if(module) {
514
- moduleOutdatedDependencies = outdatedDependencies[moduleId];
515
- var callbacks = [];
516
- for(i = 0; i < moduleOutdatedDependencies.length; i++) {
517
- dependency = moduleOutdatedDependencies[i];
518
- cb = module.hot._acceptedDependencies[dependency];
519
- if(cb) {
520
- if(callbacks.indexOf(cb) >= 0) continue;
521
- callbacks.push(cb);
522
- }
523
- }
524
- for(i = 0; i < callbacks.length; i++) {
525
- cb = callbacks[i];
526
- try {
527
- cb(moduleOutdatedDependencies);
528
- } catch(err) {
529
- if(options.onErrored) {
530
- options.onErrored({
531
- type: "accept-errored",
532
- moduleId: moduleId,
533
- dependencyId: moduleOutdatedDependencies[i],
534
- error: err
535
- });
536
- }
537
- if(!options.ignoreErrored) {
538
- if(!error)
539
- error = err;
540
- }
541
- }
542
- }
543
- }
544
- }
545
- }
546
-
547
- // Load self accepted modules
548
- for(i = 0; i < outdatedSelfAcceptedModules.length; i++) {
549
- var item = outdatedSelfAcceptedModules[i];
550
- moduleId = item.module;
551
- hotCurrentParents = [moduleId];
552
- try {
553
- $require$(moduleId);
554
- } catch(err) {
555
- if(typeof item.errorHandler === "function") {
556
- try {
557
- item.errorHandler(err);
558
- } catch(err2) {
559
- if(options.onErrored) {
560
- options.onErrored({
561
- type: "self-accept-error-handler-errored",
562
- moduleId: moduleId,
563
- error: err2,
564
- orginalError: err, // TODO remove in webpack 4
565
- originalError: err
566
- });
567
- }
568
- if(!options.ignoreErrored) {
569
- if(!error)
570
- error = err2;
571
- }
572
- if(!error)
573
- error = err;
574
- }
575
- } else {
576
- if(options.onErrored) {
577
- options.onErrored({
578
- type: "self-accept-errored",
579
- moduleId: moduleId,
580
- error: err
581
- });
582
- }
583
- if(!options.ignoreErrored) {
584
- if(!error)
585
- error = err;
586
- }
587
- }
588
- }
589
- }
590
-
591
- // handle errors in accept handlers and self accepted module load
592
- if(error) {
593
- hotSetStatus("fail");
594
- return Promise.reject(error);
595
- }
596
-
597
- hotSetStatus("idle");
598
- return new Promise(function(resolve) {
599
- resolve(outdatedModules);
600
- });
601
- }
602
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
6
+ module.exports = function() {
7
+
8
+ var hotApplyOnUpdate = true;
9
+ var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
10
+ var hotRequestTimeout = $requestTimeout$;
11
+ var hotCurrentModuleData = {};
12
+ var hotCurrentChildModule; // eslint-disable-line no-unused-vars
13
+ var hotCurrentParents = []; // eslint-disable-line no-unused-vars
14
+ var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
15
+
16
+ function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
17
+ var me = installedModules[moduleId];
18
+ if(!me) return $require$;
19
+ var fn = function(request) {
20
+ if(me.hot.active) {
21
+ if(installedModules[request]) {
22
+ if(installedModules[request].parents.indexOf(moduleId) < 0)
23
+ installedModules[request].parents.push(moduleId);
24
+ } else {
25
+ hotCurrentParents = [moduleId];
26
+ hotCurrentChildModule = request;
27
+ }
28
+ if(me.children.indexOf(request) < 0)
29
+ me.children.push(request);
30
+ } else {
31
+ console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
32
+ hotCurrentParents = [];
33
+ }
34
+ return $require$(request);
35
+ };
36
+ var ObjectFactory = function ObjectFactory(name) {
37
+ return {
38
+ configurable: true,
39
+ enumerable: true,
40
+ get: function() {
41
+ return $require$[name];
42
+ },
43
+ set: function(value) {
44
+ $require$[name] = value;
45
+ }
46
+ };
47
+ };
48
+ for(var name in $require$) {
49
+ if(Object.prototype.hasOwnProperty.call($require$, name) && name !== "e") {
50
+ Object.defineProperty(fn, name, ObjectFactory(name));
51
+ }
52
+ }
53
+ fn.e = function(chunkId) {
54
+ if(hotStatus === "ready")
55
+ hotSetStatus("prepare");
56
+ hotChunksLoading++;
57
+ return $require$.e(chunkId).then(finishChunkLoading, function(err) {
58
+ finishChunkLoading();
59
+ throw err;
60
+ });
61
+
62
+ function finishChunkLoading() {
63
+ hotChunksLoading--;
64
+ if(hotStatus === "prepare") {
65
+ if(!hotWaitingFilesMap[chunkId]) {
66
+ hotEnsureUpdateChunk(chunkId);
67
+ }
68
+ if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
69
+ hotUpdateDownloaded();
70
+ }
71
+ }
72
+ }
73
+ };
74
+ return fn;
75
+ }
76
+
77
+ function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars
78
+ var hot = {
79
+ // private stuff
80
+ _acceptedDependencies: {},
81
+ _declinedDependencies: {},
82
+ _selfAccepted: false,
83
+ _selfDeclined: false,
84
+ _disposeHandlers: [],
85
+ _main: hotCurrentChildModule !== moduleId,
86
+
87
+ // Module API
88
+ active: true,
89
+ accept: function(dep, callback) {
90
+ if(typeof dep === "undefined")
91
+ hot._selfAccepted = true;
92
+ else if(typeof dep === "function")
93
+ hot._selfAccepted = dep;
94
+ else if(typeof dep === "object")
95
+ for(var i = 0; i < dep.length; i++)
96
+ hot._acceptedDependencies[dep[i]] = callback || function() {};
97
+ else
98
+ hot._acceptedDependencies[dep] = callback || function() {};
99
+ },
100
+ decline: function(dep) {
101
+ if(typeof dep === "undefined")
102
+ hot._selfDeclined = true;
103
+ else if(typeof dep === "object")
104
+ for(var i = 0; i < dep.length; i++)
105
+ hot._declinedDependencies[dep[i]] = true;
106
+ else
107
+ hot._declinedDependencies[dep] = true;
108
+ },
109
+ dispose: function(callback) {
110
+ hot._disposeHandlers.push(callback);
111
+ },
112
+ addDisposeHandler: function(callback) {
113
+ hot._disposeHandlers.push(callback);
114
+ },
115
+ removeDisposeHandler: function(callback) {
116
+ var idx = hot._disposeHandlers.indexOf(callback);
117
+ if(idx >= 0) hot._disposeHandlers.splice(idx, 1);
118
+ },
119
+
120
+ // Management API
121
+ check: hotCheck,
122
+ apply: hotApply,
123
+ status: function(l) {
124
+ if(!l) return hotStatus;
125
+ hotStatusHandlers.push(l);
126
+ },
127
+ addStatusHandler: function(l) {
128
+ hotStatusHandlers.push(l);
129
+ },
130
+ removeStatusHandler: function(l) {
131
+ var idx = hotStatusHandlers.indexOf(l);
132
+ if(idx >= 0) hotStatusHandlers.splice(idx, 1);
133
+ },
134
+
135
+ //inherit from previous dispose call
136
+ data: hotCurrentModuleData[moduleId]
137
+ };
138
+ hotCurrentChildModule = undefined;
139
+ return hot;
140
+ }
141
+
142
+ var hotStatusHandlers = [];
143
+ var hotStatus = "idle";
144
+
145
+ function hotSetStatus(newStatus) {
146
+ hotStatus = newStatus;
147
+ for(var i = 0; i < hotStatusHandlers.length; i++)
148
+ hotStatusHandlers[i].call(null, newStatus);
149
+ }
150
+
151
+ // while downloading
152
+ var hotWaitingFiles = 0;
153
+ var hotChunksLoading = 0;
154
+ var hotWaitingFilesMap = {};
155
+ var hotRequestedFilesMap = {};
156
+ var hotAvailableFilesMap = {};
157
+ var hotDeferred;
158
+
159
+ // The update info
160
+ var hotUpdate, hotUpdateNewHash;
161
+
162
+ function toModuleId(id) {
163
+ var isNumber = (+id) + "" === id;
164
+ return isNumber ? +id : id;
165
+ }
166
+
167
+ function hotCheck(apply) {
168
+ if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
169
+ hotApplyOnUpdate = apply;
170
+ hotSetStatus("check");
171
+ return hotDownloadManifest(hotRequestTimeout).then(function(update) {
172
+ if(!update) {
173
+ hotSetStatus("idle");
174
+ return null;
175
+ }
176
+ hotRequestedFilesMap = {};
177
+ hotWaitingFilesMap = {};
178
+ hotAvailableFilesMap = update.c;
179
+ hotUpdateNewHash = update.h;
180
+
181
+ hotSetStatus("prepare");
182
+ var promise = new Promise(function(resolve, reject) {
183
+ hotDeferred = {
184
+ resolve: resolve,
185
+ reject: reject
186
+ };
187
+ });
188
+ hotUpdate = {};
189
+ /*foreachInstalledChunks*/
190
+ { // eslint-disable-line no-lone-blocks
191
+ /*globals chunkId */
192
+ hotEnsureUpdateChunk(chunkId);
193
+ }
194
+ if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
195
+ hotUpdateDownloaded();
196
+ }
197
+ return promise;
198
+ });
199
+ }
200
+
201
+ function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars
202
+ if(!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
203
+ return;
204
+ hotRequestedFilesMap[chunkId] = false;
205
+ for(var moduleId in moreModules) {
206
+ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
207
+ hotUpdate[moduleId] = moreModules[moduleId];
208
+ }
209
+ }
210
+ if(--hotWaitingFiles === 0 && hotChunksLoading === 0) {
211
+ hotUpdateDownloaded();
212
+ }
213
+ }
214
+
215
+ function hotEnsureUpdateChunk(chunkId) {
216
+ if(!hotAvailableFilesMap[chunkId]) {
217
+ hotWaitingFilesMap[chunkId] = true;
218
+ } else {
219
+ hotRequestedFilesMap[chunkId] = true;
220
+ hotWaitingFiles++;
221
+ hotDownloadUpdateChunk(chunkId);
222
+ }
223
+ }
224
+
225
+ function hotUpdateDownloaded() {
226
+ hotSetStatus("ready");
227
+ var deferred = hotDeferred;
228
+ hotDeferred = null;
229
+ if(!deferred) return;
230
+ if(hotApplyOnUpdate) {
231
+ // Wrap deferred object in Promise to mark it as a well-handled Promise to
232
+ // avoid triggering uncaught exception warning in Chrome.
233
+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
234
+ Promise.resolve().then(function() {
235
+ return hotApply(hotApplyOnUpdate);
236
+ }).then(
237
+ function(result) {
238
+ deferred.resolve(result);
239
+ },
240
+ function(err) {
241
+ deferred.reject(err);
242
+ }
243
+ );
244
+ } else {
245
+ var outdatedModules = [];
246
+ for(var id in hotUpdate) {
247
+ if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
248
+ outdatedModules.push(toModuleId(id));
249
+ }
250
+ }
251
+ deferred.resolve(outdatedModules);
252
+ }
253
+ }
254
+
255
+ function hotApply(options) {
256
+ if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
257
+ options = options || {};
258
+
259
+ var cb;
260
+ var i;
261
+ var j;
262
+ var module;
263
+ var moduleId;
264
+
265
+ function getAffectedStuff(updateModuleId) {
266
+ var outdatedModules = [updateModuleId];
267
+ var outdatedDependencies = {};
268
+
269
+ var queue = outdatedModules.slice().map(function(id) {
270
+ return {
271
+ chain: [id],
272
+ id: id
273
+ };
274
+ });
275
+ while(queue.length > 0) {
276
+ var queueItem = queue.pop();
277
+ var moduleId = queueItem.id;
278
+ var chain = queueItem.chain;
279
+ module = installedModules[moduleId];
280
+ if(!module || module.hot._selfAccepted)
281
+ continue;
282
+ if(module.hot._selfDeclined) {
283
+ return {
284
+ type: "self-declined",
285
+ chain: chain,
286
+ moduleId: moduleId
287
+ };
288
+ }
289
+ if(module.hot._main) {
290
+ return {
291
+ type: "unaccepted",
292
+ chain: chain,
293
+ moduleId: moduleId
294
+ };
295
+ }
296
+ for(var i = 0; i < module.parents.length; i++) {
297
+ var parentId = module.parents[i];
298
+ var parent = installedModules[parentId];
299
+ if(!parent) continue;
300
+ if(parent.hot._declinedDependencies[moduleId]) {
301
+ return {
302
+ type: "declined",
303
+ chain: chain.concat([parentId]),
304
+ moduleId: moduleId,
305
+ parentId: parentId
306
+ };
307
+ }
308
+ if(outdatedModules.indexOf(parentId) >= 0) continue;
309
+ if(parent.hot._acceptedDependencies[moduleId]) {
310
+ if(!outdatedDependencies[parentId])
311
+ outdatedDependencies[parentId] = [];
312
+ addAllToSet(outdatedDependencies[parentId], [moduleId]);
313
+ continue;
314
+ }
315
+ delete outdatedDependencies[parentId];
316
+ outdatedModules.push(parentId);
317
+ queue.push({
318
+ chain: chain.concat([parentId]),
319
+ id: parentId
320
+ });
321
+ }
322
+ }
323
+
324
+ return {
325
+ type: "accepted",
326
+ moduleId: updateModuleId,
327
+ outdatedModules: outdatedModules,
328
+ outdatedDependencies: outdatedDependencies
329
+ };
330
+ }
331
+
332
+ function addAllToSet(a, b) {
333
+ for(var i = 0; i < b.length; i++) {
334
+ var item = b[i];
335
+ if(a.indexOf(item) < 0)
336
+ a.push(item);
337
+ }
338
+ }
339
+
340
+ // at begin all updates modules are outdated
341
+ // the "outdated" status can propagate to parents if they don't accept the children
342
+ var outdatedDependencies = {};
343
+ var outdatedModules = [];
344
+ var appliedUpdate = {};
345
+
346
+ var warnUnexpectedRequire = function warnUnexpectedRequire() {
347
+ console.warn("[HMR] unexpected require(" + result.moduleId + ") to disposed module");
348
+ };
349
+
350
+ for(var id in hotUpdate) {
351
+ if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
352
+ moduleId = toModuleId(id);
353
+ var result;
354
+ if(hotUpdate[id]) {
355
+ result = getAffectedStuff(moduleId);
356
+ } else {
357
+ result = {
358
+ type: "disposed",
359
+ moduleId: id
360
+ };
361
+ }
362
+ var abortError = false;
363
+ var doApply = false;
364
+ var doDispose = false;
365
+ var chainInfo = "";
366
+ if(result.chain) {
367
+ chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
368
+ }
369
+ switch(result.type) {
370
+ case "self-declined":
371
+ if(options.onDeclined)
372
+ options.onDeclined(result);
373
+ if(!options.ignoreDeclined)
374
+ abortError = new Error("Aborted because of self decline: " + result.moduleId + chainInfo);
375
+ break;
376
+ case "declined":
377
+ if(options.onDeclined)
378
+ options.onDeclined(result);
379
+ if(!options.ignoreDeclined)
380
+ abortError = new Error("Aborted because of declined dependency: " + result.moduleId + " in " + result.parentId + chainInfo);
381
+ break;
382
+ case "unaccepted":
383
+ if(options.onUnaccepted)
384
+ options.onUnaccepted(result);
385
+ if(!options.ignoreUnaccepted)
386
+ abortError = new Error("Aborted because " + moduleId + " is not accepted" + chainInfo);
387
+ break;
388
+ case "accepted":
389
+ if(options.onAccepted)
390
+ options.onAccepted(result);
391
+ doApply = true;
392
+ break;
393
+ case "disposed":
394
+ if(options.onDisposed)
395
+ options.onDisposed(result);
396
+ doDispose = true;
397
+ break;
398
+ default:
399
+ throw new Error("Unexception type " + result.type);
400
+ }
401
+ if(abortError) {
402
+ hotSetStatus("abort");
403
+ return Promise.reject(abortError);
404
+ }
405
+ if(doApply) {
406
+ appliedUpdate[moduleId] = hotUpdate[moduleId];
407
+ addAllToSet(outdatedModules, result.outdatedModules);
408
+ for(moduleId in result.outdatedDependencies) {
409
+ if(Object.prototype.hasOwnProperty.call(result.outdatedDependencies, moduleId)) {
410
+ if(!outdatedDependencies[moduleId])
411
+ outdatedDependencies[moduleId] = [];
412
+ addAllToSet(outdatedDependencies[moduleId], result.outdatedDependencies[moduleId]);
413
+ }
414
+ }
415
+ }
416
+ if(doDispose) {
417
+ addAllToSet(outdatedModules, [result.moduleId]);
418
+ appliedUpdate[moduleId] = warnUnexpectedRequire;
419
+ }
420
+ }
421
+ }
422
+
423
+ // Store self accepted outdated modules to require them later by the module system
424
+ var outdatedSelfAcceptedModules = [];
425
+ for(i = 0; i < outdatedModules.length; i++) {
426
+ moduleId = outdatedModules[i];
427
+ if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
428
+ outdatedSelfAcceptedModules.push({
429
+ module: moduleId,
430
+ errorHandler: installedModules[moduleId].hot._selfAccepted
431
+ });
432
+ }
433
+
434
+ // Now in "dispose" phase
435
+ hotSetStatus("dispose");
436
+ Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
437
+ if(hotAvailableFilesMap[chunkId] === false) {
438
+ hotDisposeChunk(chunkId);
439
+ }
440
+ });
441
+
442
+ var idx;
443
+ var queue = outdatedModules.slice();
444
+ while(queue.length > 0) {
445
+ moduleId = queue.pop();
446
+ module = installedModules[moduleId];
447
+ if(!module) continue;
448
+
449
+ var data = {};
450
+
451
+ // Call dispose handlers
452
+ var disposeHandlers = module.hot._disposeHandlers;
453
+ for(j = 0; j < disposeHandlers.length; j++) {
454
+ cb = disposeHandlers[j];
455
+ cb(data);
456
+ }
457
+ hotCurrentModuleData[moduleId] = data;
458
+
459
+ // disable module (this disables requires from this module)
460
+ module.hot.active = false;
461
+
462
+ // remove module from cache
463
+ delete installedModules[moduleId];
464
+
465
+ // when disposing there is no need to call dispose handler
466
+ delete outdatedDependencies[moduleId];
467
+
468
+ // remove "parents" references from all children
469
+ for(j = 0; j < module.children.length; j++) {
470
+ var child = installedModules[module.children[j]];
471
+ if(!child) continue;
472
+ idx = child.parents.indexOf(moduleId);
473
+ if(idx >= 0) {
474
+ child.parents.splice(idx, 1);
475
+ }
476
+ }
477
+ }
478
+
479
+ // remove outdated dependency from module children
480
+ var dependency;
481
+ var moduleOutdatedDependencies;
482
+ for(moduleId in outdatedDependencies) {
483
+ if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
484
+ module = installedModules[moduleId];
485
+ if(module) {
486
+ moduleOutdatedDependencies = outdatedDependencies[moduleId];
487
+ for(j = 0; j < moduleOutdatedDependencies.length; j++) {
488
+ dependency = moduleOutdatedDependencies[j];
489
+ idx = module.children.indexOf(dependency);
490
+ if(idx >= 0) module.children.splice(idx, 1);
491
+ }
492
+ }
493
+ }
494
+ }
495
+
496
+ // Not in "apply" phase
497
+ hotSetStatus("apply");
498
+
499
+ hotCurrentHash = hotUpdateNewHash;
500
+
501
+ // insert new code
502
+ for(moduleId in appliedUpdate) {
503
+ if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
504
+ modules[moduleId] = appliedUpdate[moduleId];
505
+ }
506
+ }
507
+
508
+ // call accept handlers
509
+ var error = null;
510
+ for(moduleId in outdatedDependencies) {
511
+ if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
512
+ module = installedModules[moduleId];
513
+ if(module) {
514
+ moduleOutdatedDependencies = outdatedDependencies[moduleId];
515
+ var callbacks = [];
516
+ for(i = 0; i < moduleOutdatedDependencies.length; i++) {
517
+ dependency = moduleOutdatedDependencies[i];
518
+ cb = module.hot._acceptedDependencies[dependency];
519
+ if(cb) {
520
+ if(callbacks.indexOf(cb) >= 0) continue;
521
+ callbacks.push(cb);
522
+ }
523
+ }
524
+ for(i = 0; i < callbacks.length; i++) {
525
+ cb = callbacks[i];
526
+ try {
527
+ cb(moduleOutdatedDependencies);
528
+ } catch(err) {
529
+ if(options.onErrored) {
530
+ options.onErrored({
531
+ type: "accept-errored",
532
+ moduleId: moduleId,
533
+ dependencyId: moduleOutdatedDependencies[i],
534
+ error: err
535
+ });
536
+ }
537
+ if(!options.ignoreErrored) {
538
+ if(!error)
539
+ error = err;
540
+ }
541
+ }
542
+ }
543
+ }
544
+ }
545
+ }
546
+
547
+ // Load self accepted modules
548
+ for(i = 0; i < outdatedSelfAcceptedModules.length; i++) {
549
+ var item = outdatedSelfAcceptedModules[i];
550
+ moduleId = item.module;
551
+ hotCurrentParents = [moduleId];
552
+ try {
553
+ $require$(moduleId);
554
+ } catch(err) {
555
+ if(typeof item.errorHandler === "function") {
556
+ try {
557
+ item.errorHandler(err);
558
+ } catch(err2) {
559
+ if(options.onErrored) {
560
+ options.onErrored({
561
+ type: "self-accept-error-handler-errored",
562
+ moduleId: moduleId,
563
+ error: err2,
564
+ orginalError: err, // TODO remove in webpack 4
565
+ originalError: err
566
+ });
567
+ }
568
+ if(!options.ignoreErrored) {
569
+ if(!error)
570
+ error = err2;
571
+ }
572
+ if(!error)
573
+ error = err;
574
+ }
575
+ } else {
576
+ if(options.onErrored) {
577
+ options.onErrored({
578
+ type: "self-accept-errored",
579
+ moduleId: moduleId,
580
+ error: err
581
+ });
582
+ }
583
+ if(!options.ignoreErrored) {
584
+ if(!error)
585
+ error = err;
586
+ }
587
+ }
588
+ }
589
+ }
590
+
591
+ // handle errors in accept handlers and self accepted module load
592
+ if(error) {
593
+ hotSetStatus("fail");
594
+ return Promise.reject(error);
595
+ }
596
+
597
+ hotSetStatus("idle");
598
+ return new Promise(function(resolve) {
599
+ resolve(outdatedModules);
600
+ });
601
+ }
602
+ };