@jsenv/core 36.2.1 → 36.3.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.
Files changed (124) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +45 -35
  2. package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -3
  3. package/dist/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +13 -13
  4. package/dist/babel_helpers/applyDecs/applyDecs.js +227 -42
  5. package/dist/babel_helpers/applyDecs2203/applyDecs2203.js +559 -418
  6. package/dist/babel_helpers/applyDecs2203R/applyDecs2203R.js +235 -87
  7. package/dist/babel_helpers/applyDecs2301/applyDecs2301.js +591 -456
  8. package/dist/babel_helpers/applyDecs2305/applyDecs2305.js +681 -0
  9. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +5 -5
  10. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +3 -3
  11. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +4 -4
  12. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +4 -4
  13. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +12 -4
  14. package/dist/babel_helpers/asyncIterator/asyncIterator.js +13 -11
  15. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +18 -17
  16. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +2 -1
  17. package/dist/babel_helpers/checkInRHS/checkInRHS.js +8 -5
  18. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +7 -7
  19. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +3 -3
  20. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +4 -4
  21. package/dist/babel_helpers/classCallCheck/classCallCheck.js +2 -2
  22. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +2 -2
  23. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +2 -2
  24. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +3 -3
  25. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +2 -2
  26. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -5
  27. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -5
  28. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +3 -3
  29. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +3 -3
  30. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -6
  31. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +3 -3
  32. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +2 -2
  33. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -7
  34. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -9
  35. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -4
  36. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +2 -2
  37. package/dist/babel_helpers/construct/construct.js +10 -9
  38. package/dist/babel_helpers/createClass/createClass.js +2 -3
  39. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +30 -29
  40. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +18 -16
  41. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +23 -17
  42. package/dist/babel_helpers/createSuper/createSuper.js +14 -12
  43. package/dist/babel_helpers/decorate/decorate.js +242 -210
  44. package/dist/babel_helpers/defaults/defaults.js +6 -6
  45. package/dist/babel_helpers/defineAccessor/defineAccessor.js +1 -4
  46. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +12 -12
  47. package/dist/babel_helpers/defineProperty/defineProperty.js +7 -6
  48. package/dist/babel_helpers/extends/extends.js +5 -4
  49. package/dist/babel_helpers/get/get.js +2 -1
  50. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +4 -3
  51. package/dist/babel_helpers/inherits/inherits.js +3 -4
  52. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -5
  53. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +4 -4
  54. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +5 -2
  55. package/dist/babel_helpers/instanceof/instanceof.js +3 -3
  56. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +2 -4
  57. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +19 -21
  58. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +2 -2
  59. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +7 -7
  60. package/dist/babel_helpers/iterableToArray/iterableToArray.js +6 -2
  61. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +6 -1
  62. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +6 -2
  63. package/dist/babel_helpers/jsx/jsx.js +14 -7
  64. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +6 -5
  65. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +2 -2
  66. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +5 -3
  67. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +5 -3
  68. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +2 -2
  69. package/dist/babel_helpers/objectSpread/objectSpread.js +15 -12
  70. package/dist/babel_helpers/objectSpread2/objectSpread2.js +7 -2
  71. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +15 -13
  72. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +11 -11
  73. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +7 -6
  74. package/dist/babel_helpers/readOnlyError/readOnlyError.js +2 -2
  75. package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +124 -73
  76. package/dist/babel_helpers/set/set.js +23 -20
  77. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +6 -5
  78. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +5 -5
  79. package/dist/babel_helpers/slicedToArray/slicedToArray.js +10 -5
  80. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +12 -6
  81. package/dist/babel_helpers/superPropBase/superPropBase.js +6 -5
  82. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +7 -7
  83. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +4 -4
  84. package/dist/babel_helpers/tdz/tdz.js +2 -2
  85. package/dist/babel_helpers/temporalRef/temporalRef.js +5 -4
  86. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +1 -1
  87. package/dist/babel_helpers/toArray/toArray.js +10 -5
  88. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +10 -5
  89. package/dist/babel_helpers/toPrimitive/toPrimitive.js +7 -7
  90. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -4
  91. package/dist/babel_helpers/typeof/typeof.js +14 -5
  92. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -8
  93. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +5 -4
  94. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +17 -15
  95. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +19 -8
  96. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +2 -2
  97. package/dist/js/autoreload.js +148 -133
  98. package/dist/js/import_meta_hot.js +19 -13
  99. package/dist/js/inline_content.js +1 -3
  100. package/dist/js/new_stylesheet.js +119 -60
  101. package/dist/js/regenerator_runtime.js +204 -102
  102. package/dist/js/ribbon.js +11 -6
  103. package/dist/js/server_events_client.js +122 -98
  104. package/dist/js/ws.js +968 -265
  105. package/dist/jsenv_core.js +8513 -6162
  106. package/package.json +9 -9
  107. package/src/build/build.js +497 -486
  108. package/src/build/version_mappings_injection.js +21 -44
  109. package/src/kitchen/errors.js +2 -2
  110. package/src/kitchen/fetched_content_compliance.js +6 -2
  111. package/src/kitchen/kitchen.js +285 -80
  112. package/src/kitchen/prepend_content.js +135 -0
  113. package/src/kitchen/url_graph/url_graph_visitor.js +99 -0
  114. package/src/kitchen/url_graph/url_info_transformations.js +140 -21
  115. package/src/kitchen/url_graph.js +59 -29
  116. package/src/plugins/autoreload/jsenv_plugin_hmr.js +1 -2
  117. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +2 -2
  118. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -2
  119. package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +1 -1
  120. package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +44 -23
  121. package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +2 -1
  122. package/dist/js/global_this_js_classic.js +0 -24
  123. package/dist/js/global_this_js_module.js +0 -20
  124. package/src/build/graph_utils.js +0 -34
@@ -1,5 +1,14 @@
1
- const nativeTypeOf = obj => typeof obj;
2
- const customTypeOf = obj => {
3
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
4
- };
5
- export default typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? nativeTypeOf : customTypeOf;
1
+ const nativeTypeOf = (obj) => typeof obj
2
+
3
+ const customTypeOf = (obj) => {
4
+ return obj &&
5
+ typeof Symbol === "function" &&
6
+ obj.constructor === Symbol &&
7
+ obj !== Symbol.prototype
8
+ ? "symbol"
9
+ : typeof obj
10
+ }
11
+
12
+ export default typeof Symbol === "function" && typeof Symbol.iterator === "symbol"
13
+ ? nativeTypeOf
14
+ : customTypeOf
@@ -1,10 +1,12 @@
1
1
  /* eslint-disable consistent-return */
2
- import arrayLikeToArray from "../arrayLikeToArray/arrayLikeToArray.js";
2
+ import arrayLikeToArray from "../arrayLikeToArray/arrayLikeToArray.js"
3
+
3
4
  export default function unsupportedIterableToArray(o, minLen) {
4
- if (!o) return;
5
- if (typeof o === "string") return arrayLikeToArray(o, minLen);
6
- var n = Object.prototype.toString.call(o).slice(8, -1);
7
- if (n === "Object" && o.constructor) n = o.constructor.name;
8
- if (n === "Map" || n === "Set") return Array.from(o);
9
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
10
- }
5
+ if (!o) return
6
+ if (typeof o === "string") return arrayLikeToArray(o, minLen)
7
+ var n = Object.prototype.toString.call(o).slice(8, -1)
8
+ if (n === "Object" && o.constructor) n = o.constructor.name
9
+ if (n === "Map" || n === "Set") return Array.from(o)
10
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
11
+ return arrayLikeToArray(o, minLen)
12
+ }
@@ -1,7 +1,8 @@
1
- import AsyncGenerator from "../AsyncGenerator/AsyncGenerator.js";
1
+ import AsyncGenerator from "../AsyncGenerator/AsyncGenerator.js"
2
+
2
3
  export default function (fn) {
3
4
  return function () {
4
5
  // eslint-disable-next-line prefer-rest-params
5
- return new AsyncGenerator(fn.apply(this, arguments));
6
- };
7
- }
6
+ return new AsyncGenerator(fn.apply(this, arguments))
7
+ }
8
+ }
@@ -1,28 +1,30 @@
1
- import getPrototypeOf from "../getPrototypeOf/getPrototypeOf.js";
2
- import setPrototypeOf from "../setPrototypeOf/setPrototypeOf.js";
3
- import isNativeFunction from "../isNativeFunction/isNativeFunction.js";
4
- import construct from "../construct/construct.js";
5
- var _cache = typeof Map === "function" ? new Map() : undefined;
1
+ import getPrototypeOf from "../getPrototypeOf/getPrototypeOf.js"
2
+ import setPrototypeOf from "../setPrototypeOf/setPrototypeOf.js"
3
+ import isNativeFunction from "../isNativeFunction/isNativeFunction.js"
4
+ import construct from "../construct/construct.js"
5
+
6
+ var _cache = typeof Map === "function" ? new Map() : undefined
7
+
6
8
  export default function (Class) {
7
- if (Class === null || !isNativeFunction(Class)) return Class;
9
+ if (Class === null || !isNativeFunction(Class)) return Class
8
10
  if (typeof Class !== "function") {
9
- throw new TypeError("Super expression must either be null or a function");
11
+ throw new TypeError("Super expression must either be null or a function")
10
12
  }
11
13
  if (typeof _cache !== "undefined") {
12
- if (_cache.has(Class)) return _cache.get(Class);
13
- _cache.set(Class, Wrapper);
14
+ if (_cache.has(Class)) return _cache.get(Class)
15
+ _cache.set(Class, Wrapper)
14
16
  }
15
17
  function Wrapper() {
16
18
  // eslint-disable-next-line prefer-rest-params
17
- return construct(Class, arguments, getPrototypeOf(this).constructor);
19
+ return construct(Class, arguments, getPrototypeOf(this).constructor)
18
20
  }
19
21
  Wrapper.prototype = Object.create(Class.prototype, {
20
22
  constructor: {
21
23
  value: Wrapper,
22
24
  enumerable: false,
23
25
  writable: true,
24
- configurable: true
25
- }
26
- });
27
- return setPrototypeOf(Wrapper, Class);
28
- }
26
+ configurable: true,
27
+ },
28
+ })
29
+ return setPrototypeOf(Wrapper, Class)
30
+ }
@@ -1,11 +1,14 @@
1
- import setPrototypeOf from "../setPrototypeOf/setPrototypeOf.js";
2
- import inherits from "../inherits/inherits.js";
1
+ import setPrototypeOf from "../setPrototypeOf/setPrototypeOf.js"
2
+ import inherits from "../inherits/inherits.js"
3
+
3
4
  export default function _wrapRegExp() {
4
5
  _wrapRegExp = function (re, groups) {
5
6
  return new BabelRegExp(re, undefined, groups);
6
7
  };
8
+
7
9
  var _super = RegExp.prototype;
8
10
  var _groups = new WeakMap();
11
+
9
12
  function BabelRegExp(re, flags, groups) {
10
13
  var _this = new RegExp(re, flags);
11
14
  // if the regex is recreated with 'g' flag
@@ -13,6 +16,7 @@ export default function _wrapRegExp() {
13
16
  return setPrototypeOf(_this, BabelRegExp.prototype);
14
17
  }
15
18
  inherits(BabelRegExp, RegExp);
19
+
16
20
  BabelRegExp.prototype.exec = function (str) {
17
21
  var result = _super.exec.call(this, str);
18
22
  if (result) {
@@ -25,10 +29,14 @@ export default function _wrapRegExp() {
25
29
  BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
26
30
  if (typeof substitution === "string") {
27
31
  var groups = _groups.get(this);
28
- return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
29
- var group = groups[name];
30
- return "$" + (Array.isArray(group) ? group.join("$") : group);
31
- }));
32
+ return _super[Symbol.replace].call(
33
+ this,
34
+ str,
35
+ substitution.replace(/\$<([^>]+)>/g, function (_, name) {
36
+ var group = groups[name];
37
+ return "$" + (Array.isArray(group) ? group.join("$") : group);
38
+ })
39
+ );
32
40
  } else if (typeof substitution === "function") {
33
41
  var _this = this;
34
42
  return _super[Symbol.replace].call(this, str, function () {
@@ -44,6 +52,7 @@ export default function _wrapRegExp() {
44
52
  return _super[Symbol.replace].call(this, str, substitution);
45
53
  }
46
54
  };
55
+
47
56
  function buildGroups(result, re) {
48
57
  // NOTE: This function should return undefined if there are no groups,
49
58
  // but in that case Babel doesn't add the wrapper anyway.
@@ -51,7 +60,8 @@ export default function _wrapRegExp() {
51
60
  var g = _groups.get(re);
52
61
  return Object.keys(g).reduce(function (groups, name) {
53
62
  var i = g[name];
54
- if (typeof i === "number") groups[name] = result[i];else {
63
+ if (typeof i === "number") groups[name] = result[i];
64
+ else {
55
65
  // i is an array of indexes
56
66
  var k = 0;
57
67
  // if no group matched, we stop at k = i.length - 1 and then
@@ -62,5 +72,6 @@ export default function _wrapRegExp() {
62
72
  return groups;
63
73
  }, Object.create(null));
64
74
  }
75
+
65
76
  return _wrapRegExp.apply(this, arguments);
66
- }
77
+ }
@@ -1,4 +1,4 @@
1
1
  export default function (name) {
2
2
  // eslint-disable-next-line prefer-template
3
- throw new TypeError(name + " is write-only");
4
- }
3
+ throw new TypeError(name + " is write-only")
4
+ }
@@ -15,12 +15,11 @@ const compareTwoUrlPaths = (url, otherUrl) => {
15
15
  }
16
16
  return true;
17
17
  };
18
+
18
19
  const injectQuery = (url, query) => {
19
20
  const urlObject = new URL(url);
20
- const {
21
- searchParams
22
- } = urlObject;
23
- Object.keys(query).forEach(key => {
21
+ const { searchParams } = urlObject;
22
+ Object.keys(query).forEach((key) => {
24
23
  searchParams.set(key, query[key]);
25
24
  });
26
25
  return String(urlObject);
@@ -34,9 +33,9 @@ const reloadHtmlPage = () => {
34
33
  // - no need to check [hot-accept]and [hot-decline] attributes for instance
35
34
  // This is because if something should full reload, we receive "full_reload"
36
35
  // from server and this function is not called
37
- const getDOMNodesUsingUrl = urlToReload => {
36
+ const getDOMNodesUsingUrl = (urlToReload) => {
38
37
  const nodes = [];
39
- const shouldReloadUrl = urlCandidate => {
38
+ const shouldReloadUrl = (urlCandidate) => {
40
39
  return compareTwoUrlPaths(urlCandidate, urlToReload);
41
40
  };
42
41
  const visitNodeAttributeAsUrl = (node, attributeName) => {
@@ -55,40 +54,40 @@ const getDOMNodesUsingUrl = urlToReload => {
55
54
  reload: () => {
56
55
  if (node.nodeName === "SCRIPT") {
57
56
  const copy = document.createElement("script");
58
- Array.from(node.attributes).forEach(attribute => {
57
+ Array.from(node.attributes).forEach((attribute) => {
59
58
  copy.setAttribute(attribute.nodeName, attribute.nodeValue);
60
59
  });
61
- copy.src = injectQuery(node.src, {
62
- hmr: Date.now()
63
- });
60
+ copy.src = injectQuery(node.src, { hmr: Date.now() });
64
61
  if (node.parentNode) {
65
62
  node.parentNode.replaceChild(copy, node);
66
63
  } else {
67
64
  document.body.appendChild(copy);
68
65
  }
69
66
  } else {
70
- node[attributeName] = injectQuery(attribute, {
71
- hmr: Date.now()
72
- });
67
+ node[attributeName] = injectQuery(attribute, { hmr: Date.now() });
73
68
  }
74
- }
69
+ },
75
70
  });
76
71
  };
77
- Array.from(document.querySelectorAll(`link[rel="stylesheet"]`)).forEach(link => {
78
- visitNodeAttributeAsUrl(link, "href");
79
- });
80
- Array.from(document.querySelectorAll(`link[rel="icon"]`)).forEach(link => {
72
+ Array.from(document.querySelectorAll(`link[rel="stylesheet"]`)).forEach(
73
+ (link) => {
74
+ visitNodeAttributeAsUrl(link, "href");
75
+ },
76
+ );
77
+ Array.from(document.querySelectorAll(`link[rel="icon"]`)).forEach((link) => {
81
78
  visitNodeAttributeAsUrl(link, "href");
82
79
  });
83
- Array.from(document.querySelectorAll("script")).forEach(script => {
80
+ Array.from(document.querySelectorAll("script")).forEach((script) => {
84
81
  visitNodeAttributeAsUrl(script, "src");
85
82
  const inlinedFromSrc = script.getAttribute("inlined-from-src");
86
83
  if (inlinedFromSrc) {
87
- const inlinedFromUrl = new URL(inlinedFromSrc, window.location.origin).href;
84
+ const inlinedFromUrl = new URL(inlinedFromSrc, window.location.origin)
85
+ .href;
88
86
  if (shouldReloadUrl(inlinedFromUrl)) {
89
87
  nodes.push({
90
88
  node: script,
91
- reload: () => window.__supervisor__.reloadSupervisedScript(inlinedFromSrc)
89
+ reload: () =>
90
+ window.__supervisor__.reloadSupervisedScript(inlinedFromSrc),
92
91
  });
93
92
  }
94
93
  }
@@ -96,7 +95,7 @@ const getDOMNodesUsingUrl = urlToReload => {
96
95
  // There is no real need to update a.href because the resource will be fetched when clicked.
97
96
  // But in a scenario where the resource was already visited and is in browser cache, adding
98
97
  // the dynamic query param ensure the cache is invalidated
99
- Array.from(document.querySelectorAll("a")).forEach(a => {
98
+ Array.from(document.querySelectorAll("a")).forEach((a) => {
100
99
  visitNodeAttributeAsUrl(a, "href");
101
100
  });
102
101
  // About iframes:
@@ -105,44 +104,41 @@ const getDOMNodesUsingUrl = urlToReload => {
105
104
  // In that case and if there is code in the iframe and parent doing post message communication:
106
105
  // you must put import.meta.hot.decline() for code involved in communication.
107
106
  // (both in parent and iframe)
108
- Array.from(document.querySelectorAll("img")).forEach(img => {
107
+ Array.from(document.querySelectorAll("img")).forEach((img) => {
109
108
  visitNodeAttributeAsUrl(img, "src");
110
109
  const srcset = img.srcset;
111
110
  if (srcset) {
112
111
  const srcCandidates = parseSrcSet(srcset);
113
- srcCandidates.forEach(srcCandidate => {
112
+ srcCandidates.forEach((srcCandidate) => {
114
113
  const url = new URL(srcCandidate.specifier, `${window.location.href}`);
115
114
  if (shouldReloadUrl(url)) {
116
- srcCandidate.specifier = injectQuery(url, {
117
- hmr: Date.now()
118
- });
115
+ srcCandidate.specifier = injectQuery(url, { hmr: Date.now() });
119
116
  }
120
117
  });
121
118
  nodes.push({
122
119
  node: img,
123
120
  reload: () => {
124
121
  img.srcset = stringifySrcSet(srcCandidates);
125
- }
122
+ },
126
123
  });
127
124
  }
128
125
  });
129
- Array.from(document.querySelectorAll("source")).forEach(source => {
126
+ Array.from(document.querySelectorAll("source")).forEach((source) => {
130
127
  visitNodeAttributeAsUrl(source, "src");
131
128
  });
132
129
  // svg image tag
133
- Array.from(document.querySelectorAll("image")).forEach(image => {
130
+ Array.from(document.querySelectorAll("image")).forEach((image) => {
134
131
  visitNodeAttributeAsUrl(image, "href");
135
132
  });
136
133
  // svg use
137
- Array.from(document.querySelectorAll("use")).forEach(use => {
134
+ Array.from(document.querySelectorAll("use")).forEach((use) => {
138
135
  visitNodeAttributeAsUrl(use, "href");
139
136
  });
140
137
  return nodes;
141
138
  };
142
- const reloadJsImport = async url => {
143
- const urlWithHmr = injectQuery(url, {
144
- hmr: Date.now()
145
- });
139
+
140
+ const reloadJsImport = async (url) => {
141
+ const urlWithHmr = injectQuery(url, { hmr: Date.now() });
146
142
  const namespace = await import(urlWithHmr);
147
143
  return namespace;
148
144
  };
@@ -152,10 +148,10 @@ const reloader = {
152
148
  status: {
153
149
  value: "idle",
154
150
  onchange: () => {},
155
- goTo: value => {
151
+ goTo: (value) => {
156
152
  reloader.status.value = value;
157
153
  reloader.status.onchange();
158
- }
154
+ },
159
155
  },
160
156
  autoreload: {
161
157
  enabled: ["1", null].includes(window.localStorage.getItem("autoreload")),
@@ -169,12 +165,12 @@ const reloader = {
169
165
  reloader.autoreload.enabled = false;
170
166
  window.localStorage.setItem("autoreload", "0");
171
167
  reloader.autoreload.onchange();
172
- }
168
+ },
173
169
  },
174
170
  changes: {
175
171
  value: [],
176
172
  onchange: () => {},
177
- add: reloadMessage => {
173
+ add: (reloadMessage) => {
178
174
  reloader.changes.value.push(reloadMessage);
179
175
  reloader.changes.onchange();
180
176
  if (reloader.autoreload.enabled) {
@@ -183,7 +179,7 @@ const reloader = {
183
179
  reloader.status.goTo("can_reload");
184
180
  }
185
181
  },
186
- remove: reloadMessage => {
182
+ remove: (reloadMessage) => {
187
183
  const index = reloader.changes.value.indexOf(reloadMessage);
188
184
  if (index > -1) {
189
185
  reloader.changes.value.splice(index, 1);
@@ -192,36 +188,43 @@ const reloader = {
192
188
  }
193
189
  reloader.changes.onchange();
194
190
  }
195
- }
191
+ },
196
192
  },
197
193
  currentExecution: null,
198
194
  reload: () => {
199
- const someEffectIsFullReload = reloader.changes.value.some(reloadMessage => reloadMessage.type === "full");
195
+ const someEffectIsFullReload = reloader.changes.value.some(
196
+ (reloadMessage) => reloadMessage.type === "full",
197
+ );
200
198
  if (someEffectIsFullReload) {
201
199
  reloadHtmlPage();
202
200
  return;
203
201
  }
204
202
  reloader.status.goTo("reloading");
205
- const onApplied = reloadMessage => {
203
+ const onApplied = (reloadMessage) => {
206
204
  reloader.changes.remove(reloadMessage);
207
205
  };
208
206
  const setReloadMessagePromise = (reloadMessage, promise) => {
209
- promise.then(() => {
210
- onApplied(reloadMessage);
211
- reloader.currentExecution = null;
212
- }, e => {
213
- reloader.status.goTo("failed");
214
- if (typeof window.reportError === "function") {
215
- window.reportError(e);
216
- } else {
217
- console.error(e);
218
- }
219
- console.error(`[jsenv] Hot reload failed after ${reloadMessage.reason}.
220
- This could be due to syntax errors or importing non-existent modules (see errors in console)`);
221
- reloader.currentExecution = null;
222
- });
207
+ promise.then(
208
+ () => {
209
+ onApplied(reloadMessage);
210
+ reloader.currentExecution = null;
211
+ },
212
+ (e) => {
213
+ reloader.status.goTo("failed");
214
+ if (typeof window.reportError === "function") {
215
+ window.reportError(e);
216
+ } else {
217
+ console.error(e);
218
+ }
219
+ console.error(
220
+ `[jsenv] Hot reload failed after ${reloadMessage.reason}.
221
+ This could be due to syntax errors or importing non-existent modules (see errors in console)`,
222
+ );
223
+ reloader.currentExecution = null;
224
+ },
225
+ );
223
226
  };
224
- reloader.changes.value.forEach(reloadMessage => {
227
+ reloader.changes.value.forEach((reloadMessage) => {
225
228
  if (reloadMessage.type === "hot") {
226
229
  const promise = addToHotQueue(() => {
227
230
  return applyHotReload(reloadMessage);
@@ -231,11 +234,12 @@ This could be due to syntax errors or importing non-existent modules (see errors
231
234
  setReloadMessagePromise(reloadMessage, Promise.resolve());
232
235
  }
233
236
  });
234
- }
237
+ },
235
238
  };
239
+
236
240
  let pendingCallbacks = [];
237
241
  let running = false;
238
- const addToHotQueue = async callback => {
242
+ const addToHotQueue = async (callback) => {
239
243
  pendingCallbacks.push(callback);
240
244
  dequeue();
241
245
  };
@@ -258,90 +262,101 @@ const dequeue = async () => {
258
262
  }
259
263
  }
260
264
  };
261
- const applyHotReload = async ({
262
- hotInstructions
263
- }) => {
264
- await hotInstructions.reduce(async (previous, {
265
- type,
266
- boundary,
267
- acceptedBy
268
- }) => {
269
- await previous;
270
- const urlToFetch = new URL(boundary, `${window.location.origin}/`).href;
271
- const urlHotMeta = urlHotMetas[urlToFetch];
272
- // there is no url hot meta when:
273
- // - code was not executed (code splitting with dynamic import)
274
- // - import.meta.hot.accept() is not called (happens for HTML and CSS)
275
265
 
276
- if (type === "prune") {
277
- if (urlHotMeta) {
278
- delete urlHotMetas[urlToFetch];
279
- if (urlHotMeta.disposeCallback) {
280
- console.groupCollapsed(`[jsenv] cleanup ${boundary} (previously used in ${acceptedBy})`);
281
- console.log(`call dispose callback`);
282
- await urlHotMeta.disposeCallback();
283
- console.groupEnd();
266
+ const applyHotReload = async ({ hotInstructions }) => {
267
+ await hotInstructions.reduce(
268
+ async (previous, { type, boundary, acceptedBy }) => {
269
+ await previous;
270
+
271
+ const urlToFetch = new URL(boundary, `${window.location.origin}/`).href;
272
+ const urlHotMeta = urlHotMetas[urlToFetch];
273
+ // there is no url hot meta when:
274
+ // - code was not executed (code splitting with dynamic import)
275
+ // - import.meta.hot.accept() is not called (happens for HTML and CSS)
276
+
277
+ if (type === "prune") {
278
+ if (urlHotMeta) {
279
+ delete urlHotMetas[urlToFetch];
280
+ if (urlHotMeta.disposeCallback) {
281
+ console.groupCollapsed(
282
+ `[jsenv] cleanup ${boundary} (previously used in ${acceptedBy})`,
283
+ );
284
+ console.log(`call dispose callback`);
285
+ await urlHotMeta.disposeCallback();
286
+ console.groupEnd();
287
+ }
284
288
  }
285
- }
286
- return null;
287
- }
288
- if (acceptedBy === boundary) {
289
- console.groupCollapsed(`[jsenv] hot reloading ${boundary}`);
290
- } else {
291
- console.groupCollapsed(`[jsenv] hot reloading ${acceptedBy} usage in ${boundary}`);
292
- }
293
- if (type === "js_module") {
294
- if (!urlHotMeta) {
295
- // code was not executed, no need to re-execute it
296
289
  return null;
297
290
  }
298
- if (urlHotMeta.disposeCallback) {
299
- console.log(`call dispose callback`);
300
- await urlHotMeta.disposeCallback();
291
+
292
+ if (acceptedBy === boundary) {
293
+ console.groupCollapsed(`[jsenv] hot reloading ${boundary}`);
294
+ } else {
295
+ console.groupCollapsed(
296
+ `[jsenv] hot reloading ${acceptedBy} usage in ${boundary}`,
297
+ );
301
298
  }
302
- console.log(`importing js module`);
303
- reloader.currentExecution = {
304
- type: "dynamic_import",
305
- url: urlToFetch
306
- };
307
- const namespace = await reloadJsImport(urlToFetch);
308
- if (urlHotMeta.acceptCallback) {
309
- await urlHotMeta.acceptCallback(namespace);
299
+ if (type === "js_module") {
300
+ if (!urlHotMeta) {
301
+ // code was not executed, no need to re-execute it
302
+ return null;
303
+ }
304
+ if (urlHotMeta.disposeCallback) {
305
+ console.log(`call dispose callback`);
306
+ await urlHotMeta.disposeCallback();
307
+ }
308
+ console.log(`importing js module`);
309
+ reloader.currentExecution = {
310
+ type: "dynamic_import",
311
+ url: urlToFetch,
312
+ };
313
+ const namespace = await reloadJsImport(urlToFetch);
314
+ if (urlHotMeta.acceptCallback) {
315
+ await urlHotMeta.acceptCallback(namespace);
316
+ }
317
+ console.log(`js module import done`);
318
+ console.groupEnd();
319
+ return namespace;
310
320
  }
311
- console.log(`js module import done`);
312
- console.groupEnd();
313
- return namespace;
314
- }
315
- if (type === "html") {
316
- const isRootHtmlFile = window.location.pathname === "/" && new URL(urlToFetch).pathname.slice(1).indexOf("/") === -1;
317
- if (!isRootHtmlFile && !compareTwoUrlPaths(urlToFetch, window.location.href)) {
318
- // we are not in that HTML page
321
+ if (type === "html") {
322
+ const isRootHtmlFile =
323
+ window.location.pathname === "/" &&
324
+ new URL(urlToFetch).pathname.slice(1).indexOf("/") === -1;
325
+ if (
326
+ !isRootHtmlFile &&
327
+ !compareTwoUrlPaths(urlToFetch, window.location.href)
328
+ ) {
329
+ // we are not in that HTML page
330
+ return null;
331
+ }
332
+ const urlToReload = new URL(acceptedBy, `${window.location.origin}/`)
333
+ .href;
334
+ const domNodesUsingUrl = getDOMNodesUsingUrl(urlToReload);
335
+ const domNodesCount = domNodesUsingUrl.length;
336
+ if (domNodesCount === 0) {
337
+ console.log(`no dom node using ${acceptedBy}`);
338
+ } else if (domNodesCount === 1) {
339
+ console.log(`reloading`, domNodesUsingUrl[0].node);
340
+ domNodesUsingUrl[0].reload();
341
+ } else {
342
+ console.log(`reloading ${domNodesCount} nodes using ${acceptedBy}`);
343
+ domNodesUsingUrl.forEach((domNodesUsingUrl) => {
344
+ domNodesUsingUrl.reload();
345
+ });
346
+ }
347
+ console.groupEnd();
319
348
  return null;
320
349
  }
321
- const urlToReload = new URL(acceptedBy, `${window.location.origin}/`).href;
322
- const domNodesUsingUrl = getDOMNodesUsingUrl(urlToReload);
323
- const domNodesCount = domNodesUsingUrl.length;
324
- if (domNodesCount === 0) {
325
- console.log(`no dom node using ${acceptedBy}`);
326
- } else if (domNodesCount === 1) {
327
- console.log(`reloading`, domNodesUsingUrl[0].node);
328
- domNodesUsingUrl[0].reload();
329
- } else {
330
- console.log(`reloading ${domNodesCount} nodes using ${acceptedBy}`);
331
- domNodesUsingUrl.forEach(domNodesUsingUrl => {
332
- domNodesUsingUrl.reload();
333
- });
334
- }
335
- console.groupEnd();
350
+ console.warn(`unknown update type: "${type}"`);
336
351
  return null;
337
- }
338
- console.warn(`unknown update type: "${type}"`);
339
- return null;
340
- }, Promise.resolve());
352
+ },
353
+ Promise.resolve(),
354
+ );
341
355
  };
356
+
342
357
  window.__reloader__ = reloader;
343
358
  window.__server_events__.listenEvents({
344
- reload: reloadServerEvent => {
359
+ reload: (reloadServerEvent) => {
345
360
  reloader.changes.add(reloadServerEvent.data);
346
- }
361
+ },
347
362
  });