@atlaspack/runtime-browser-hmr 2.14.5-canary.49 → 2.14.5-canary.490

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