@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 @@ window.__supervisor__ = (() => {
2
2
  const notImplemented = () => {
3
3
  throw new Error(`window.__supervisor__.setup() not called`);
4
4
  };
5
-
6
5
  const executionResults = {};
7
6
  const supervisor = {
8
7
  reportError: notImplemented,
@@ -12,13 +11,11 @@ window.__supervisor__ = (() => {
12
11
  executionResults
13
12
  };
14
13
  let navigationStartTime;
15
-
16
14
  try {
17
15
  navigationStartTime = window.performance.timing.navigationStart;
18
16
  } catch (e) {
19
17
  navigationStartTime = Date.now();
20
18
  }
21
-
22
19
  supervisor.setupReportException = ({
23
20
  rootDirectoryUrl,
24
21
  errorNotification,
@@ -29,7 +26,6 @@ window.__supervisor__ = (() => {
29
26
  const DYNAMIC_IMPORT_FETCH_ERROR = "dynamic_import_fetch_error";
30
27
  const DYNAMIC_IMPORT_EXPORT_MISSING = "dynamic_import_export_missing";
31
28
  const DYNAMIC_IMPORT_SYNTAX_ERROR = "dynamic_import_syntax_error";
32
-
33
29
  const createException = ({
34
30
  reason,
35
31
  reportedBy,
@@ -57,28 +53,23 @@ window.__supervisor__ = (() => {
57
53
  originalUrl: null
58
54
  }
59
55
  };
60
-
61
56
  const writeBasicProperties = () => {
62
57
  if (reason === undefined) {
63
58
  exception.message = "undefined";
64
59
  return;
65
60
  }
66
-
67
61
  if (reason === null) {
68
62
  exception.message = "null";
69
63
  return;
70
64
  }
71
-
72
65
  if (typeof reason === "string") {
73
66
  exception.message = reason;
74
67
  return;
75
68
  }
76
-
77
69
  if (reason instanceof Error) {
78
70
  const error = reason;
79
71
  let message = error.message;
80
72
  exception.isError = true;
81
-
82
73
  if (Error.captureStackTrace) {
83
74
  // stackTrace formatted by V8
84
75
  exception.message = message;
@@ -91,108 +82,88 @@ window.__supervisor__ = (() => {
91
82
  exception.stackFormatIsV8 = false;
92
83
  exception.stackSourcemapped = false;
93
84
  }
94
-
95
85
  if (error.reportedBy) {
96
86
  exception.reportedBy = error.reportedBy;
97
87
  }
98
-
99
88
  if (error.url) {
100
89
  Object.assign(exception.site, resolveUrlSite({
101
90
  url: error.url
102
91
  }));
103
92
  }
104
-
105
93
  if (error.needsReport) {
106
94
  exception.needsReport = true;
107
95
  }
108
-
109
96
  {
110
97
  // chrome
111
98
  if (message.includes("does not provide an export named")) {
112
99
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
113
100
  return;
114
- } // firefox
115
-
116
-
101
+ }
102
+ // firefox
117
103
  if (message.startsWith("import not found:") || message.startsWith("ambiguous indirect export:")) {
118
104
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
119
105
  return;
120
- } // safari
121
-
122
-
106
+ }
107
+ // safari
123
108
  if (message.startsWith("import binding name")) {
124
109
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
125
110
  return;
126
111
  }
127
112
  }
128
-
129
113
  {
130
114
  if (error.name === "SyntaxError" && typeof line === "number") {
131
115
  exception.code = DYNAMIC_IMPORT_SYNTAX_ERROR;
132
116
  return;
133
117
  }
134
118
  }
135
-
136
119
  return;
137
120
  }
138
-
139
121
  if (typeof reason === "object") {
140
122
  exception.code = reason.code;
141
123
  exception.message = reason.message;
142
124
  exception.stack = reason.stack;
143
-
144
125
  if (reason.reportedBy) {
145
126
  exception.reportedBy = reason.reportedBy;
146
127
  }
147
-
148
128
  if (reason.url) {
149
129
  Object.assign(exception.site, resolveUrlSite({
150
130
  url: reason.url
151
131
  }));
152
132
  }
153
-
154
133
  if (reason.needsReport) {
155
134
  exception.needsReport = true;
156
135
  }
157
-
158
136
  return;
159
137
  }
160
-
161
138
  exception.message = JSON.stringify(reason);
162
139
  };
140
+ writeBasicProperties();
163
141
 
164
- writeBasicProperties(); // first create a version of the stack with file://
142
+ // first create a version of the stack with file://
165
143
  // (and use it to locate exception url+line+column)
166
-
167
144
  if (exception.stack) {
168
145
  exception.originalStack = exception.stack;
169
146
  exception.stack = replaceUrls(exception.originalStack, serverUrlSite => {
170
147
  const fileUrlSite = resolveUrlSite(serverUrlSite);
171
-
172
148
  if (exception.site.url === null) {
173
149
  Object.assign(exception.site, fileUrlSite);
174
150
  }
175
-
176
151
  return stringifyUrlSite(fileUrlSite);
177
152
  });
178
- } // then if it fails, use url+line+column passed
179
-
180
-
153
+ }
154
+ // then if it fails, use url+line+column passed
181
155
  if (exception.site.url === null && url) {
182
156
  if (typeof line === "string") {
183
157
  line = parseInt(line);
184
158
  }
185
-
186
159
  if (typeof column === "string") {
187
160
  column = parseInt(column);
188
161
  }
189
-
190
162
  const fileUrlSite = resolveUrlSite({
191
163
  url,
192
164
  line,
193
165
  column
194
166
  });
195
-
196
167
  if (fileUrlSite.isInline && exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR) {
197
168
  // syntax error on inline script need line-1 for some reason
198
169
  if (Error.captureStackTrace) {
@@ -202,14 +173,11 @@ window.__supervisor__ = (() => {
202
173
  fileUrlSite.line -= 2;
203
174
  }
204
175
  }
205
-
206
176
  Object.assign(exception.site, fileUrlSite);
207
177
  }
208
-
209
178
  exception.text = stringifyMessageAndStack(exception);
210
179
  return exception;
211
180
  };
212
-
213
181
  const stringifyMessageAndStack = ({
214
182
  message,
215
183
  stack
@@ -217,14 +185,11 @@ window.__supervisor__ = (() => {
217
185
  if (message && stack) {
218
186
  return `${message}\n${stack}`;
219
187
  }
220
-
221
188
  if (stack) {
222
189
  return stack;
223
190
  }
224
-
225
191
  return message;
226
192
  };
227
-
228
193
  const stringifyUrlSite = ({
229
194
  url,
230
195
  line,
@@ -233,21 +198,17 @@ window.__supervisor__ = (() => {
233
198
  if (typeof line === "number" && typeof column === "number") {
234
199
  return `${url}:${line}:${column}`;
235
200
  }
236
-
237
201
  if (typeof line === "number") {
238
202
  return `${url}:${line}`;
239
203
  }
240
-
241
204
  return url;
242
205
  };
243
-
244
206
  const resolveUrlSite = ({
245
207
  url,
246
208
  line,
247
209
  column
248
210
  }) => {
249
211
  const inlineUrlMatch = url.match(/@L([0-9]+)C([0-9]+)\-L([0-9]+)C([0-9]+)(\.[\w]+)$/);
250
-
251
212
  if (inlineUrlMatch) {
252
213
  const htmlUrl = url.slice(0, inlineUrlMatch.index);
253
214
  const tagLineStart = parseInt(inlineUrlMatch[1]);
@@ -256,12 +217,11 @@ window.__supervisor__ = (() => {
256
217
  const tagColumnEnd = parseInt(inlineUrlMatch[4]);
257
218
  const extension = inlineUrlMatch[5];
258
219
  url = htmlUrl;
259
- line = tagLineStart + (typeof line === "number" ? line : 0); // stackTrace formatted by V8 (chrome)
260
-
220
+ line = tagLineStart + (typeof line === "number" ? line : 0);
221
+ // stackTrace formatted by V8 (chrome)
261
222
  if (Error.captureStackTrace) {
262
223
  line--;
263
224
  }
264
-
265
225
  column = tagColumnStart + (typeof column === "number" ? column : 0);
266
226
  const fileUrl = resolveFileUrl(url);
267
227
  return {
@@ -273,7 +233,6 @@ window.__supervisor__ = (() => {
273
233
  column
274
234
  };
275
235
  }
276
-
277
236
  return {
278
237
  isInline: false,
279
238
  serverUrl: url,
@@ -282,65 +241,53 @@ window.__supervisor__ = (() => {
282
241
  column
283
242
  };
284
243
  };
285
-
286
244
  const getErrorStackWithoutErrorMessage = error => {
287
245
  let stack = error.stack;
288
246
  if (!stack) return "";
289
247
  const messageInStack = `${error.name}: ${error.message}`;
290
-
291
248
  if (stack.startsWith(messageInStack)) {
292
249
  stack = stack.slice(messageInStack.length);
293
250
  }
294
-
295
251
  const nextLineIndex = stack.indexOf("\n");
296
-
297
252
  if (nextLineIndex > -1) {
298
253
  stack = stack.slice(nextLineIndex + 1);
299
254
  }
300
-
301
255
  return stack;
302
256
  };
303
-
304
257
  const resolveFileUrl = url => {
305
258
  let urlObject = new URL(url);
306
-
307
259
  if (urlObject.origin === window.origin) {
308
260
  urlObject = new URL(`${urlObject.pathname.slice(1)}${urlObject.search}`, rootDirectoryUrl);
309
261
  }
310
-
311
262
  if (urlObject.href.startsWith("file:")) {
312
263
  const atFsIndex = urlObject.pathname.indexOf("/@fs/");
313
-
314
264
  if (atFsIndex > -1) {
315
265
  const afterAtFs = urlObject.pathname.slice(atFsIndex + "/@fs/".length);
316
266
  return new URL(afterAtFs, "file:///").href;
317
267
  }
318
268
  }
319
-
320
269
  return urlObject.href;
321
- }; // `Error: yo
270
+ };
271
+
272
+ // `Error: yo
322
273
  // at Object.execute (http://127.0.0.1:57300/build/src/__test__/file-throw.js:9:13)
323
274
  // at doExec (http://127.0.0.1:3000/src/__test__/file-throw.js:452:38)
324
275
  // at postOrderExec (http://127.0.0.1:3000/src/__test__/file-throw.js:448:16)
325
276
  // at http://127.0.0.1:3000/src/__test__/file-throw.js:399:18`.replace(/(?:https?|ftp|file):\/\/(.*+)$/gm, (...args) => {
326
277
  // debugger
327
278
  // })
328
-
329
-
330
279
  const replaceUrls = (source, replace) => {
331
280
  return source.replace(/(?:https?|ftp|file):\/\/\S+/gm, match => {
332
281
  let replacement = "";
333
- const lastChar = match[match.length - 1]; // hotfix because our url regex sucks a bit
282
+ const lastChar = match[match.length - 1];
334
283
 
284
+ // hotfix because our url regex sucks a bit
335
285
  const endsWithSeparationChar = lastChar === ")" || lastChar === ":";
336
-
337
286
  if (endsWithSeparationChar) {
338
287
  match = match.slice(0, -1);
339
288
  }
340
-
341
289
  const lineAndColumnPattern = /:([0-9]+):([0-9]+)$/;
342
290
  const lineAndColumMatch = match.match(lineAndColumnPattern);
343
-
344
291
  if (lineAndColumMatch) {
345
292
  const lineAndColumnString = lineAndColumMatch[0];
346
293
  const lineString = lineAndColumMatch[1];
@@ -353,7 +300,6 @@ window.__supervisor__ = (() => {
353
300
  } else {
354
301
  const linePattern = /:([0-9]+)$/;
355
302
  const lineMatch = match.match(linePattern);
356
-
357
303
  if (lineMatch) {
358
304
  const lineString = lineMatch[0];
359
305
  replacement = replace({
@@ -366,17 +312,13 @@ window.__supervisor__ = (() => {
366
312
  });
367
313
  }
368
314
  }
369
-
370
315
  if (endsWithSeparationChar) {
371
316
  return `${replacement}${lastChar}`;
372
317
  }
373
-
374
318
  return replacement;
375
319
  });
376
320
  };
377
-
378
321
  let formatError;
379
-
380
322
  {
381
323
  formatError = exceptionInfo => {
382
324
  const errorParts = {
@@ -389,7 +331,6 @@ window.__supervisor__ = (() => {
389
331
  const tips = [];
390
332
  tips.push("Click outside to close.");
391
333
  errorParts.tip = tips.join(`\n <br />\n `);
392
-
393
334
  const generateClickableText = text => {
394
335
  const textWithHtmlLinks = makeLinksClickable(text, {
395
336
  createLink: ({
@@ -402,7 +343,6 @@ window.__supervisor__ = (() => {
402
343
  line,
403
344
  column
404
345
  });
405
-
406
346
  if (errorBaseUrl) {
407
347
  if (urlSite.url.startsWith(rootDirectoryUrl)) {
408
348
  urlSite.url = `${errorBaseUrl}${urlSite.url.slice(rootDirectoryUrl.length)}`;
@@ -410,7 +350,6 @@ window.__supervisor__ = (() => {
410
350
  urlSite.url = "file:///mocked_for_snapshots";
411
351
  }
412
352
  }
413
-
414
353
  const urlWithLineAndColumn = stringifyUrlSite(urlSite);
415
354
  return {
416
355
  href: urlSite.url.startsWith("file:") && openInEditor ? `javascript:window.fetch('/__open_in_editor__/${encodeURIComponent(urlWithLineAndColumn)}')` : urlSite.url,
@@ -420,28 +359,22 @@ window.__supervisor__ = (() => {
420
359
  });
421
360
  return textWithHtmlLinks;
422
361
  };
423
-
424
362
  errorParts.text = stringifyMessageAndStack({
425
363
  message: exceptionInfo.message ? generateClickableText(exceptionInfo.message) : "",
426
364
  stack: exceptionInfo.stack ? generateClickableText(exceptionInfo.stack) : ""
427
365
  });
428
-
429
366
  if (exceptionInfo.site.url) {
430
367
  errorParts.errorDetailsPromise = (async () => {
431
368
  try {
432
369
  if (exceptionInfo.code === DYNAMIC_IMPORT_FETCH_ERROR || exceptionInfo.reportedBy === "script_error_event") {
433
370
  const response = await window.fetch(`/__get_error_cause__/${encodeURIComponent(exceptionInfo.site.isInline ? exceptionInfo.site.originalUrl : exceptionInfo.site.url)}`);
434
-
435
371
  if (response.status !== 200) {
436
372
  return null;
437
373
  }
438
-
439
374
  const causeInfo = await response.json();
440
-
441
375
  if (!causeInfo) {
442
376
  return null;
443
377
  }
444
-
445
378
  const causeText = causeInfo.code === "NOT_FOUND" ? stringifyMessageAndStack({
446
379
  message: generateClickableText(causeInfo.reason),
447
380
  stack: generateClickableText(causeInfo.codeFrame)
@@ -453,21 +386,17 @@ window.__supervisor__ = (() => {
453
386
  cause: causeText
454
387
  };
455
388
  }
456
-
457
- if (exceptionInfo.site.line !== undefined && // code frame showing internal window.reportError is pointless
389
+ if (exceptionInfo.site.line !== undefined &&
390
+ // code frame showing internal window.reportError is pointless
458
391
  !exceptionInfo.site.url.endsWith(`script_type_module_supervisor.js`)) {
459
392
  const urlToFetch = new URL(`/__get_code_frame__/${encodeURIComponent(stringifyUrlSite(exceptionInfo.site))}`, window.origin);
460
-
461
393
  if (!exceptionInfo.stackSourcemapped) {
462
394
  urlToFetch.searchParams.set("remap", "");
463
395
  }
464
-
465
396
  const response = await window.fetch(urlToFetch);
466
-
467
397
  if (response.status !== 200) {
468
398
  return null;
469
399
  }
470
-
471
400
  const codeFrame = await response.text();
472
401
  return {
473
402
  codeFrame: generateClickableText(codeFrame)
@@ -477,14 +406,11 @@ window.__supervisor__ = (() => {
477
406
  // happens if server is closed for instance
478
407
  return null;
479
408
  }
480
-
481
409
  return null;
482
410
  })();
483
411
  }
484
-
485
412
  return errorParts;
486
413
  };
487
-
488
414
  const makeLinksClickable = (string, {
489
415
  createLink = ({
490
416
  url
@@ -492,8 +418,8 @@ window.__supervisor__ = (() => {
492
418
  }) => {
493
419
  // normalize line breaks
494
420
  string = string.replace(/\n/g, "\n");
495
- string = escapeHtml(string); // render links
496
-
421
+ string = escapeHtml(string);
422
+ // render links
497
423
  string = replaceUrls(string, ({
498
424
  url,
499
425
  line,
@@ -514,19 +440,15 @@ window.__supervisor__ = (() => {
514
440
  });
515
441
  return string;
516
442
  };
517
-
518
443
  const escapeHtml = string => {
519
444
  return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
520
445
  };
521
-
522
446
  const link = ({
523
447
  href,
524
448
  text = href
525
449
  }) => `<a href="${href}">${text}</a>`;
526
450
  }
527
-
528
451
  let displayErrorNotification;
529
-
530
452
  {
531
453
  const {
532
454
  Notification
@@ -542,17 +464,14 @@ window.__supervisor__ = (() => {
542
464
  body: text,
543
465
  icon
544
466
  });
545
-
546
467
  notification.onclick = () => {
547
468
  window.focus();
548
469
  };
549
470
  }
550
471
  } : () => {};
551
472
  }
552
-
553
473
  const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay";
554
474
  let displayJsenvErrorOverlay;
555
-
556
475
  {
557
476
  displayJsenvErrorOverlay = params => {
558
477
  let jsenvErrorOverlay = new JsenvErrorOverlay(params);
@@ -560,17 +479,14 @@ window.__supervisor__ = (() => {
560
479
  node.parentNode.removeChild(node);
561
480
  });
562
481
  document.body.appendChild(jsenvErrorOverlay);
563
-
564
482
  const removeErrorOverlay = () => {
565
483
  if (jsenvErrorOverlay && jsenvErrorOverlay.parentNode) {
566
484
  document.body.removeChild(jsenvErrorOverlay);
567
485
  jsenvErrorOverlay = null;
568
486
  }
569
487
  };
570
-
571
488
  return removeErrorOverlay;
572
489
  };
573
-
574
490
  class JsenvErrorOverlay extends HTMLElement {
575
491
  constructor({
576
492
  theme,
@@ -597,32 +513,26 @@ window.__supervisor__ = (() => {
597
513
  ${tip}
598
514
  </div>
599
515
  </div>`;
600
-
601
516
  this.root.querySelector(".backdrop").onclick = () => {
602
517
  if (!this.parentNode) {
603
518
  // not in document anymore
604
519
  return;
605
520
  }
606
-
607
521
  this.root.querySelector(".backdrop").onclick = null;
608
522
  this.parentNode.removeChild(this);
609
523
  };
610
-
611
524
  if (errorDetailsPromise) {
612
525
  errorDetailsPromise.then(errorDetails => {
613
526
  if (!errorDetails || !this.parentNode) {
614
527
  return;
615
528
  }
616
-
617
529
  const {
618
530
  codeFrame,
619
531
  cause
620
532
  } = errorDetails;
621
-
622
533
  if (codeFrame) {
623
534
  this.root.querySelector(".text").innerHTML += `\n\n${codeFrame}`;
624
535
  }
625
-
626
536
  if (cause) {
627
537
  const causeIndented = prefixRemainingLines(cause, " ");
628
538
  this.root.querySelector(".text").innerHTML += `\n [cause]: ${causeIndented}`;
@@ -630,28 +540,22 @@ window.__supervisor__ = (() => {
630
540
  });
631
541
  }
632
542
  }
633
-
634
543
  }
635
-
636
544
  const prefixRemainingLines = (text, prefix) => {
637
545
  const lines = text.split(/\r?\n/);
638
546
  const firstLine = lines.shift();
639
547
  let result = firstLine;
640
548
  let i = 0;
641
-
642
549
  while (i < lines.length) {
643
550
  const line = lines[i];
644
551
  i++;
645
552
  result += line.length ? `\n${prefix}${line}` : `\n`;
646
553
  }
647
-
648
554
  return result;
649
555
  };
650
-
651
556
  if (customElements && !customElements.get(JSENV_ERROR_OVERLAY_TAGNAME)) {
652
557
  customElements.define(JSENV_ERROR_OVERLAY_TAGNAME, JsenvErrorOverlay);
653
558
  }
654
-
655
559
  const overlayCSS = `
656
560
  :host {
657
561
  position: fixed;
@@ -728,9 +632,7 @@ window.__supervisor__ = (() => {
728
632
  color: inherit;
729
633
  }`;
730
634
  }
731
-
732
635
  supervisor.createException = createException;
733
-
734
636
  supervisor.reportException = exception => {
735
637
  const {
736
638
  theme,
@@ -739,7 +641,6 @@ window.__supervisor__ = (() => {
739
641
  tip,
740
642
  errorDetailsPromise
741
643
  } = formatError(exception);
742
-
743
644
  if (errorOverlay) {
744
645
  const removeErrorOverlay = displayJsenvErrorOverlay({
745
646
  theme,
@@ -748,7 +649,6 @@ window.__supervisor__ = (() => {
748
649
  tip,
749
650
  errorDetailsPromise
750
651
  });
751
-
752
652
  if (window.__reloader__) {
753
653
  window.__reloader__.onstatuschange = () => {
754
654
  if (window.__reloader__.status === "reloading") {
@@ -757,23 +657,19 @@ window.__supervisor__ = (() => {
757
657
  };
758
658
  }
759
659
  }
760
-
761
660
  if (errorNotification) {
762
661
  displayErrorNotification({
763
662
  title,
764
663
  text
765
664
  });
766
665
  }
767
-
768
666
  return exception;
769
667
  };
770
-
771
668
  window.addEventListener("error", errorEvent => {
772
669
  if (!errorEvent.isTrusted) {
773
670
  // ignore custom error event (not sent by browser)
774
671
  return;
775
672
  }
776
-
777
673
  const {
778
674
  error,
779
675
  message,
@@ -796,7 +692,6 @@ window.__supervisor__ = (() => {
796
692
  if (event.defaultPrevented) {
797
693
  return;
798
694
  }
799
-
800
695
  const exception = supervisor.createException({
801
696
  reason: event.reason,
802
697
  reportedBy: "window_unhandledrejection_event"
@@ -804,7 +699,6 @@ window.__supervisor__ = (() => {
804
699
  supervisor.reportException(exception);
805
700
  });
806
701
  };
807
-
808
702
  supervisor.setup = ({
809
703
  rootDirectoryUrl,
810
704
  logs,
@@ -819,40 +713,34 @@ window.__supervisor__ = (() => {
819
713
  openInEditor
820
714
  });
821
715
  const supervisedScripts = [];
822
- const pendingPromises = []; // respect execution order
716
+ const pendingPromises = [];
717
+ // respect execution order
823
718
  // - wait for classic scripts to be done (non async)
824
719
  // - wait module script previous execution (non async)
825
720
  // see https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8afd7a6#typemodule-vs-non-module-typetextjavascript-vs-script-nomodule
826
-
827
721
  const executionQueue = [];
828
722
  let executing = false;
829
-
830
723
  const addToExecutionQueue = async execution => {
831
724
  if (execution.async) {
832
725
  execution.start();
833
726
  return;
834
727
  }
835
-
836
728
  if (executing) {
837
729
  executionQueue.push(execution);
838
730
  return;
839
731
  }
840
-
841
732
  startThenDequeue(execution);
842
733
  };
843
-
844
734
  const startThenDequeue = async execution => {
845
735
  executing = true;
846
736
  const promise = execution.start();
847
737
  await promise;
848
738
  executing = false;
849
-
850
739
  if (executionQueue.length) {
851
740
  const nextExecution = executionQueue.shift();
852
741
  startThenDequeue(nextExecution);
853
742
  }
854
743
  };
855
-
856
744
  supervisor.addExecution = ({
857
745
  type,
858
746
  src,
@@ -865,30 +753,25 @@ window.__supervisor__ = (() => {
865
753
  async,
866
754
  execute
867
755
  };
868
-
869
756
  execution.start = () => {
870
757
  return superviseExecution(execution, {
871
758
  isReload: false
872
759
  });
873
760
  };
874
-
875
761
  execution.reload = () => {
876
762
  return superviseExecution(execution, {
877
763
  isReload: true
878
764
  });
879
765
  };
880
-
881
766
  supervisedScripts.push(execution);
882
767
  return addToExecutionQueue(execution);
883
768
  };
884
-
885
769
  const superviseExecution = async (execution, {
886
770
  isReload
887
771
  }) => {
888
772
  if (logs) {
889
773
  console.group(`[jsenv] loading ${execution.type} ${execution.src}`);
890
774
  }
891
-
892
775
  const executionResult = {
893
776
  status: "pending",
894
777
  loadDuration: null,
@@ -899,7 +782,6 @@ window.__supervisor__ = (() => {
899
782
  coverage: null
900
783
  };
901
784
  executionResults[execution.src] = executionResult;
902
-
903
785
  const monitorScriptLoad = () => {
904
786
  const loadStartTime = Date.now();
905
787
  let resolveScriptLoadPromise;
@@ -913,7 +795,6 @@ window.__supervisor__ = (() => {
913
795
  resolveScriptLoadPromise();
914
796
  };
915
797
  };
916
-
917
798
  const monitorScriptExecution = () => {
918
799
  const executionStartTime = Date.now();
919
800
  let resolveExecutionPromise;
@@ -928,36 +809,28 @@ window.__supervisor__ = (() => {
928
809
  resolveExecutionPromise();
929
810
  };
930
811
  };
931
-
932
812
  const onError = e => {
933
813
  executionResult.status = "errored";
934
814
  const exception = supervisor.createException({
935
815
  reason: e
936
816
  });
937
-
938
817
  if (exception.needsReport) {
939
818
  supervisor.reportException(exception);
940
819
  }
941
-
942
820
  executionResult.exception = exception;
943
821
  };
944
-
945
822
  const scriptLoadDone = monitorScriptLoad();
946
-
947
823
  try {
948
824
  const result = await execution.execute({
949
825
  isReload
950
826
  });
951
-
952
827
  if (logs) {
953
828
  console.log(`${execution.type} load ended`);
954
829
  console.groupEnd();
955
830
  }
956
-
957
831
  executionResult.status = "loaded";
958
832
  scriptLoadDone();
959
833
  const scriptExecutionDone = monitorScriptExecution();
960
-
961
834
  if (execution.type === "js_classic") {
962
835
  executionResult.status = "completed";
963
836
  scriptExecutionDone();
@@ -975,12 +848,10 @@ window.__supervisor__ = (() => {
975
848
  if (logs) {
976
849
  console.groupEnd();
977
850
  }
978
-
979
851
  onError(e);
980
852
  scriptLoadDone();
981
853
  }
982
854
  };
983
-
984
855
  supervisor.superviseScript = async ({
985
856
  src,
986
857
  async
@@ -1002,14 +873,13 @@ window.__supervisor__ = (() => {
1002
873
  const loadPromise = new Promise((resolve, reject) => {
1003
874
  // do not use script.cloneNode()
1004
875
  // bcause https://stackoverflow.com/questions/28771542/why-dont-clonenode-script-tags-execute
1005
- currentScriptClone = document.createElement("script"); // browsers set async by default when creating script(s)
876
+ currentScriptClone = document.createElement("script");
877
+ // browsers set async by default when creating script(s)
1006
878
  // we want an exact copy to preserves how code is executed
1007
-
1008
879
  currentScriptClone.async = false;
1009
880
  Array.from(currentScript.attributes).forEach(attribute => {
1010
881
  currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
1011
882
  });
1012
-
1013
883
  if (isReload) {
1014
884
  urlObject.searchParams.set("hmr", Date.now());
1015
885
  nodeToReplace = currentScriptClone;
@@ -1023,12 +893,10 @@ window.__supervisor__ = (() => {
1023
893
  nodeToReplace = currentScript;
1024
894
  currentScriptClone.src = src;
1025
895
  }
1026
-
1027
896
  currentScriptClone.addEventListener("error", reject);
1028
897
  currentScriptClone.addEventListener("load", resolve);
1029
898
  parentNode.replaceChild(currentScriptClone, nodeToReplace);
1030
899
  });
1031
-
1032
900
  try {
1033
901
  await loadPromise;
1034
902
  } catch (e) {
@@ -1044,7 +912,6 @@ window.__supervisor__ = (() => {
1044
912
  }
1045
913
  });
1046
914
  };
1047
-
1048
915
  supervisor.reloadSupervisedScript = ({
1049
916
  type,
1050
917
  src
@@ -1053,15 +920,12 @@ window.__supervisor__ = (() => {
1053
920
  if (type && supervisedScriptCandidate.type !== type) {
1054
921
  return false;
1055
922
  }
1056
-
1057
923
  return supervisedScriptCandidate.src === src;
1058
924
  });
1059
-
1060
925
  if (supervisedScript) {
1061
926
  supervisedScript.reload();
1062
927
  }
1063
928
  };
1064
-
1065
929
  supervisor.getDocumentExecutionResult = async () => {
1066
930
  // just to be super safe and ensure any <script type="module"> got a chance to execute
1067
931
  const documentReadyPromise = new Promise(resolve => {
@@ -1069,29 +933,24 @@ window.__supervisor__ = (() => {
1069
933
  resolve();
1070
934
  return;
1071
935
  }
1072
-
1073
936
  const loadCallback = () => {
1074
937
  window.removeEventListener("load", loadCallback);
1075
938
  resolve();
1076
939
  };
1077
-
1078
940
  window.addEventListener("load", loadCallback);
1079
941
  });
1080
942
  await documentReadyPromise;
1081
-
1082
943
  const waitScriptExecutions = async () => {
1083
944
  const numberOfPromises = pendingPromises.length;
1084
- await Promise.all(pendingPromises); // new scripts added while the other where executing
945
+ await Promise.all(pendingPromises);
946
+ // new scripts added while the other where executing
1085
947
  // (should happen only on webkit where
1086
948
  // script might be added after window load event)
1087
-
1088
949
  await new Promise(resolve => setTimeout(resolve));
1089
-
1090
950
  if (pendingPromises.length > numberOfPromises) {
1091
951
  await waitScriptExecutions();
1092
952
  }
1093
953
  };
1094
-
1095
954
  await waitScriptExecutions();
1096
955
  return {
1097
956
  status: "completed",
@@ -1101,6 +960,5 @@ window.__supervisor__ = (() => {
1101
960
  };
1102
961
  };
1103
962
  };
1104
-
1105
963
  return supervisor;
1106
964
  })();