@atlaspack/runtime-browser-hmr 2.14.5-canary.16 → 2.14.5-canary.160

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,4 +1,3 @@
1
- // @flow
2
1
  /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */
3
2
 
4
3
  /*::
@@ -49,56 +48,85 @@ declare var globalThis: typeof self;
49
48
  declare var ServiceWorkerGlobalScope: Object;
50
49
  */
51
50
 
51
+ // flow-to-ts helpers
52
+ export type SetComplement<A, B extends A> = A extends B ? never : A;
53
+ export type Diff<T extends U, U extends object> = Pick<
54
+ T,
55
+ SetComplement<keyof T, keyof U>
56
+ >;
57
+ // /flow-to-ts helpers
58
+
52
59
  var OVERLAY_ID = '__parcel__error__overlay__';
53
60
 
61
+ // @ts-expect-error TS2339
54
62
  var OldModule = module.bundle.Module;
55
63
 
56
- function Module(moduleName) {
64
+ function Module(moduleName: any) {
65
+ // @ts-expect-error TS2683
57
66
  OldModule.call(this, moduleName);
67
+ // @ts-expect-error TS2683
58
68
  this.hot = {
69
+ // @ts-expect-error TS2339
59
70
  data: module.bundle.hotData[moduleName],
60
71
  _acceptCallbacks: [],
61
72
  _disposeCallbacks: [],
73
+ // @ts-expect-error TS7006
62
74
  accept: function (fn) {
63
75
  this._acceptCallbacks.push(fn || function () {});
64
76
  },
77
+ // @ts-expect-error TS7006
65
78
  dispose: function (fn) {
66
79
  this._disposeCallbacks.push(fn);
67
80
  },
68
81
  };
82
+ // @ts-expect-error TS2339
69
83
  module.bundle.hotData[moduleName] = undefined;
70
84
  }
85
+ // @ts-expect-error TS2339
71
86
  module.bundle.Module = Module;
87
+ // @ts-expect-error TS2339
72
88
  module.bundle.hotData = {};
73
89
 
90
+ // @ts-expect-error TS7034
74
91
  var checkedAssets /*: {|[string]: boolean|} */,
92
+ // @ts-expect-error TS7034
93
+ disposedAssets /*: {|[string]: boolean|} */,
94
+ // @ts-expect-error TS7034
75
95
  assetsToDispose /*: Array<[ParcelRequire, string]> */,
96
+ // @ts-expect-error TS7034
76
97
  assetsToAccept /*: Array<[ParcelRequire, string]> */;
77
98
 
78
99
  function getHostname() {
79
100
  return (
101
+ // @ts-expect-error TS2304
80
102
  HMR_HOST ||
103
+ // @ts-expect-error TS2304
81
104
  (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
82
105
  );
83
106
  }
84
107
 
85
108
  function getPort() {
109
+ // @ts-expect-error TS2304
86
110
  return HMR_PORT || location.port;
87
111
  }
88
112
 
89
113
  // eslint-disable-next-line no-redeclare
114
+ // @ts-expect-error TS2339
90
115
  var parent = module.bundle.parent;
91
116
  if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
92
117
  var hostname = getHostname();
93
118
  var port = getPort();
94
119
  var protocol =
120
+ // @ts-expect-error TS2304
95
121
  HMR_SECURE ||
122
+ // @ts-expect-error TS2304
96
123
  (location.protocol == 'https:' &&
97
124
  !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname))
98
125
  ? 'wss'
99
126
  : 'ws';
100
127
 
101
128
  var ws;
129
+ // @ts-expect-error TS2304
102
130
  if (HMR_USE_SSE) {
103
131
  ws = new EventSource('/__parcel_hmr');
104
132
  } else {
@@ -106,7 +134,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
106
134
  ws = new WebSocket(
107
135
  protocol + '://' + hostname + (port ? ':' + port : '') + '/',
108
136
  );
109
- } catch (err) {
137
+ } catch (err: any) {
110
138
  if (err.message) {
111
139
  console.error(err.message);
112
140
  }
@@ -116,24 +144,33 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
116
144
 
117
145
  // Web extension context
118
146
  var extCtx =
147
+ // @ts-expect-error TS2304
119
148
  typeof browser === 'undefined'
120
- ? typeof chrome === 'undefined'
149
+ ? // @ts-expect-error TS2304
150
+ typeof chrome === 'undefined'
121
151
  ? null
122
- : chrome
123
- : browser;
152
+ : // @ts-expect-error TS2304
153
+ chrome
154
+ : // @ts-expect-error TS2304
155
+ browser;
124
156
 
125
157
  // Safari doesn't support sourceURL in error stacks.
126
158
  // eval may also be disabled via CSP, so do a quick check.
127
159
  var supportsSourceURL = false;
128
160
  try {
129
161
  (0, eval)('throw new Error("test"); //# sourceURL=test.js');
130
- } catch (err) {
162
+ } catch (err: any) {
131
163
  supportsSourceURL = err.stack.includes('test.js');
132
164
  }
133
165
 
134
- // $FlowFixMe
135
- ws.onmessage = async function (event /*: {data: string, ...} */) {
136
- checkedAssets = ({} /*: {|[string]: boolean|} */);
166
+ // @ts-expect-error TS2339
167
+ ws.onmessage = async function (
168
+ event: {
169
+ data: string;
170
+ } /*: {data: string, ...} */,
171
+ ) {
172
+ checkedAssets = {} /*: {|[string]: boolean|} */;
173
+ disposedAssets = {} /*: {|[string]: boolean|} */;
137
174
  assetsToAccept = [];
138
175
  assetsToDispose = [];
139
176
 
@@ -143,19 +180,23 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
143
180
  fullReload();
144
181
  } else if (data.type === 'update') {
145
182
  // Remove error overlay if there is one
183
+ // @ts-expect-error TS2304
146
184
  if (typeof document !== 'undefined') {
147
185
  removeErrorOverlay();
148
186
  }
149
187
 
150
188
  let assets = data.assets.filter(
189
+ // @ts-expect-error TS7006
151
190
  (asset) => asset.envHash === HMR_ENV_HASH,
152
191
  );
153
192
 
154
193
  // Handle HMR Update
194
+ // @ts-expect-error TS7006
155
195
  let handled = assets.every((asset) => {
156
196
  return (
157
197
  asset.type === 'css' ||
158
198
  (asset.type === 'js' &&
199
+ // @ts-expect-error TS2339
159
200
  hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle))
160
201
  );
161
202
  });
@@ -165,31 +206,26 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
165
206
 
166
207
  // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
167
208
  if (
209
+ // @ts-expect-error TS2304
168
210
  typeof window !== 'undefined' &&
169
211
  typeof CustomEvent !== 'undefined'
170
212
  ) {
213
+ // @ts-expect-error TS2304
171
214
  window.dispatchEvent(new CustomEvent('parcelhmraccept'));
172
215
  }
173
216
 
174
217
  await hmrApplyUpdates(assets);
175
218
 
176
- // Dispose all old assets.
177
- let processedAssets = ({} /*: {|[string]: boolean|} */);
178
- for (let i = 0; i < assetsToDispose.length; i++) {
179
- let id = assetsToDispose[i][1];
180
-
181
- if (!processedAssets[id]) {
182
- hmrDispose(assetsToDispose[i][0], id);
183
- processedAssets[id] = true;
184
- }
185
- }
219
+ hmrDisposeQueue();
186
220
 
187
221
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
188
- processedAssets = {};
222
+ let processedAssets: Record<string, any> = {};
189
223
  for (let i = 0; i < assetsToAccept.length; i++) {
224
+ // @ts-expect-error TS7005
190
225
  let id = assetsToAccept[i][1];
191
226
 
192
227
  if (!processedAssets[id]) {
228
+ // @ts-expect-error TS7005
193
229
  hmrAccept(assetsToAccept[i][0], id);
194
230
  processedAssets[id] = true;
195
231
  }
@@ -214,22 +250,23 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
214
250
  );
215
251
  }
216
252
 
253
+ // @ts-expect-error TS2304
217
254
  if (typeof document !== 'undefined') {
218
255
  // Render the fancy html overlay
219
256
  removeErrorOverlay();
220
257
  var overlay = createErrorOverlay(data.diagnostics.html);
221
- // $FlowFixMe
258
+ // @ts-expect-error TS2304
222
259
  document.body.appendChild(overlay);
223
260
  }
224
261
  }
225
262
  };
226
263
  if (ws instanceof WebSocket) {
227
- ws.onerror = function (e) {
264
+ ws.onerror = function (e: any) {
228
265
  if (e.message) {
229
266
  console.error(e.message);
230
267
  }
231
268
  };
232
- ws.onclose = function (e) {
269
+ ws.onclose = function (e: CloseEvent) {
233
270
  if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
234
271
  console.warn('[parcel] 🚨 Connection to the HMR server was lost');
235
272
  }
@@ -238,6 +275,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
238
275
  }
239
276
 
240
277
  function removeErrorOverlay() {
278
+ // @ts-expect-error TS2304
241
279
  var overlay = document.getElementById(OVERLAY_ID);
242
280
  if (overlay) {
243
281
  overlay.remove();
@@ -245,7 +283,20 @@ function removeErrorOverlay() {
245
283
  }
246
284
  }
247
285
 
248
- function createErrorOverlay(diagnostics) {
286
+ function createErrorOverlay(
287
+ diagnostics: Array<
288
+ Partial<
289
+ Diff<
290
+ // @ts-expect-error TS2304
291
+ AnsiDiagnosticResult,
292
+ {
293
+ codeframe: string;
294
+ }
295
+ >
296
+ >
297
+ >,
298
+ ) {
299
+ // @ts-expect-error TS2304
249
300
  var overlay = document.createElement('div');
250
301
  overlay.id = OVERLAY_ID;
251
302
 
@@ -254,7 +305,8 @@ function createErrorOverlay(diagnostics) {
254
305
 
255
306
  for (let diagnostic of diagnostics) {
256
307
  let stack = diagnostic.frames.length
257
- ? diagnostic.frames.reduce((p, frame) => {
308
+ ? // @ts-expect-error TS7006
309
+ diagnostic.frames.reduce((p, frame) => {
258
310
  return `${p}
259
311
  <a href="/__parcel_launch_editor?file=${encodeURIComponent(
260
312
  frame.location,
@@ -273,6 +325,7 @@ ${frame.code}`;
273
325
  <pre>${stack}</pre>
274
326
  <div>
275
327
  ${diagnostic.hints
328
+ // @ts-expect-error TS7006
276
329
  .map((hint) => '<div>💡 ' + hint + '</div>')
277
330
  .join('')}
278
331
  </div>
@@ -293,20 +346,27 @@ ${frame.code}`;
293
346
  }
294
347
 
295
348
  function fullReload() {
349
+ // @ts-expect-error TS2304
296
350
  if ('reload' in location) {
351
+ // @ts-expect-error TS2304
297
352
  location.reload();
298
353
  } else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
299
354
  extCtx.runtime.reload();
300
355
  }
301
356
  }
302
357
 
303
- function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
358
+ function getParents(
359
+ // @ts-expect-error TS2304
360
+ bundle: ParcelRequire,
361
+ id: string,
362
+ ) /*: Array<[ParcelRequire, string]> */ {
304
363
  var modules = bundle.modules;
305
364
  if (!modules) {
306
365
  return [];
307
366
  }
308
367
 
309
- var parents = [];
368
+ // @ts-expect-error TS2304
369
+ var parents: Array<[ParcelRequire, string]> = [];
310
370
  var k, d, dep;
311
371
 
312
372
  for (k in modules) {
@@ -326,38 +386,40 @@ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
326
386
  return parents;
327
387
  }
328
388
 
329
- function updateLink(link) {
389
+ function updateLink(link: HTMLElement) {
390
+ // @ts-expect-error TS2339
330
391
  var href = link.getAttribute('href');
331
392
 
332
393
  if (!href) {
333
394
  return;
334
395
  }
396
+ // @ts-expect-error TS2339
335
397
  var newLink = link.cloneNode();
336
398
  newLink.onload = function () {
399
+ // @ts-expect-error TS2339
337
400
  if (link.parentNode !== null) {
338
- // $FlowFixMe
401
+ // @ts-expect-error TS2339
339
402
  link.parentNode.removeChild(link);
340
403
  }
341
404
  };
342
- newLink.setAttribute(
343
- 'href',
344
- // $FlowFixMe
345
- href.split('?')[0] + '?' + Date.now(),
346
- );
347
- // $FlowFixMe
405
+ newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
406
+ // @ts-expect-error TS18047
348
407
  link.parentNode.insertBefore(newLink, link.nextSibling);
349
408
  }
350
409
 
410
+ // @ts-expect-error TS7034
351
411
  var cssTimeout = null;
352
412
  function reloadCSS() {
413
+ // @ts-expect-error TS7005
353
414
  if (cssTimeout) {
354
415
  return;
355
416
  }
356
417
 
357
418
  cssTimeout = setTimeout(function () {
419
+ // @ts-expect-error TS18047
420
+ var document = window.document;
358
421
  var links = document.querySelectorAll('link[rel="stylesheet"]');
359
422
  for (var i = 0; i < links.length; i++) {
360
- // $FlowFixMe[incompatible-type]
361
423
  var href /*: string */ = links[i].getAttribute('href');
362
424
  var hostname = getHostname();
363
425
  var servedFromHMRServer =
@@ -368,6 +430,7 @@ function reloadCSS() {
368
430
  : href.indexOf(hostname + ':' + getPort());
369
431
  var absolute =
370
432
  /^https?:\/\//i.test(href) &&
433
+ // @ts-expect-error TS18047
371
434
  href.indexOf(location.origin) !== 0 &&
372
435
  !servedFromHMRServer;
373
436
  if (!absolute) {
@@ -379,38 +442,60 @@ function reloadCSS() {
379
442
  }, 50);
380
443
  }
381
444
 
382
- function hmrDownload(asset) {
445
+ // @ts-expect-error TS2304
446
+ function hmrDownload(asset: HMRAsset) {
383
447
  if (asset.type === 'js') {
448
+ // @ts-expect-error TS18047
384
449
  if (typeof document !== 'undefined') {
450
+ // @ts-expect-error TS18047
385
451
  let script = document.createElement('script');
386
452
  script.src = asset.url + '?t=' + Date.now();
387
453
  if (asset.outputFormat === 'esmodule') {
388
454
  script.type = 'module';
389
455
  }
390
- return new Promise((resolve, reject) => {
391
- script.onload = () => resolve(script);
392
- script.onerror = reject;
393
- document.head?.appendChild(script);
394
- });
456
+ return new Promise(
457
+ (
458
+ resolve: (
459
+ result: Promise<HTMLScriptElement> | HTMLScriptElement,
460
+ ) => void,
461
+ reject: (error?: any) => void,
462
+ ) => {
463
+ script.onload = () => resolve(script);
464
+ script.onerror = reject;
465
+ // @ts-expect-error TS18047
466
+ document.head?.appendChild(script);
467
+ },
468
+ );
469
+ // @ts-expect-error TS2304
395
470
  } else if (typeof importScripts === 'function') {
396
471
  // Worker scripts
397
472
  if (asset.outputFormat === 'esmodule') {
473
+ // @ts-expect-error TS2304
398
474
  return __parcel__import__(asset.url + '?t=' + Date.now());
399
475
  } else {
400
- return new Promise((resolve, reject) => {
401
- try {
402
- __parcel__importScripts__(asset.url + '?t=' + Date.now());
403
- resolve();
404
- } catch (err) {
405
- reject(err);
406
- }
407
- });
476
+ return new Promise(
477
+ (
478
+ resolve: (result: Promise<undefined> | undefined) => void,
479
+ reject: (error?: any) => void,
480
+ ) => {
481
+ try {
482
+ // @ts-expect-error TS2304
483
+ __parcel__importScripts__(asset.url + '?t=' + Date.now());
484
+ // @ts-expect-error TS2794
485
+ resolve();
486
+ } catch (err: any) {
487
+ reject(err);
488
+ }
489
+ },
490
+ );
408
491
  }
409
492
  }
410
493
  }
411
494
  }
412
495
 
413
- async function hmrApplyUpdates(assets) {
496
+ // @ts-expect-error TS2304
497
+ async function hmrApplyUpdates(assets: Array<HMRAsset>) {
498
+ // @ts-expect-error TS7017
414
499
  global.parcelHotUpdate = Object.create(null);
415
500
 
416
501
  let scriptsToRemove;
@@ -423,13 +508,15 @@ async function hmrApplyUpdates(assets) {
423
508
  // This path is also taken if a CSP disallows eval.
424
509
  if (!supportsSourceURL) {
425
510
  let promises = assets.map((asset) =>
426
- hmrDownload(asset)?.catch((err) => {
511
+ hmrDownload(asset)?.catch((err: any) => {
427
512
  // Web extension fix
428
513
  if (
429
514
  extCtx &&
430
515
  extCtx.runtime &&
431
516
  extCtx.runtime.getManifest().manifest_version == 3 &&
517
+ // @ts-expect-error TS2304
432
518
  typeof ServiceWorkerGlobalScope != 'undefined' &&
519
+ // @ts-expect-error TS2304
433
520
  global instanceof ServiceWorkerGlobalScope
434
521
  ) {
435
522
  extCtx.runtime.reload();
@@ -443,14 +530,18 @@ async function hmrApplyUpdates(assets) {
443
530
  }
444
531
 
445
532
  assets.forEach(function (asset) {
533
+ // @ts-expect-error TS2339
446
534
  hmrApply(module.bundle.root, asset);
447
535
  });
448
536
  } finally {
537
+ // @ts-expect-error TS7017
449
538
  delete global.parcelHotUpdate;
450
539
 
451
540
  if (scriptsToRemove) {
541
+ // @ts-expect-error TS7006
452
542
  scriptsToRemove.forEach((script) => {
453
543
  if (script) {
544
+ // @ts-expect-error TS18047
454
545
  document.head?.removeChild(script);
455
546
  }
456
547
  });
@@ -458,7 +549,12 @@ async function hmrApplyUpdates(assets) {
458
549
  }
459
550
  }
460
551
 
461
- function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
552
+ function hmrApply(
553
+ // @ts-expect-error TS2304
554
+ bundle: ParcelRequire /*: ParcelRequire */,
555
+ // @ts-expect-error TS2304
556
+ asset: HMRAsset /*: HMRAsset */,
557
+ ) {
462
558
  var modules = bundle.modules;
463
559
  if (!modules) {
464
560
  return;
@@ -476,8 +572,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
476
572
  for (let dep in oldDeps) {
477
573
  if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
478
574
  let id = oldDeps[dep];
575
+ // @ts-expect-error TS2339
479
576
  let parents = getParents(module.bundle.root, id);
480
577
  if (parents.length === 1) {
578
+ // @ts-expect-error TS2339
481
579
  hmrDelete(module.bundle.root, id);
482
580
  }
483
581
  }
@@ -490,16 +588,21 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
490
588
  (0, eval)(asset.output);
491
589
  }
492
590
 
493
- // $FlowFixMe
591
+ // @ts-expect-error TS7017
494
592
  let fn = global.parcelHotUpdate[asset.id];
495
593
  modules[asset.id] = [fn, deps];
496
- } else if (bundle.parent) {
594
+ }
595
+
596
+ // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
597
+ // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
598
+ if (bundle.parent) {
497
599
  hmrApply(bundle.parent, asset);
498
600
  }
499
601
  }
500
602
  }
501
603
 
502
- function hmrDelete(bundle, id) {
604
+ // @ts-expect-error TS2304
605
+ function hmrDelete(bundle: ParcelRequire, id: string) {
503
606
  let modules = bundle.modules;
504
607
  if (!modules) {
505
608
  return;
@@ -508,8 +611,9 @@ function hmrDelete(bundle, id) {
508
611
  if (modules[id]) {
509
612
  // Collect dependencies that will become orphaned when this module is deleted.
510
613
  let deps = modules[id][1];
511
- let orphans = [];
614
+ let orphans: Array<string> = [];
512
615
  for (let dep in deps) {
616
+ // @ts-expect-error TS2339
513
617
  let parents = getParents(module.bundle.root, deps[dep]);
514
618
  if (parents.length === 1) {
515
619
  orphans.push(deps[dep]);
@@ -522,6 +626,7 @@ function hmrDelete(bundle, id) {
522
626
 
523
627
  // Now delete the orphans.
524
628
  orphans.forEach((id) => {
629
+ // @ts-expect-error TS2339
525
630
  hmrDelete(module.bundle.root, id);
526
631
  });
527
632
  } else if (bundle.parent) {
@@ -530,25 +635,36 @@ function hmrDelete(bundle, id) {
530
635
  }
531
636
 
532
637
  function hmrAcceptCheck(
533
- bundle /*: ParcelRequire */,
534
- id /*: string */,
535
- depsByBundle /*: ?{ [string]: { [string]: string } }*/,
638
+ // @ts-expect-error TS2304
639
+ bundle: ParcelRequire /*: ParcelRequire */,
640
+ id: string /*: string */,
641
+ depsByBundle:
642
+ | {
643
+ [key: string]: {
644
+ [key: string]: string;
645
+ };
646
+ }
647
+ | null
648
+ | undefined /*: ?{ [string]: { [string]: string } }*/,
536
649
  ) {
537
650
  if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
538
651
  return true;
539
652
  }
540
653
 
541
654
  // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
655
+ // @ts-expect-error TS2339
542
656
  let parents = getParents(module.bundle.root, id);
543
657
  let accepted = false;
544
658
  while (parents.length > 0) {
545
659
  let v = parents.shift();
660
+ // @ts-expect-error TS18048
546
661
  let a = hmrAcceptCheckOne(v[0], v[1], null);
547
662
  if (a) {
548
663
  // If this parent accepts, stop traversing upward, but still consider siblings.
549
664
  accepted = true;
550
665
  } else {
551
666
  // Otherwise, queue the parents in the next level upward.
667
+ // @ts-expect-error TS2339
552
668
  let p = getParents(module.bundle.root, v[1]);
553
669
  if (p.length === 0) {
554
670
  // If there are no parents, then we've reached an entry without accepting. Reload.
@@ -563,9 +679,17 @@ function hmrAcceptCheck(
563
679
  }
564
680
 
565
681
  function hmrAcceptCheckOne(
566
- bundle /*: ParcelRequire */,
567
- id /*: string */,
568
- depsByBundle /*: ?{ [string]: { [string]: string } }*/,
682
+ // @ts-expect-error TS2304
683
+ bundle: ParcelRequire /*: ParcelRequire */,
684
+ id: string /*: string */,
685
+ depsByBundle:
686
+ | {
687
+ [key: string]: {
688
+ [key: string]: string;
689
+ };
690
+ }
691
+ | null
692
+ | undefined /*: ?{ [string]: { [string]: string } }*/,
569
693
  ) {
570
694
  var modules = bundle.modules;
571
695
  if (!modules) {
@@ -582,10 +706,12 @@ function hmrAcceptCheckOne(
582
706
  return hmrAcceptCheck(bundle.parent, id, depsByBundle);
583
707
  }
584
708
 
709
+ // @ts-expect-error TS7005
585
710
  if (checkedAssets[id]) {
586
711
  return true;
587
712
  }
588
713
 
714
+ // @ts-expect-error TS7005
589
715
  checkedAssets[id] = true;
590
716
 
591
717
  var cached = bundle.cache[id];
@@ -597,7 +723,28 @@ function hmrAcceptCheckOne(
597
723
  }
598
724
  }
599
725
 
600
- function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
726
+ function hmrDisposeQueue() {
727
+ // Dispose all old assets.
728
+ for (let i = 0; i < assetsToDispose.length; i++) {
729
+ // @ts-expect-error TS7005
730
+ let id = assetsToDispose[i][1];
731
+
732
+ // @ts-expect-error TS7005
733
+ if (!disposedAssets[id]) {
734
+ // @ts-expect-error TS7005
735
+ hmrDispose(assetsToDispose[i][0], id);
736
+ disposedAssets[id] = true;
737
+ }
738
+ }
739
+
740
+ assetsToDispose = [];
741
+ }
742
+
743
+ function hmrDispose(
744
+ // @ts-expect-error TS2304
745
+ bundle: ParcelRequire /*: ParcelRequire */,
746
+ id: string /*: string */,
747
+ ) {
601
748
  var cached = bundle.cache[id];
602
749
  bundle.hotData[id] = {};
603
750
  if (cached && cached.hot) {
@@ -605,6 +752,7 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
605
752
  }
606
753
 
607
754
  if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
755
+ // @ts-expect-error TS7006
608
756
  cached.hot._disposeCallbacks.forEach(function (cb) {
609
757
  cb(bundle.hotData[id]);
610
758
  });
@@ -613,25 +761,41 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
613
761
  delete bundle.cache[id];
614
762
  }
615
763
 
616
- function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
764
+ function hmrAccept(
765
+ // @ts-expect-error TS2304
766
+ bundle: ParcelRequire /*: ParcelRequire */,
767
+ id: string /*: string */,
768
+ ) {
617
769
  // Execute the module.
618
770
  bundle(id);
619
771
 
620
772
  // Run the accept callbacks in the new version of the module.
621
773
  var cached = bundle.cache[id];
622
774
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
775
+ let assetsToAlsoAccept: Array<never> = [];
776
+ // @ts-expect-error TS7006
623
777
  cached.hot._acceptCallbacks.forEach(function (cb) {
624
- var assetsToAlsoAccept = cb(function () {
778
+ let additionalAssets = cb(function () {
779
+ // @ts-expect-error TS2339
625
780
  return getParents(module.bundle.root, id);
626
781
  });
627
- if (assetsToAlsoAccept && assetsToAccept.length) {
628
- assetsToAlsoAccept.forEach(function (a) {
629
- hmrDispose(a[0], a[1]);
630
- });
631
-
632
- // $FlowFixMe[method-unbinding]
633
- assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
782
+ if (Array.isArray(additionalAssets) && additionalAssets.length) {
783
+ // @ts-expect-error TS2345
784
+ assetsToAlsoAccept.push(...additionalAssets);
634
785
  }
635
786
  });
787
+
788
+ if (assetsToAlsoAccept.length > 0) {
789
+ let handled = assetsToAlsoAccept.every(function (a) {
790
+ // @ts-expect-error TS2554
791
+ return hmrAcceptCheck(a[0], a[1]);
792
+ });
793
+
794
+ if (!handled) {
795
+ return fullReload();
796
+ }
797
+
798
+ hmrDisposeQueue();
799
+ }
636
800
  }
637
801
  }