@jsenv/core 29.1.19 → 29.2.1

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 (75) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +3 -16
  2. package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -5
  3. package/dist/babel_helpers/applyDecs/applyDecs.js +54 -241
  4. package/dist/babel_helpers/applyDecs2023/applyDecs2023.js +47 -195
  5. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +0 -2
  6. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +2 -1
  7. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +0 -1
  8. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +4 -14
  9. package/dist/babel_helpers/asyncIterator/asyncIterator.js +5 -20
  10. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +2 -8
  11. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +1 -3
  12. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -4
  13. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -1
  14. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -1
  15. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -1
  16. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -1
  17. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +0 -1
  18. package/dist/babel_helpers/construct/construct.js +5 -5
  19. package/dist/babel_helpers/createClass/createClass.js +0 -1
  20. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +5 -9
  21. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +2 -3
  22. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +2 -8
  23. package/dist/babel_helpers/createSuper/createSuper.js +2 -4
  24. package/dist/babel_helpers/decorate/decorate.js +60 -311
  25. package/dist/babel_helpers/defaults/defaults.js +0 -3
  26. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +2 -5
  27. package/dist/babel_helpers/defineProperty/defineProperty.js +0 -1
  28. package/dist/babel_helpers/extends/extends.js +0 -3
  29. package/dist/babel_helpers/get/get.js +0 -3
  30. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -1
  31. package/dist/babel_helpers/inherits/inherits.js +2 -3
  32. package/dist/babel_helpers/instanceof/instanceof.js +0 -1
  33. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +0 -10
  34. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +6 -6
  35. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +0 -5
  36. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +2 -5
  37. package/dist/babel_helpers/jsx/jsx.js +2 -8
  38. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +2 -3
  39. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +1 -1
  40. package/dist/babel_helpers/objectSpread/objectSpread.js +4 -6
  41. package/dist/babel_helpers/objectSpread2/objectSpread2.js +3 -8
  42. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +0 -3
  43. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -2
  44. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +0 -1
  45. package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +634 -0
  46. package/dist/babel_helpers/set/set.js +2 -12
  47. package/dist/babel_helpers/superPropBase/superPropBase.js +0 -1
  48. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -1
  49. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -1
  50. package/dist/babel_helpers/toPrimitive/toPrimitive.js +1 -5
  51. package/dist/babel_helpers/typeof/typeof.js +0 -2
  52. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +0 -7
  53. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +5 -19
  54. package/dist/controllable_child_process.mjs +17 -27
  55. package/dist/controllable_worker_thread.mjs +4 -16
  56. package/dist/js/autoreload.js +13 -56
  57. package/dist/js/execute_using_dynamic_import.js +40 -164
  58. package/dist/js/global_this.js +2 -10
  59. package/dist/js/import_meta_hot.js +3 -9
  60. package/dist/js/new_stylesheet.js +0 -59
  61. package/dist/js/regenerator_runtime.js +80 -156
  62. package/dist/js/s.js +25 -113
  63. package/dist/js/s.js.map +10 -10
  64. package/dist/js/script_type_module_supervisor.js +4 -13
  65. package/dist/js/server_events_client.js +10 -38
  66. package/dist/js/supervisor.js +25 -167
  67. package/dist/js/v8_coverage.js +29 -92
  68. package/dist/js/ws.js +239 -717
  69. package/dist/main.js +761 -4155
  70. package/package.json +6 -6
  71. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +1 -2
  72. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +1 -1
  73. package/src/plugins/plugins.js +1 -1
  74. package/src/plugins/transpilation/as_js_classic/helpers-string.js +1 -0
  75. package/src/plugins/transpilation/babel/global_this/client/global_this.js +0 -2
@@ -2,7 +2,6 @@ export default function (strings, raw) {
2
2
  if (!raw) {
3
3
  raw = strings.slice(0);
4
4
  }
5
-
6
5
  strings.raw = raw;
7
6
  return strings;
8
7
  }
@@ -1,14 +1,10 @@
1
- export default function (input, hint
2
- /* : "default" | "string" | "number" | void */
3
- ) {
1
+ export default function (input, hint /* : "default" | "string" | "number" | void */) {
4
2
  if (typeof input !== "object" || input === null) return input;
5
3
  var prim = input[Symbol.toPrimitive];
6
-
7
4
  if (prim !== undefined) {
8
5
  var res = prim.call(input, hint || "default");
9
6
  if (typeof res !== "object") return res;
10
7
  throw new TypeError("@@toPrimitive must return a primitive value.");
11
8
  }
12
-
13
9
  return (hint === "string" ? String : Number)(input);
14
10
  }
@@ -1,7 +1,5 @@
1
1
  const nativeTypeOf = obj => typeof obj;
2
-
3
2
  const customTypeOf = obj => {
4
3
  return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
5
4
  };
6
-
7
5
  export default typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? nativeTypeOf : customTypeOf;
@@ -2,27 +2,20 @@ import getPrototypeOf from "../getPrototypeOf/getPrototypeOf.js";
2
2
  import setPrototypeOf from "../setPrototypeOf/setPrototypeOf.js";
3
3
  import isNativeFunction from "../isNativeFunction/isNativeFunction.js";
4
4
  import construct from "../construct/construct.js";
5
-
6
5
  var _cache = typeof Map === "function" ? new Map() : undefined;
7
-
8
6
  export default function (Class) {
9
7
  if (Class === null || !isNativeFunction(Class)) return Class;
10
-
11
8
  if (typeof Class !== "function") {
12
9
  throw new TypeError("Super expression must either be null or a function");
13
10
  }
14
-
15
11
  if (typeof _cache !== "undefined") {
16
12
  if (_cache.has(Class)) return _cache.get(Class);
17
-
18
13
  _cache.set(Class, Wrapper);
19
14
  }
20
-
21
15
  function Wrapper() {
22
16
  // eslint-disable-next-line prefer-rest-params
23
17
  return construct(Class, arguments, getPrototypeOf(this).constructor);
24
18
  }
25
-
26
19
  Wrapper.prototype = Object.create(Class.prototype, {
27
20
  constructor: {
28
21
  value: Wrapper,
@@ -4,64 +4,50 @@ export default function _wrapRegExp() {
4
4
  _wrapRegExp = function (re, groups) {
5
5
  return new BabelRegExp(re, undefined, groups);
6
6
  };
7
-
8
7
  var _super = RegExp.prototype;
9
-
10
8
  var _groups = new WeakMap();
11
-
12
9
  function BabelRegExp(re, flags, groups) {
13
- var _this = new RegExp(re, flags); // if the regex is recreated with 'g' flag
14
-
15
-
10
+ var _this = new RegExp(re, flags);
11
+ // if the regex is recreated with 'g' flag
16
12
  _groups.set(_this, groups || _groups.get(re));
17
-
18
13
  return setPrototypeOf(_this, BabelRegExp.prototype);
19
14
  }
20
-
21
15
  inherits(BabelRegExp, RegExp);
22
-
23
16
  BabelRegExp.prototype.exec = function (str) {
24
17
  var result = _super.exec.call(this, str);
25
-
26
18
  if (result) result.groups = buildGroups(result, this);
27
19
  return result;
28
20
  };
29
-
30
21
  BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
31
22
  if (typeof substitution === "string") {
32
23
  var groups = _groups.get(this);
33
-
34
24
  return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
35
25
  return "$" + groups[name];
36
26
  }));
37
27
  } else if (typeof substitution === "function") {
38
28
  var _this = this;
39
-
40
29
  return _super[Symbol.replace].call(this, str, function () {
41
- var args = arguments; // Modern engines already pass result.groups returned by exec() as the last arg.
42
-
30
+ var args = arguments;
31
+ // Modern engines already pass result.groups returned by exec() as the last arg.
43
32
  if (typeof args[args.length - 1] !== "object") {
44
33
  args = [].slice.call(args);
45
34
  args.push(buildGroups(args, _this));
46
35
  }
47
-
48
36
  return substitution.apply(this, args);
49
37
  });
50
38
  } else {
51
39
  return _super[Symbol.replace].call(this, str, substitution);
52
40
  }
53
41
  };
54
-
55
42
  function buildGroups(result, re) {
56
43
  // NOTE: This function should return undefined if there are no groups,
57
44
  // but in that case Babel doesn't add the wrapper anyway.
58
- var g = _groups.get(re);
59
45
 
46
+ var g = _groups.get(re);
60
47
  return Object.keys(g).reduce(function (groups, name) {
61
48
  groups[name] = result[g[name]];
62
49
  return groups;
63
50
  }, Object.create(null));
64
51
  }
65
-
66
52
  return _wrapRegExp.apply(this, arguments);
67
53
  }
@@ -15,12 +15,9 @@ const ACTIONS_AVAILABLE = {
15
15
  fileURLToPath
16
16
  } = await import("node:url");
17
17
  const filePath = fileURLToPath(fileUrl);
18
-
19
- const require = createRequire(fileUrl); // eslint-disable-next-line import/no-dynamic-require
20
-
21
-
18
+ const require = createRequire(fileUrl);
19
+ // eslint-disable-next-line import/no-dynamic-require
22
20
  const namespace = require(filePath);
23
-
24
21
  const namespaceResolved = {};
25
22
  await Promise.all(Object.keys(namespace).map(async key => {
26
23
  const value = await namespace[key];
@@ -33,13 +30,12 @@ const ACTION_REQUEST_EVENT_NAME = "action";
33
30
  const ACTION_RESPONSE_EVENT_NAME = "action-result";
34
31
  const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
35
32
  const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
36
-
37
33
  const sendActionFailed = error => {
38
34
  if (error.hasOwnProperty("toString")) {
39
35
  delete error.toString;
40
36
  }
41
-
42
- sendToParent(ACTION_RESPONSE_EVENT_NAME, // process.send algorithm does not send non enumerable values
37
+ sendToParent(ACTION_RESPONSE_EVENT_NAME,
38
+ // process.send algorithm does not send non enumerable values
43
39
  // so use @jsenv/uneval
44
40
  uneval({
45
41
  status: ACTION_RESPONSE_STATUS_FAILED,
@@ -48,9 +44,9 @@ const sendActionFailed = error => {
48
44
  ignoreSymbols: true
49
45
  }));
50
46
  };
51
-
52
47
  const sendActionCompleted = value => {
53
- sendToParent(ACTION_RESPONSE_EVENT_NAME, // here we use JSON.stringify because we should not
48
+ sendToParent(ACTION_RESPONSE_EVENT_NAME,
49
+ // here we use JSON.stringify because we should not
54
50
  // have non enumerable value (unlike there is on Error objects)
55
51
  // otherwise uneval is quite slow to turn a giant object
56
52
  // into a string (and value can be giant when using coverage)
@@ -59,76 +55,70 @@ const sendActionCompleted = value => {
59
55
  value
60
56
  }));
61
57
  };
62
-
63
58
  const sendToParent = (type, data) => {
64
59
  // https://nodejs.org/api/process.html#process_process_connected
65
60
  // not connected anymore, cannot communicate with parent
66
61
  if (!process.connected) {
67
62
  return;
68
- } // this can keep process alive longer than expected
63
+ }
64
+ // this can keep process alive longer than expected
69
65
  // when source is a long string.
70
66
  // It means node process may stay alive longer than expected
71
67
  // the time to send the data to the parent.
72
-
73
-
74
68
  process.send({
75
69
  jsenv: true,
76
70
  type,
77
71
  data
78
72
  });
79
73
  };
80
-
81
74
  const onceParentMessage = (type, callback) => {
82
75
  const listener = message => {
83
76
  if (message && message.jsenv && message.type === type) {
84
77
  removeListener(); // commenting this line keep this process alive
85
-
86
78
  callback(message.data);
87
79
  }
88
80
  };
89
-
90
81
  const removeListener = () => {
91
82
  process.removeListener("message", listener);
92
83
  };
93
-
94
84
  process.on("message", listener);
95
85
  return removeListener;
96
86
  };
97
-
98
87
  const removeActionRequestListener = onceParentMessage(ACTION_REQUEST_EVENT_NAME, async ({
99
88
  actionType,
100
89
  actionParams
101
90
  }) => {
102
91
  const action = ACTIONS_AVAILABLE[actionType];
103
-
104
92
  if (!action) {
105
93
  sendActionFailed(new Error(`unknown action ${actionType}`));
106
94
  return;
107
95
  }
108
-
109
96
  let value;
110
97
  let failed = false;
111
-
112
98
  try {
113
99
  value = await action(actionParams);
114
100
  } catch (e) {
115
101
  failed = true;
116
102
  value = e;
117
- } // setTimeout(() => {}, 100)
103
+ }
118
104
 
105
+ // setTimeout(() => {}, 100)
119
106
 
120
107
  if (failed) {
121
108
  sendActionFailed(value);
122
109
  } else {
123
110
  sendActionCompleted(value);
124
- } // removeActionRequestListener()
125
-
111
+ }
126
112
 
113
+ // removeActionRequestListener()
127
114
  if (actionParams.exitAfterAction) {
128
- removeActionRequestListener(); // for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
115
+ removeActionRequestListener();
116
+ // for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
129
117
  // process.exit()
130
118
  }
131
- }); // remove listener to process.on('message')
119
+ });
120
+
121
+ // remove listener to process.on('message')
132
122
  // which is sufficient to let child process die
133
123
  // assuming nothing else keeps it alive
134
124
  // process.once("SIGTERM", removeActionRequestListener)
@@ -11,13 +11,12 @@ const ACTION_REQUEST_EVENT_NAME = "action";
11
11
  const ACTION_RESPONSE_EVENT_NAME = "action-result";
12
12
  const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
13
13
  const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
14
-
15
14
  const sendActionFailed = error => {
16
15
  if (error.hasOwnProperty("toString")) {
17
16
  delete error.toString;
18
17
  }
19
-
20
- sendToParent(ACTION_RESPONSE_EVENT_NAME, // process.send algorithm does not send non enumerable values
18
+ sendToParent(ACTION_RESPONSE_EVENT_NAME,
19
+ // process.send algorithm does not send non enumerable values
21
20
  // so use @jsenv/uneval
22
21
  uneval({
23
22
  status: ACTION_RESPONSE_STATUS_FAILED,
@@ -26,9 +25,9 @@ const sendActionFailed = error => {
26
25
  ignoreSymbols: true
27
26
  }));
28
27
  };
29
-
30
28
  const sendActionCompleted = value => {
31
- sendToParent(ACTION_RESPONSE_EVENT_NAME, // here we use JSON.stringify because we should not
29
+ sendToParent(ACTION_RESPONSE_EVENT_NAME,
30
+ // here we use JSON.stringify because we should not
32
31
  // have non enumerable value (unlike there is on Error objects)
33
32
  // otherwise uneval is quite slow to turn a giant object
34
33
  // into a string (and value can be giant when using coverage)
@@ -37,7 +36,6 @@ const sendActionCompleted = value => {
37
36
  value
38
37
  }));
39
38
  };
40
-
41
39
  const sendToParent = (type, data) => {
42
40
  // this can keep process alive longer than expected
43
41
  // when source is a long string.
@@ -49,51 +47,41 @@ const sendToParent = (type, data) => {
49
47
  data
50
48
  });
51
49
  };
52
-
53
50
  const onceParentMessage = (type, callback) => {
54
51
  const listener = message => {
55
52
  if (message && message.jsenv && message.type === type) {
56
53
  removeListener(); // commenting this line keep this worker alive
57
-
58
54
  callback(message.data);
59
55
  }
60
56
  };
61
-
62
57
  const removeListener = () => {
63
58
  parentPort.removeListener("message", listener);
64
59
  };
65
-
66
60
  parentPort.on("message", listener);
67
61
  return removeListener;
68
62
  };
69
-
70
63
  const removeActionRequestListener = onceParentMessage(ACTION_REQUEST_EVENT_NAME, async ({
71
64
  actionType,
72
65
  actionParams
73
66
  }) => {
74
67
  const action = ACTIONS_AVAILABLE[actionType];
75
-
76
68
  if (!action) {
77
69
  sendActionFailed(new Error(`unknown action ${actionType}`));
78
70
  return;
79
71
  }
80
-
81
72
  let value;
82
73
  let failed = false;
83
-
84
74
  try {
85
75
  value = await action(actionParams);
86
76
  } catch (e) {
87
77
  failed = true;
88
78
  value = e;
89
79
  }
90
-
91
80
  if (failed) {
92
81
  sendActionFailed(value);
93
82
  } else {
94
83
  sendActionCompleted(value);
95
84
  }
96
-
97
85
  if (actionParams.exitAfterAction) {
98
86
  removeActionRequestListener();
99
87
  }
@@ -3,11 +3,9 @@ import { parseSrcSet, stringifySrcSet } from "@jsenv/ast/src/html/html_src_set.j
3
3
 
4
4
  const isAutoreloadEnabled = () => {
5
5
  const value = window.localStorage.getItem("autoreload");
6
-
7
6
  if (value === "0") {
8
7
  return false;
9
8
  }
10
-
11
9
  return true;
12
10
  };
13
11
  const setAutoreloadPreference = value => {
@@ -18,7 +16,6 @@ const compareTwoUrlPaths = (url, otherUrl) => {
18
16
  if (url === otherUrl) {
19
17
  return true;
20
18
  }
21
-
22
19
  const urlObject = new URL(url);
23
20
  const otherUrlObject = new URL(otherUrl);
24
21
  return urlObject.origin === otherUrlObject.origin && urlObject.pathname === otherUrlObject.pathname;
@@ -36,33 +33,28 @@ const injectQuery = (url, query) => {
36
33
 
37
34
  const reloadHtmlPage = () => {
38
35
  window.location.reload(true);
39
- }; // This function can consider everything as hot reloadable:
36
+ };
37
+
38
+ // This function can consider everything as hot reloadable:
40
39
  // - no need to check [hot-accept]and [hot-decline] attributes for instance
41
40
  // This is because if something should full reload, we receive "full_reload"
42
41
  // from server and this function is not called
43
-
44
42
  const getDOMNodesUsingUrl = urlToReload => {
45
43
  const nodes = [];
46
-
47
44
  const shouldReloadUrl = urlCandidate => {
48
45
  return compareTwoUrlPaths(urlCandidate, urlToReload);
49
46
  };
50
-
51
47
  const visitNodeAttributeAsUrl = (node, attributeName) => {
52
48
  let attribute = node[attributeName];
53
-
54
49
  if (!attribute) {
55
50
  return;
56
51
  }
57
-
58
52
  if (SVGAnimatedString && attribute instanceof SVGAnimatedString) {
59
53
  attribute = attribute.animVal;
60
54
  }
61
-
62
55
  if (!shouldReloadUrl(attribute)) {
63
56
  return;
64
57
  }
65
-
66
58
  nodes.push({
67
59
  node,
68
60
  reload: () => {
@@ -74,7 +66,6 @@ const getDOMNodesUsingUrl = urlToReload => {
74
66
  copy.src = injectQuery(node.src, {
75
67
  hmr: Date.now()
76
68
  });
77
-
78
69
  if (node.parentNode) {
79
70
  node.parentNode.replaceChild(copy, node);
80
71
  } else {
@@ -88,7 +79,6 @@ const getDOMNodesUsingUrl = urlToReload => {
88
79
  }
89
80
  });
90
81
  };
91
-
92
82
  Array.from(document.querySelectorAll(`link[rel="stylesheet"]`)).forEach(link => {
93
83
  visitNodeAttributeAsUrl(link, "href");
94
84
  });
@@ -98,10 +88,8 @@ const getDOMNodesUsingUrl = urlToReload => {
98
88
  Array.from(document.querySelectorAll("script")).forEach(script => {
99
89
  visitNodeAttributeAsUrl(script, "src");
100
90
  const inlinedFromSrc = script.getAttribute("inlined-from-src");
101
-
102
91
  if (inlinedFromSrc) {
103
92
  const inlinedFromUrl = new URL(inlinedFromSrc, window.location.origin).href;
104
-
105
93
  if (shouldReloadUrl(inlinedFromUrl)) {
106
94
  nodes.push({
107
95
  node: script,
@@ -112,28 +100,26 @@ const getDOMNodesUsingUrl = urlToReload => {
112
100
  });
113
101
  }
114
102
  }
115
- }); // There is no real need to update a.href because the resource will be fetched when clicked.
103
+ });
104
+ // There is no real need to update a.href because the resource will be fetched when clicked.
116
105
  // But in a scenario where the resource was already visited and is in browser cache, adding
117
106
  // the dynamic query param ensure the cache is invalidated
118
-
119
107
  Array.from(document.querySelectorAll("a")).forEach(a => {
120
108
  visitNodeAttributeAsUrl(a, "href");
121
- }); // About iframes:
109
+ });
110
+ // About iframes:
122
111
  // - By default iframe itself and everything inside trigger a parent page full-reload
123
112
  // - Adding [hot-accept] on the iframe means parent page won't reload when iframe full/hot reload
124
113
  // In that case and if there is code in the iframe and parent doing post message communication:
125
114
  // you must put import.meta.hot.decline() for code involved in communication.
126
115
  // (both in parent and iframe)
127
-
128
116
  Array.from(document.querySelectorAll("img")).forEach(img => {
129
117
  visitNodeAttributeAsUrl(img, "src");
130
118
  const srcset = img.srcset;
131
-
132
119
  if (srcset) {
133
120
  const srcCandidates = parseSrcSet(srcset);
134
121
  srcCandidates.forEach(srcCandidate => {
135
122
  const url = new URL(srcCandidate.specifier, `${window.location.href}`);
136
-
137
123
  if (shouldReloadUrl(url)) {
138
124
  srcCandidate.specifier = injectQuery(url, {
139
125
  hmr: Date.now()
@@ -150,12 +136,12 @@ const getDOMNodesUsingUrl = urlToReload => {
150
136
  });
151
137
  Array.from(document.querySelectorAll("source")).forEach(source => {
152
138
  visitNodeAttributeAsUrl(source, "src");
153
- }); // svg image tag
154
-
139
+ });
140
+ // svg image tag
155
141
  Array.from(document.querySelectorAll("image")).forEach(image => {
156
142
  visitNodeAttributeAsUrl(image, "href");
157
- }); // svg use
158
-
143
+ });
144
+ // svg use
159
145
  Array.from(document.querySelectorAll("use")).forEach(use => {
160
146
  visitNodeAttributeAsUrl(use, "href");
161
147
  });
@@ -183,7 +169,6 @@ const reloader = {
183
169
  messages: [],
184
170
  addMessage: reloadMessage => {
185
171
  reloader.messages.push(reloadMessage);
186
-
187
172
  if (isAutoreloadEnabled()) {
188
173
  reloader.reload();
189
174
  } else {
@@ -192,42 +177,34 @@ const reloader = {
192
177
  },
193
178
  reload: () => {
194
179
  const someEffectIsFullReload = reloader.messages.some(reloadMessage => reloadMessage.type === "full");
195
-
196
180
  if (someEffectIsFullReload) {
197
181
  reloadHtmlPage();
198
182
  return;
199
183
  }
200
-
201
184
  reloader.setStatus("reloading");
202
-
203
185
  const onApplied = reloadMessage => {
204
186
  const index = reloader.messages.indexOf(reloadMessage);
205
187
  reloader.messages.splice(index, 1);
206
-
207
188
  if (reloader.messages.length === 0) {
208
189
  reloader.setStatus("idle");
209
190
  }
210
191
  };
211
-
212
192
  const setReloadMessagePromise = (reloadMessage, promise) => {
213
193
  promise.then(() => {
214
194
  onApplied(reloadMessage);
215
195
  reloader.currentExecution = null;
216
196
  }, e => {
217
197
  reloader.setStatus("failed");
218
-
219
198
  if (typeof window.reportError === "function") {
220
199
  window.reportError(e);
221
200
  } else {
222
201
  console.error(e);
223
202
  }
224
-
225
203
  console.error(`[jsenv] Hot reload failed after ${reloadMessage.reason}.
226
204
  This could be due to syntax errors or importing non-existent modules (see errors in console)`);
227
205
  reloader.currentExecution = null;
228
206
  });
229
207
  };
230
-
231
208
  reloader.messages.forEach(reloadMessage => {
232
209
  if (reloadMessage.type === "hot") {
233
210
  const promise = addToHotQueue(() => {
@@ -242,21 +219,17 @@ This could be due to syntax errors or importing non-existent modules (see errors
242
219
  };
243
220
  let pendingCallbacks = [];
244
221
  let running = false;
245
-
246
222
  const addToHotQueue = async callback => {
247
223
  pendingCallbacks.push(callback);
248
224
  dequeue();
249
225
  };
250
-
251
226
  const dequeue = async () => {
252
227
  if (running) {
253
228
  return;
254
229
  }
255
-
256
230
  const callbacks = pendingCallbacks.slice();
257
231
  pendingCallbacks = [];
258
232
  running = true;
259
-
260
233
  try {
261
234
  await callbacks.reduce(async (previous, callback) => {
262
235
  await previous;
@@ -264,13 +237,11 @@ const dequeue = async () => {
264
237
  }, Promise.resolve());
265
238
  } finally {
266
239
  running = false;
267
-
268
240
  if (pendingCallbacks.length) {
269
241
  dequeue();
270
242
  }
271
243
  }
272
244
  };
273
-
274
245
  const applyHotReload = async ({
275
246
  hotInstructions
276
247
  }) => {
@@ -281,14 +252,14 @@ const applyHotReload = async ({
281
252
  }) => {
282
253
  await previous;
283
254
  const urlToFetch = new URL(boundary, `${window.location.origin}/`).href;
284
- const urlHotMeta = urlHotMetas[urlToFetch]; // there is no url hot meta when:
255
+ const urlHotMeta = urlHotMetas[urlToFetch];
256
+ // there is no url hot meta when:
285
257
  // - code was not executed (code splitting with dynamic import)
286
258
  // - import.meta.hot.accept() is not called (happens for HTML and CSS)
287
259
 
288
260
  if (type === "prune") {
289
261
  if (urlHotMeta) {
290
262
  delete urlHotMetas[urlToFetch];
291
-
292
263
  if (urlHotMeta.disposeCallback) {
293
264
  console.groupCollapsed(`[jsenv] cleanup ${boundary} (previously used in ${acceptedBy})`);
294
265
  console.log(`call dispose callback`);
@@ -296,53 +267,43 @@ const applyHotReload = async ({
296
267
  console.groupEnd();
297
268
  }
298
269
  }
299
-
300
270
  return null;
301
271
  }
302
-
303
272
  if (acceptedBy === boundary) {
304
273
  console.groupCollapsed(`[jsenv] hot reloading ${boundary}`);
305
274
  } else {
306
275
  console.groupCollapsed(`[jsenv] hot reloading ${acceptedBy} usage in ${boundary}`);
307
276
  }
308
-
309
277
  if (type === "js_module") {
310
278
  if (!urlHotMeta) {
311
279
  // code was not executed, no need to re-execute it
312
280
  return null;
313
281
  }
314
-
315
282
  if (urlHotMeta.disposeCallback) {
316
283
  console.log(`call dispose callback`);
317
284
  await urlHotMeta.disposeCallback();
318
285
  }
319
-
320
286
  console.log(`importing js module`);
321
287
  reloader.currentExecution = {
322
288
  type: "dynamic_import",
323
289
  url: urlToFetch
324
290
  };
325
291
  const namespace = await reloadJsImport(urlToFetch);
326
-
327
292
  if (urlHotMeta.acceptCallback) {
328
293
  await urlHotMeta.acceptCallback(namespace);
329
294
  }
330
-
331
295
  console.log(`js module import done`);
332
296
  console.groupEnd();
333
297
  return namespace;
334
298
  }
335
-
336
299
  if (type === "html") {
337
300
  if (!compareTwoUrlPaths(urlToFetch, window.location.href)) {
338
301
  // we are not in that HTML page
339
302
  return null;
340
303
  }
341
-
342
304
  const urlToReload = new URL(acceptedBy, `${window.location.origin}/`).href;
343
305
  const domNodesUsingUrl = getDOMNodesUsingUrl(urlToReload);
344
306
  const domNodesCount = domNodesUsingUrl.length;
345
-
346
307
  if (domNodesCount === 0) {
347
308
  console.log(`no dom node using ${acceptedBy}`);
348
309
  } else if (domNodesCount === 1) {
@@ -354,18 +315,14 @@ const applyHotReload = async ({
354
315
  domNodesUsingUrl.reload();
355
316
  });
356
317
  }
357
-
358
318
  console.groupEnd();
359
319
  return null;
360
320
  }
361
-
362
321
  console.warn(`unknown update type: "${type}"`);
363
322
  return null;
364
323
  }, Promise.resolve());
365
324
  };
366
-
367
325
  window.__reloader__ = reloader;
368
-
369
326
  window.__server_events__.listenEvents({
370
327
  reload: reloadServerEvent => {
371
328
  reloader.addMessage(reloadServerEvent.data);