@jsenv/core 27.0.0-alpha.64 → 27.0.0-alpha.65

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 (146) hide show
  1. package/dist/html/explorer.html +557 -0
  2. package/dist/js/controllable_file.mjs +227 -0
  3. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  4. package/dist/js/global_this.js +32 -0
  5. package/dist/js/html_supervisor_installer.js +522 -0
  6. package/dist/js/html_supervisor_setup.js +79 -0
  7. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  8. package/dist/js/inline_content.js +8 -0
  9. package/dist/js/new_stylesheet.js +409 -0
  10. package/dist/js/regenerator_runtime.js +721 -0
  11. package/dist/js/s.js +429 -0
  12. package/dist/main.js +13362 -0
  13. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  14. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  15. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  16. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  17. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  18. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  19. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  20. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  21. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  22. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  23. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  24. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  25. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  26. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  27. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  28. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  29. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  30. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  31. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  32. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  33. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  34. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  35. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  36. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  37. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  38. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  39. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  40. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  41. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  42. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  43. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/construct/construct.js +15 -0
  44. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createClass/createClass.js +18 -0
  45. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  46. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  47. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  48. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createSuper/createSuper.js +22 -0
  49. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/decorate/decorate.js +622 -0
  50. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defaults/defaults.js +14 -0
  51. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  52. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineProperty/defineProperty.js +19 -0
  53. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/extends/extends.js +16 -0
  54. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/get/get.js +21 -0
  55. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  56. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inherits/inherits.js +21 -0
  57. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  58. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  59. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  60. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/instanceof/instanceof.js +7 -0
  61. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  62. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  63. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  64. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  65. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  66. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  67. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  68. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/jsx/jsx.js +49 -0
  69. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  70. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  71. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  72. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  73. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  74. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread/objectSpread.js +22 -0
  75. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  76. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  77. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  78. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  79. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  80. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readme.md +8 -0
  81. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/set/set.js +51 -0
  82. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  83. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  84. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  85. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  86. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/superPropBase/superPropBase.js +10 -0
  87. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  88. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  89. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/tdz/tdz.js +4 -0
  90. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalRef/temporalRef.js +5 -0
  91. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  92. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toArray/toArray.js +5 -0
  93. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  94. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  95. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  96. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/typeof/typeof.js +7 -0
  97. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  98. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  99. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  100. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  101. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/package.json +15 -11
  104. package/src/build/build.js +152 -67
  105. package/src/build/build_urls_generator.js +18 -2
  106. package/src/build/inject_service_worker_urls.js +1 -1
  107. package/src/build/resync_ressource_hints.js +56 -9
  108. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  109. package/src/dev/start_dev_server.js +17 -3
  110. package/src/execute/execute.js +3 -0
  111. package/src/omega/errors.js +10 -7
  112. package/src/omega/kitchen.js +209 -216
  113. package/src/omega/url_graph/url_graph_report.js +2 -2
  114. package/src/omega/url_graph.js +1 -1
  115. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  116. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  117. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  118. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +171 -53
  119. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  120. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  121. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  122. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +12 -2
  123. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  124. package/src/plugins/plugin_controller.js +17 -3
  125. package/src/plugins/plugins.js +16 -19
  126. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -13
  127. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_script_type_module_as_classic.js → jsenv_plugin_as_js_classic_html.js} +0 -0
  128. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +1 -2
  129. package/src/plugins/url_analysis/html/html_urls.js +3 -0
  130. package/src/plugins/url_analysis/js/js_urls.js +2 -1
  131. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +87 -1
  132. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  133. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  134. package/src/test/execute_plan.js +2 -0
  135. package/dist/event_source_client.js.map +0 -188
  136. package/dist/html_supervisor_installer.js +0 -1236
  137. package/dist/html_supervisor_installer.js.map +0 -337
  138. package/dist/html_supervisor_setup.js +0 -95
  139. package/dist/html_supervisor_setup.js.map +0 -57
  140. package/dist/import_meta_hot.js.map +0 -42
  141. package/dist/s.js +0 -626
  142. package/dist/s.js.map +0 -207
  143. package/src/jsenv_root_directory_url.js +0 -1
  144. package/src/omega/compat/default_runtime_compat.js +0 -11
  145. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  146. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
@@ -1,1236 +0,0 @@
1
- // https://developer.mozilla.org/en-US/docs/Glossary/Primitive
2
- const isComposite = value => {
3
- if (value === null) {
4
- return false;
5
- }
6
-
7
- const type = typeof value;
8
-
9
- if (type === "object") {
10
- return true;
11
- }
12
-
13
- if (type === "function") {
14
- return true;
15
- }
16
-
17
- return false;
18
- };
19
-
20
- const compositeWellKnownMap = new WeakMap();
21
- const primitiveWellKnownMap = new Map();
22
- const getCompositeGlobalPath = value => compositeWellKnownMap.get(value);
23
- const getPrimitiveGlobalPath = value => primitiveWellKnownMap.get(value);
24
-
25
- const visitGlobalObject = value => {
26
- const visitValue = (value, path) => {
27
- if (isComposite(value)) {
28
- // prevent infinite recursion
29
- if (compositeWellKnownMap.has(value)) {
30
- return;
31
- }
32
-
33
- compositeWellKnownMap.set(value, path);
34
-
35
- const visitProperty = property => {
36
- let descriptor;
37
-
38
- try {
39
- descriptor = Object.getOwnPropertyDescriptor(value, property);
40
- } catch (e) {
41
- if (e.name === "SecurityError") {
42
- return;
43
- }
44
-
45
- throw e;
46
- }
47
-
48
- if (!descriptor) {
49
- // it's apparently possible to have getOwnPropertyNames returning
50
- // a property that later returns a null descriptor
51
- // for instance window.showModalDialog in webkit 13.0
52
- return;
53
- } // do not trigger getter/setter
54
-
55
-
56
- if ("value" in descriptor) {
57
- const propertyValue = descriptor.value;
58
- visitValue(propertyValue, [...path, property]);
59
- }
60
- };
61
-
62
- Object.getOwnPropertyNames(value).forEach(name => visitProperty(name));
63
- Object.getOwnPropertySymbols(value).forEach(symbol => visitProperty(symbol));
64
- }
65
-
66
- primitiveWellKnownMap.set(value, path);
67
- return;
68
- };
69
-
70
- visitValue(value, []);
71
- };
72
-
73
- if (typeof window === "object") visitGlobalObject(window);
74
- if (typeof global === "object") visitGlobalObject(global);
75
-
76
- /**
77
- * transforms a javascript value into an object describing it.
78
- *
79
- */
80
- const decompose = (mainValue, {
81
- functionAllowed,
82
- prototypeStrict,
83
- ignoreSymbols
84
- }) => {
85
- const valueMap = {};
86
- const recipeArray = [];
87
-
88
- const valueToIdentifier = (value, path = []) => {
89
- if (!isComposite(value)) {
90
- const existingIdentifier = identifierForPrimitive(value);
91
-
92
- if (existingIdentifier !== undefined) {
93
- return existingIdentifier;
94
- }
95
-
96
- const identifier = identifierForNewValue(value);
97
- recipeArray[identifier] = primitiveToRecipe(value);
98
- return identifier;
99
- }
100
-
101
- if (typeof Promise === "function" && value instanceof Promise) {
102
- throw new Error(createPromiseAreNotSupportedMessage({
103
- path
104
- }));
105
- }
106
-
107
- if (typeof WeakSet === "function" && value instanceof WeakSet) {
108
- throw new Error(createWeakSetAreNotSupportedMessage({
109
- path
110
- }));
111
- }
112
-
113
- if (typeof WeakMap === "function" && value instanceof WeakMap) {
114
- throw new Error(createWeakMapAreNotSupportedMessage({
115
- path
116
- }));
117
- }
118
-
119
- if (typeof value === "function" && !functionAllowed) {
120
- throw new Error(createForbiddenFunctionMessage({
121
- path
122
- }));
123
- }
124
-
125
- const existingIdentifier = identifierForComposite(value);
126
-
127
- if (existingIdentifier !== undefined) {
128
- return existingIdentifier;
129
- }
130
-
131
- const identifier = identifierForNewValue(value);
132
- const compositeGlobalPath = getCompositeGlobalPath(value);
133
-
134
- if (compositeGlobalPath) {
135
- recipeArray[identifier] = createGlobalReferenceRecipe(compositeGlobalPath);
136
- return identifier;
137
- }
138
-
139
- const propertyDescriptionArray = [];
140
- Object.getOwnPropertyNames(value).forEach(propertyName => {
141
- const propertyDescriptor = Object.getOwnPropertyDescriptor(value, propertyName);
142
- const propertyNameIdentifier = valueToIdentifier(propertyName, [...path, propertyName]);
143
- const propertyDescription = computePropertyDescription(propertyDescriptor, propertyName, path);
144
- propertyDescriptionArray.push({
145
- propertyNameIdentifier,
146
- propertyDescription
147
- });
148
- });
149
- const symbolDescriptionArray = [];
150
-
151
- if (!ignoreSymbols) {
152
- Object.getOwnPropertySymbols(value).forEach(symbol => {
153
- const propertyDescriptor = Object.getOwnPropertyDescriptor(value, symbol);
154
- const symbolIdentifier = valueToIdentifier(symbol, [...path, "[".concat(symbol.toString(), "]")]);
155
- const propertyDescription = computePropertyDescription(propertyDescriptor, symbol, path);
156
- symbolDescriptionArray.push({
157
- symbolIdentifier,
158
- propertyDescription
159
- });
160
- });
161
- }
162
-
163
- const methodDescriptionArray = computeMethodDescriptionArray(value, path);
164
- const extensible = Object.isExtensible(value);
165
- recipeArray[identifier] = createCompositeRecipe({
166
- propertyDescriptionArray,
167
- symbolDescriptionArray,
168
- methodDescriptionArray,
169
- extensible
170
- });
171
- return identifier;
172
- };
173
-
174
- const computePropertyDescription = (propertyDescriptor, propertyNameOrSymbol, path) => {
175
- if (propertyDescriptor.set && !functionAllowed) {
176
- throw new Error(createForbiddenPropertySetterMessage({
177
- path,
178
- propertyNameOrSymbol
179
- }));
180
- }
181
-
182
- if (propertyDescriptor.get && !functionAllowed) {
183
- throw new Error(createForbiddenPropertyGetterMessage({
184
- path,
185
- propertyNameOrSymbol
186
- }));
187
- }
188
-
189
- return {
190
- configurable: propertyDescriptor.configurable,
191
- writable: propertyDescriptor.writable,
192
- enumerable: propertyDescriptor.enumerable,
193
- getIdentifier: "get" in propertyDescriptor ? valueToIdentifier(propertyDescriptor.get, [...path, String(propertyNameOrSymbol), "[[descriptor:get]]"]) : undefined,
194
- setIdentifier: "set" in propertyDescriptor ? valueToIdentifier(propertyDescriptor.set, [...path, String(propertyNameOrSymbol), "[[descriptor:set]]"]) : undefined,
195
- valueIdentifier: "value" in propertyDescriptor ? valueToIdentifier(propertyDescriptor.value, [...path, String(propertyNameOrSymbol), "[[descriptor:value]]"]) : undefined
196
- };
197
- };
198
-
199
- const computeMethodDescriptionArray = (value, path) => {
200
- const methodDescriptionArray = [];
201
-
202
- if (typeof Set === "function" && value instanceof Set) {
203
- const callArray = [];
204
- value.forEach((entryValue, index) => {
205
- const entryValueIdentifier = valueToIdentifier(entryValue, [...path, "[[SetEntryValue]]", index]);
206
- callArray.push([entryValueIdentifier]);
207
- });
208
- methodDescriptionArray.push({
209
- methodNameIdentifier: valueToIdentifier("add"),
210
- callArray
211
- });
212
- }
213
-
214
- if (typeof Map === "function" && value instanceof Map) {
215
- const callArray = [];
216
- value.forEach((entryValue, entryKey) => {
217
- const entryKeyIdentifier = valueToIdentifier(entryKey, [...path, "[[MapEntryKey]]", entryKey]);
218
- const entryValueIdentifier = valueToIdentifier(entryValue, [...path, "[[MapEntryValue]]", entryValue]);
219
- callArray.push([entryKeyIdentifier, entryValueIdentifier]);
220
- });
221
- methodDescriptionArray.push({
222
- methodNameIdentifier: valueToIdentifier("set"),
223
- callArray
224
- });
225
- }
226
-
227
- return methodDescriptionArray;
228
- };
229
-
230
- const identifierForPrimitive = value => {
231
- return Object.keys(valueMap).find(existingIdentifier => {
232
- const existingValue = valueMap[existingIdentifier];
233
- if (Object.is(value, existingValue)) return true;
234
- return value === existingValue;
235
- });
236
- };
237
-
238
- const identifierForComposite = value => {
239
- return Object.keys(valueMap).find(existingIdentifier => {
240
- const existingValue = valueMap[existingIdentifier];
241
- return value === existingValue;
242
- });
243
- };
244
-
245
- const identifierForNewValue = value => {
246
- const identifier = nextIdentifier();
247
- valueMap[identifier] = value;
248
- return identifier;
249
- };
250
-
251
- let currentIdentifier = -1;
252
-
253
- const nextIdentifier = () => {
254
- const identifier = String(parseInt(currentIdentifier) + 1);
255
- currentIdentifier = identifier;
256
- return identifier;
257
- };
258
-
259
- const mainIdentifier = valueToIdentifier(mainValue); // prototype, important to keep after the whole structure was visited
260
- // so that we discover if any prototype is part of the value
261
-
262
- const prototypeValueToIdentifier = prototypeValue => {
263
- // prototype is null
264
- if (prototypeValue === null) {
265
- return valueToIdentifier(prototypeValue);
266
- } // prototype found somewhere already
267
-
268
-
269
- const prototypeExistingIdentifier = identifierForComposite(prototypeValue);
270
-
271
- if (prototypeExistingIdentifier !== undefined) {
272
- return prototypeExistingIdentifier;
273
- } // mark prototype as visited
274
-
275
-
276
- const prototypeIdentifier = identifierForNewValue(prototypeValue); // prototype is a global reference ?
277
-
278
- const prototypeGlobalPath = getCompositeGlobalPath(prototypeValue);
279
-
280
- if (prototypeGlobalPath) {
281
- recipeArray[prototypeIdentifier] = createGlobalReferenceRecipe(prototypeGlobalPath);
282
- return prototypeIdentifier;
283
- } // otherwise prototype is unknown
284
-
285
-
286
- if (prototypeStrict) {
287
- throw new Error(createUnknownPrototypeMessage({
288
- prototypeValue
289
- }));
290
- }
291
-
292
- return prototypeValueToIdentifier(Object.getPrototypeOf(prototypeValue));
293
- };
294
-
295
- const identifierForValueOf = (value, path = []) => {
296
- if (value instanceof Array) {
297
- return valueToIdentifier(value.length, [...path, "length"]);
298
- }
299
-
300
- if ("valueOf" in value === false) {
301
- return undefined;
302
- }
303
-
304
- if (typeof value.valueOf !== "function") {
305
- return undefined;
306
- }
307
-
308
- const valueOfReturnValue = value.valueOf();
309
-
310
- if (!isComposite(valueOfReturnValue)) {
311
- return valueToIdentifier(valueOfReturnValue, [...path, "valueOf()"]);
312
- }
313
-
314
- if (valueOfReturnValue === value) {
315
- return undefined;
316
- }
317
-
318
- throw new Error(createUnexpectedValueOfReturnValueMessage());
319
- };
320
-
321
- recipeArray.slice().forEach((recipe, index) => {
322
- if (recipe.type === "composite") {
323
- const value = valueMap[index];
324
-
325
- if (typeof value === "function") {
326
- const valueOfIdentifier = nextIdentifier();
327
- recipeArray[valueOfIdentifier] = {
328
- type: "primitive",
329
- value
330
- };
331
- recipe.valueOfIdentifier = valueOfIdentifier;
332
- return;
333
- }
334
-
335
- if (value instanceof RegExp) {
336
- const valueOfIdentifier = nextIdentifier();
337
- recipeArray[valueOfIdentifier] = {
338
- type: "primitive",
339
- value
340
- };
341
- recipe.valueOfIdentifier = valueOfIdentifier;
342
- return;
343
- } // valueOf, mandatory to uneval new Date(10) for instance.
344
-
345
-
346
- recipe.valueOfIdentifier = identifierForValueOf(value);
347
- const prototypeValue = Object.getPrototypeOf(value);
348
- recipe.prototypeIdentifier = prototypeValueToIdentifier(prototypeValue);
349
- }
350
- });
351
- return {
352
- recipeArray,
353
- mainIdentifier,
354
- valueMap
355
- };
356
- };
357
-
358
- const primitiveToRecipe = value => {
359
- if (typeof value === "symbol") {
360
- return symbolToRecipe(value);
361
- }
362
-
363
- return createPimitiveRecipe(value);
364
- };
365
-
366
- const symbolToRecipe = symbol => {
367
- const globalSymbolKey = Symbol.keyFor(symbol);
368
-
369
- if (globalSymbolKey !== undefined) {
370
- return createGlobalSymbolRecipe(globalSymbolKey);
371
- }
372
-
373
- const symbolGlobalPath = getPrimitiveGlobalPath(symbol);
374
-
375
- if (!symbolGlobalPath) {
376
- throw new Error(createUnknownSymbolMessage({
377
- symbol
378
- }));
379
- }
380
-
381
- return createGlobalReferenceRecipe(symbolGlobalPath);
382
- };
383
-
384
- const createPimitiveRecipe = value => {
385
- return {
386
- type: "primitive",
387
- value
388
- };
389
- };
390
-
391
- const createGlobalReferenceRecipe = path => {
392
- const recipe = {
393
- type: "global-reference",
394
- path
395
- };
396
- return recipe;
397
- };
398
-
399
- const createGlobalSymbolRecipe = key => {
400
- return {
401
- type: "global-symbol",
402
- key
403
- };
404
- };
405
-
406
- const createCompositeRecipe = ({
407
- prototypeIdentifier,
408
- valueOfIdentifier,
409
- propertyDescriptionArray,
410
- symbolDescriptionArray,
411
- methodDescriptionArray,
412
- extensible
413
- }) => {
414
- return {
415
- type: "composite",
416
- prototypeIdentifier,
417
- valueOfIdentifier,
418
- propertyDescriptionArray,
419
- symbolDescriptionArray,
420
- methodDescriptionArray,
421
- extensible
422
- };
423
- };
424
-
425
- const createPromiseAreNotSupportedMessage = ({
426
- path
427
- }) => {
428
- if (path.length === 0) {
429
- return "promise are not supported.";
430
- }
431
-
432
- return "promise are not supported.\npromise found at: ".concat(path.join(""));
433
- };
434
-
435
- const createWeakSetAreNotSupportedMessage = ({
436
- path
437
- }) => {
438
- if (path.length === 0) {
439
- return "weakSet are not supported.";
440
- }
441
-
442
- return "weakSet are not supported.\nweakSet found at: ".concat(path.join(""));
443
- };
444
-
445
- const createWeakMapAreNotSupportedMessage = ({
446
- path
447
- }) => {
448
- if (path.length === 0) {
449
- return "weakMap are not supported.";
450
- }
451
-
452
- return "weakMap are not supported.\nweakMap found at: ".concat(path.join(""));
453
- };
454
-
455
- const createForbiddenFunctionMessage = ({
456
- path
457
- }) => {
458
- if (path.length === 0) {
459
- return "function are not allowed.";
460
- }
461
-
462
- return "function are not allowed.\nfunction found at: ".concat(path.join(""));
463
- };
464
-
465
- const createForbiddenPropertyGetterMessage = ({
466
- path,
467
- propertyNameOrSymbol
468
- }) => "property getter are not allowed.\ngetter found on property: ".concat(String(propertyNameOrSymbol), "\nat: ").concat(path.join(""));
469
-
470
- const createForbiddenPropertySetterMessage = ({
471
- path,
472
- propertyNameOrSymbol
473
- }) => "property setter are not allowed.\nsetter found on property: ".concat(String(propertyNameOrSymbol), "\nat: ").concat(path.join(""));
474
-
475
- const createUnexpectedValueOfReturnValueMessage = () => "valueOf() must return a primitive of the object itself.";
476
-
477
- const createUnknownSymbolMessage = ({
478
- symbol
479
- }) => "symbol must be global, like Symbol.iterator, or created using Symbol.for().\nsymbol: ".concat(symbol.toString());
480
-
481
- const createUnknownPrototypeMessage = ({
482
- prototypeValue
483
- }) => "prototype must be global, like Object.prototype, or somewhere in the value.\nprototype constructor name: ".concat(prototypeValue.constructor.name);
484
-
485
- // be carefull because this function is mutating recipe objects inside the recipeArray.
486
- // this is not an issue because each recipe object is not accessible from the outside
487
- // when used internally by uneval
488
- const sortRecipe = recipeArray => {
489
- const findInRecipePrototypeChain = (recipe, callback) => {
490
- let currentRecipe = recipe; // eslint-disable-next-line no-constant-condition
491
-
492
- while (true) {
493
- if (currentRecipe.type !== "composite") {
494
- break;
495
- }
496
-
497
- const prototypeIdentifier = currentRecipe.prototypeIdentifier;
498
-
499
- if (prototypeIdentifier === undefined) {
500
- break;
501
- }
502
-
503
- currentRecipe = recipeArray[prototypeIdentifier];
504
-
505
- if (callback(currentRecipe, prototypeIdentifier)) {
506
- return prototypeIdentifier;
507
- }
508
- }
509
-
510
- return undefined;
511
- };
512
-
513
- const recipeArrayOrdered = recipeArray.slice();
514
- recipeArrayOrdered.sort((leftRecipe, rightRecipe) => {
515
- const leftType = leftRecipe.type;
516
- const rightType = rightRecipe.type;
517
-
518
- if (leftType === "composite" && rightType === "composite") {
519
- const rightRecipeIsInLeftRecipePrototypeChain = findInRecipePrototypeChain(leftRecipe, recipeCandidate => recipeCandidate === rightRecipe); // if left recipe requires right recipe, left must be after right
520
-
521
- if (rightRecipeIsInLeftRecipePrototypeChain) {
522
- return 1;
523
- }
524
-
525
- const leftRecipeIsInRightRecipePrototypeChain = findInRecipePrototypeChain(rightRecipe, recipeCandidate => recipeCandidate === leftRecipe); // if right recipe requires left recipe, right must be after left
526
-
527
- if (leftRecipeIsInRightRecipePrototypeChain) {
528
- return -1;
529
- }
530
- }
531
-
532
- if (leftType !== rightType) {
533
- // if left is a composite, left must be after right
534
- if (leftType === "composite") {
535
- return 1;
536
- } // if right is a composite, right must be after left
537
-
538
-
539
- if (rightType === "composite") {
540
- return -1;
541
- }
542
- }
543
-
544
- const leftIndex = recipeArray.indexOf(leftRecipe);
545
- const rightIndex = recipeArray.indexOf(rightRecipe); // left was before right, don't change that
546
-
547
- if (leftIndex < rightIndex) {
548
- return -1;
549
- } // right was after left, don't change that
550
-
551
-
552
- return 1;
553
- });
554
- return recipeArrayOrdered;
555
- };
556
-
557
- // https://github.com/joliss/js-string-escape/blob/master/index.js
558
- // http://javascript.crockford.com/remedial.html
559
- const escapeString = value => {
560
- const string = String(value);
561
- let i = 0;
562
- const j = string.length;
563
- var escapedString = "";
564
-
565
- while (i < j) {
566
- const char = string[i];
567
- let escapedChar;
568
-
569
- if (char === '"' || char === "'" || char === "\\") {
570
- escapedChar = "\\".concat(char);
571
- } else if (char === "\n") {
572
- escapedChar = "\\n";
573
- } else if (char === "\r") {
574
- escapedChar = "\\r";
575
- } else if (char === "\u2028") {
576
- escapedChar = "\\u2028";
577
- } else if (char === "\u2029") {
578
- escapedChar = "\\u2029";
579
- } else {
580
- escapedChar = char;
581
- }
582
-
583
- escapedString += escapedChar;
584
- i++;
585
- }
586
-
587
- return escapedString;
588
- };
589
-
590
- const uneval = (value, {
591
- functionAllowed = false,
592
- prototypeStrict = false,
593
- ignoreSymbols = false
594
- } = {}) => {
595
- const {
596
- recipeArray,
597
- mainIdentifier,
598
- valueMap
599
- } = decompose(value, {
600
- functionAllowed,
601
- prototypeStrict,
602
- ignoreSymbols
603
- });
604
- const recipeArraySorted = sortRecipe(recipeArray);
605
- let source = "(function () {\nvar globalObject\ntry {\n globalObject = Function('return this')() || (42, eval)('this');\n} catch(e) {\n globalObject = window;\n}\n\nfunction safeDefineProperty(object, propertyNameOrSymbol, descriptor) {\n var currentDescriptor = Object.getOwnPropertyDescriptor(object, propertyNameOrSymbol);\n if (currentDescriptor && !currentDescriptor.configurable) return\n Object.defineProperty(object, propertyNameOrSymbol, descriptor)\n};\n";
606
- const variableNameMap = {};
607
- recipeArray.forEach((recipe, index) => {
608
- const indexSorted = recipeArraySorted.indexOf(recipe);
609
- variableNameMap[index] = "_".concat(indexSorted);
610
- });
611
-
612
- const identifierToVariableName = identifier => variableNameMap[identifier];
613
-
614
- const recipeToSetupSource = recipe => {
615
- if (recipe.type === "primitive") return primitiveRecipeToSetupSource(recipe);
616
- if (recipe.type === "global-symbol") return globalSymbolRecipeToSetupSource(recipe);
617
- if (recipe.type === "global-reference") return globalReferenceRecipeToSetupSource(recipe);
618
- return compositeRecipeToSetupSource(recipe);
619
- };
620
-
621
- const primitiveRecipeToSetupSource = ({
622
- value
623
- }) => {
624
- const type = typeof value;
625
-
626
- if (type === "string") {
627
- return "\"".concat(escapeString(value), "\";");
628
- }
629
-
630
- if (type === "bigint") {
631
- return "".concat(value.toString(), "n");
632
- }
633
-
634
- if (Object.is(value, -0)) {
635
- return "-0;";
636
- }
637
-
638
- return "".concat(String(value), ";");
639
- };
640
-
641
- const globalSymbolRecipeToSetupSource = recipe => {
642
- return "Symbol.for(\"".concat(escapeString(recipe.key), "\");");
643
- };
644
-
645
- const globalReferenceRecipeToSetupSource = recipe => {
646
- const pathSource = recipe.path.map(part => "[\"".concat(escapeString(part), "\"]")).join("");
647
- return "globalObject".concat(pathSource, ";");
648
- };
649
-
650
- const compositeRecipeToSetupSource = ({
651
- prototypeIdentifier,
652
- valueOfIdentifier
653
- }) => {
654
- if (prototypeIdentifier === undefined) {
655
- return identifierToVariableName(valueOfIdentifier);
656
- }
657
-
658
- const prototypeValue = valueMap[prototypeIdentifier];
659
-
660
- if (prototypeValue === null) {
661
- return "Object.create(null);";
662
- }
663
-
664
- const prototypeConstructor = prototypeValue.constructor;
665
-
666
- if (prototypeConstructor === Object) {
667
- return "Object.create(".concat(identifierToVariableName(prototypeIdentifier), ");");
668
- }
669
-
670
- if (valueOfIdentifier === undefined) {
671
- return "new ".concat(prototypeConstructor.name, "();");
672
- }
673
-
674
- if (prototypeConstructor.name === "BigInt") {
675
- return "Object(".concat(identifierToVariableName(valueOfIdentifier), ")");
676
- }
677
-
678
- return "new ".concat(prototypeConstructor.name, "(").concat(identifierToVariableName(valueOfIdentifier), ");");
679
- };
680
-
681
- recipeArraySorted.forEach(recipe => {
682
- const recipeVariableName = identifierToVariableName(recipeArray.indexOf(recipe));
683
- source += "var ".concat(recipeVariableName, " = ").concat(recipeToSetupSource(recipe), "\n");
684
- });
685
-
686
- const recipeToMutateSource = (recipe, recipeVariableName) => {
687
- if (recipe.type === "composite") {
688
- return compositeRecipeToMutateSource(recipe, recipeVariableName);
689
- }
690
-
691
- return "";
692
- };
693
-
694
- const compositeRecipeToMutateSource = ({
695
- propertyDescriptionArray,
696
- symbolDescriptionArray,
697
- methodDescriptionArray,
698
- extensible
699
- }, recipeVariableName) => {
700
- let mutateSource = "";
701
- propertyDescriptionArray.forEach(({
702
- propertyNameIdentifier,
703
- propertyDescription
704
- }) => {
705
- mutateSource += generateDefinePropertySource(recipeVariableName, propertyNameIdentifier, propertyDescription);
706
- });
707
- symbolDescriptionArray.forEach(({
708
- symbolIdentifier,
709
- propertyDescription
710
- }) => {
711
- mutateSource += generateDefinePropertySource(recipeVariableName, symbolIdentifier, propertyDescription);
712
- });
713
- methodDescriptionArray.forEach(({
714
- methodNameIdentifier,
715
- callArray
716
- }) => {
717
- mutateSource += generateMethodCallSource(recipeVariableName, methodNameIdentifier, callArray);
718
- });
719
-
720
- if (!extensible) {
721
- mutateSource += generatePreventExtensionSource(recipeVariableName);
722
- }
723
-
724
- return mutateSource;
725
- };
726
-
727
- const generateDefinePropertySource = (recipeVariableName, propertyNameOrSymbolIdentifier, propertyDescription) => {
728
- const propertyOrSymbolVariableName = identifierToVariableName(propertyNameOrSymbolIdentifier);
729
- const propertyDescriptorSource = generatePropertyDescriptorSource(propertyDescription);
730
- return "safeDefineProperty(".concat(recipeVariableName, ", ").concat(propertyOrSymbolVariableName, ", ").concat(propertyDescriptorSource, ");");
731
- };
732
-
733
- const generatePropertyDescriptorSource = ({
734
- configurable,
735
- writable,
736
- enumerable,
737
- getIdentifier,
738
- setIdentifier,
739
- valueIdentifier
740
- }) => {
741
- if (valueIdentifier === undefined) {
742
- return "{\n configurable: ".concat(configurable, ",\n enumerable: ").concat(enumerable, ",\n get: ").concat(getIdentifier === undefined ? undefined : identifierToVariableName(getIdentifier), ",\n set: ").concat(setIdentifier === undefined ? undefined : identifierToVariableName(setIdentifier), ",\n}");
743
- }
744
-
745
- return "{\n configurable: ".concat(configurable, ",\n writable: ").concat(writable, ",\n enumerable: ").concat(enumerable, ",\n value: ").concat(valueIdentifier === undefined ? undefined : identifierToVariableName(valueIdentifier), "\n}");
746
- };
747
-
748
- const generateMethodCallSource = (recipeVariableName, methodNameIdentifier, callArray) => {
749
- let methodCallSource = "";
750
- const methodVariableName = identifierToVariableName(methodNameIdentifier);
751
- callArray.forEach(argumentIdentifiers => {
752
- const argumentVariableNames = argumentIdentifiers.map(argumentIdentifier => identifierToVariableName(argumentIdentifier));
753
- methodCallSource += "".concat(recipeVariableName, "[").concat(methodVariableName, "](").concat(argumentVariableNames.join(","), ");");
754
- });
755
- return methodCallSource;
756
- };
757
-
758
- const generatePreventExtensionSource = recipeVariableName => {
759
- return "Object.preventExtensions(".concat(recipeVariableName, ");");
760
- };
761
-
762
- recipeArraySorted.forEach(recipe => {
763
- const recipeVariableName = identifierToVariableName(recipeArray.indexOf(recipe));
764
- source += "".concat(recipeToMutateSource(recipe, recipeVariableName));
765
- });
766
- source += "return ".concat(identifierToVariableName(mainIdentifier), "; })()");
767
- return source;
768
- };
769
-
770
- const unevalException = value => {
771
- if (value && value.hasOwnProperty("toString")) {
772
- delete value.toString;
773
- }
774
-
775
- return uneval(value, {
776
- ignoreSymbols: true
777
- });
778
- };
779
-
780
- const displayErrorInDocument = error => {
781
- const title = "An error occured";
782
- let theme = error && error.cause && error.cause.code === "PARSE_ERROR" ? "light" : "dark";
783
- let message = errorToHTML(error);
784
- const css = "\n .jsenv-console {\n background: rgba(0, 0, 0, 0.95);\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n z-index: 1000;\n box-sizing: border-box;\n padding: 1em;\n }\n\n .jsenv-console h1 {\n color: red;\n display: flex;\n align-items: center;\n }\n\n #button-close-jsenv-console {\n margin-left: 10px;\n }\n\n .jsenv-console pre {\n overflow: auto;\n max-width: 70em;\n /* avoid scrollbar to hide the text behind it */\n padding: 20px;\n }\n\n .jsenv-console pre[data-theme=\"dark\"] {\n background: #111;\n border: 1px solid #333;\n color: #eee;\n }\n\n .jsenv-console pre[data-theme=\"light\"] {\n background: #1E1E1E;\n border: 1px solid white;\n color: #EEEEEE;\n }\n\n .jsenv-console pre a {\n color: inherit;\n }\n ";
785
- const html = "\n <style type=\"text/css\">".concat(css, "></style>\n <div class=\"jsenv-console\">\n <h1>").concat(title, " <button id=\"button-close-jsenv-console\">X</button></h1>\n <pre data-theme=\"").concat(theme, "\">").concat(message, "</pre>\n </div>\n ");
786
- const removeJsenvConsole = appendHMTLInside(html, document.body);
787
-
788
- document.querySelector("#button-close-jsenv-console").onclick = () => {
789
- removeJsenvConsole();
790
- };
791
- };
792
-
793
- const escapeHtml = string => {
794
- return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
795
- };
796
-
797
- const errorToHTML = error => {
798
- let html;
799
-
800
- if (error && error instanceof Error) {
801
- if (error.cause && error.cause.code === "PARSE_ERROR") {
802
- html = error.messageHTML || escapeHtml(error.message);
803
- } // stackTrace formatted by V8
804
- else if (Error.captureStackTrace) {
805
- html = escapeHtml(error.stack);
806
- } else {
807
- // other stack trace such as firefox do not contain error.message
808
- html = escapeHtml("".concat(error.message, "\n ").concat(error.stack));
809
- }
810
- } else if (typeof error === "string") {
811
- html = error;
812
- } else if (error === undefined) {
813
- html = "undefined";
814
- } else {
815
- html = JSON.stringify(error);
816
- }
817
-
818
- const htmlWithCorrectLineBreaks = html.replace(/\n/g, "\n");
819
- const htmlWithLinks = stringToStringWithLink(htmlWithCorrectLineBreaks, {
820
- transform: url => {
821
- return {
822
- href: url,
823
- text: url
824
- };
825
- }
826
- });
827
- return htmlWithLinks;
828
- }; // `Error: yo
829
- // at Object.execute (http://127.0.0.1:57300/build/src/__test__/file-throw.js:9:13)
830
- // at doExec (http://127.0.0.1:3000/src/__test__/file-throw.js:452:38)
831
- // at postOrderExec (http://127.0.0.1:3000/src/__test__/file-throw.js:448:16)
832
- // at http://127.0.0.1:3000/src/__test__/file-throw.js:399:18`.replace(/(?:https?|ftp|file):\/\/(.*+)$/gm, (...args) => {
833
- // debugger
834
- // })
835
-
836
-
837
- const stringToStringWithLink = (source, {
838
- transform = url => {
839
- return {
840
- href: url,
841
- text: url
842
- };
843
- }
844
- } = {}) => {
845
- return source.replace(/(?:https?|ftp|file):\/\/\S+/gm, match => {
846
- let linkHTML = "";
847
- const lastChar = match[match.length - 1]; // hotfix because our url regex sucks a bit
848
-
849
- const endsWithSeparationChar = lastChar === ")" || lastChar === ":";
850
-
851
- if (endsWithSeparationChar) {
852
- match = match.slice(0, -1);
853
- }
854
-
855
- const lineAndColumnPattern = /:([0-9]+):([0-9]+)$/;
856
- const lineAndColumMatch = match.match(lineAndColumnPattern);
857
-
858
- if (lineAndColumMatch) {
859
- const lineAndColumnString = lineAndColumMatch[0];
860
- const lineNumber = lineAndColumMatch[1];
861
- const columnNumber = lineAndColumMatch[2];
862
- const url = match.slice(0, -lineAndColumnString.length);
863
- const {
864
- href,
865
- text
866
- } = transform(url);
867
- linkHTML = link({
868
- href,
869
- text: "".concat(text, ":").concat(lineNumber, ":").concat(columnNumber)
870
- });
871
- } else {
872
- const linePattern = /:([0-9]+)$/;
873
- const lineMatch = match.match(linePattern);
874
-
875
- if (lineMatch) {
876
- const lineString = lineMatch[0];
877
- const lineNumber = lineMatch[1];
878
- const url = match.slice(0, -lineString.length);
879
- const {
880
- href,
881
- text
882
- } = transform(url);
883
- linkHTML = link({
884
- href,
885
- text: "".concat(text, ":").concat(lineNumber)
886
- });
887
- } else {
888
- const url = match;
889
- const {
890
- href,
891
- text
892
- } = transform(url);
893
- linkHTML = link({
894
- href,
895
- text
896
- });
897
- }
898
- }
899
-
900
- if (endsWithSeparationChar) {
901
- return "".concat(linkHTML).concat(lastChar);
902
- }
903
-
904
- return linkHTML;
905
- });
906
- };
907
-
908
- const link = ({
909
- href,
910
- text = href
911
- }) => "<a href=\"".concat(href, "\">").concat(text, "</a>");
912
-
913
- const appendHMTLInside = (html, parentNode) => {
914
- const temoraryParent = document.createElement("div");
915
- temoraryParent.innerHTML = html;
916
- return transferChildren(temoraryParent, parentNode);
917
- };
918
-
919
- const transferChildren = (fromNode, toNode) => {
920
- const childNodes = [].slice.call(fromNode.childNodes, 0);
921
- let i = 0;
922
-
923
- while (i < childNodes.length) {
924
- toNode.appendChild(childNodes[i]);
925
- i++;
926
- }
927
-
928
- return () => {
929
- let c = 0;
930
-
931
- while (c < childNodes.length) {
932
- fromNode.appendChild(childNodes[c]);
933
- c++;
934
- }
935
- };
936
- };
937
-
938
- const {
939
- Notification
940
- } = window;
941
-
942
- const displayErrorNotificationNotAvailable = () => {};
943
-
944
- const displayErrorNotificationImplementation = (error, {
945
- icon
946
- } = {}) => {
947
- if (Notification.permission === "granted") {
948
- const notification = new Notification("An error occured", {
949
- lang: "en",
950
- body: error ? error.stack : "undefined",
951
- icon
952
- });
953
-
954
- notification.onclick = () => {
955
- window.focus();
956
- };
957
- }
958
- };
959
-
960
- const displayErrorNotification = typeof Notification === "function" ? displayErrorNotificationImplementation : displayErrorNotificationNotAvailable;
961
-
962
- const {
963
- __html_supervisor__
964
- } = window;
965
- const installHtmlSupervisor = ({
966
- logs,
967
- measurePerf
968
- }) => {
969
-
970
- const scriptExecutionResults = {};
971
- let collectCalled = false;
972
- let pendingExecutionCount = 0;
973
- let resolveScriptExecutionsPromise;
974
- const scriptExecutionsPromise = new Promise(resolve => {
975
- resolveScriptExecutionsPromise = resolve;
976
- });
977
-
978
- const onExecutionStart = name => {
979
- scriptExecutionResults[name] = null; // ensure execution order is reflected into the object
980
-
981
- pendingExecutionCount++;
982
-
983
- if (measurePerf) {
984
- performance.mark("execution_start");
985
- }
986
- };
987
-
988
- const onExecutionSettled = (name, executionResult) => {
989
- if (measurePerf) {
990
- performance.measure("execution", "execution_start");
991
- }
992
-
993
- scriptExecutionResults[name] = executionResult;
994
- pendingExecutionCount--;
995
-
996
- if (pendingExecutionCount === 0 && collectCalled) {
997
- resolveScriptExecutionsPromise();
998
- }
999
- };
1000
-
1001
- const onExecutionError = (executionResult, {
1002
- currentScript,
1003
- errorExposureInNotification = false,
1004
- errorExposureInDocument = true
1005
- }) => {
1006
- const error = executionResult.error;
1007
-
1008
- if (error && error.code === "NETWORK_FAILURE") {
1009
- if (currentScript) {
1010
- const errorEvent = new Event("error");
1011
- currentScript.dispatchEvent(errorEvent);
1012
- }
1013
- } else if (typeof error === "object") {
1014
- const globalErrorEvent = new Event("error");
1015
- globalErrorEvent.filename = error.filename;
1016
- globalErrorEvent.lineno = error.line || error.lineno;
1017
- globalErrorEvent.colno = error.column || error.columnno;
1018
- globalErrorEvent.message = error.message;
1019
- window.dispatchEvent(globalErrorEvent);
1020
- }
1021
-
1022
- if (errorExposureInNotification) {
1023
- displayErrorNotification(error);
1024
- }
1025
-
1026
- if (errorExposureInDocument) {
1027
- displayErrorInDocument(error);
1028
- }
1029
-
1030
- executionResult.exceptionSource = unevalException(error);
1031
- delete executionResult.error;
1032
- };
1033
-
1034
- const getNavigationStartTime = () => {
1035
- try {
1036
- return window.performance.timing.navigationStart;
1037
- } catch (e) {
1038
- return Date.now();
1039
- }
1040
- };
1041
-
1042
- const performExecution = async ({
1043
- src,
1044
- type,
1045
- currentScript,
1046
- execute // https://developer.mozilla.org/en-US/docs/web/html/element/script
1047
-
1048
- }) => {
1049
- if (logs) {
1050
- console.group("[jsenv] loading ".concat(type, " ").concat(src));
1051
- }
1052
-
1053
- onExecutionStart(src);
1054
- let completed;
1055
- let result;
1056
- let error;
1057
-
1058
- try {
1059
- result = await execute();
1060
- completed = true;
1061
- } catch (e) {
1062
- completed = false;
1063
- error = e;
1064
- }
1065
-
1066
- if (completed) {
1067
- const executionResult = {
1068
- status: "completed",
1069
- namespace: result,
1070
- coverage: window.__coverage__
1071
- };
1072
- onExecutionSettled(src, executionResult);
1073
-
1074
- if (logs) {
1075
- console.log("".concat(type, " load ended"));
1076
- console.groupEnd();
1077
- }
1078
-
1079
- return;
1080
- }
1081
-
1082
- const executionResult = {
1083
- status: "errored",
1084
- coverage: window.__coverage__
1085
- };
1086
-
1087
- if (error.name === "SyntaxError") ;
1088
-
1089
- executionResult.error = error;
1090
- onExecutionSettled(src, executionResult);
1091
- onExecutionError(executionResult, {
1092
- currentScript
1093
- });
1094
-
1095
- {
1096
- if (typeof window.reportError === "function") {
1097
- window.reportError(error);
1098
- } else {
1099
- console.error(error);
1100
- }
1101
- }
1102
-
1103
- if (logs) {
1104
- console.groupEnd();
1105
- }
1106
- };
1107
-
1108
- const queue = [];
1109
- let previousDonePromise = null;
1110
-
1111
- const dequeue = () => {
1112
- const next = queue.shift();
1113
-
1114
- if (next) {
1115
- __html_supervisor__.addScriptToExecute(next);
1116
- } else {
1117
- const nextDefered = deferQueue.shift();
1118
-
1119
- if (nextDefered) {
1120
- __html_supervisor__.addScriptToExecute(nextDefered);
1121
- }
1122
- }
1123
- };
1124
-
1125
- const deferQueue = [];
1126
- let previousDeferDonePromise = null;
1127
-
1128
- __html_supervisor__.addScriptToExecute = async scriptToExecute => {
1129
- if (scriptToExecute.async) {
1130
- performExecution(scriptToExecute);
1131
- return;
1132
- }
1133
-
1134
- const useDeferQueue = scriptToExecute.defer || scriptToExecute.type === "js_module";
1135
-
1136
- if (useDeferQueue) {
1137
- if (document.readyState !== "interactive") {
1138
- deferQueue.push(scriptToExecute);
1139
- return;
1140
- }
1141
-
1142
- if (previousDonePromise) {
1143
- // defer must wait for the regular script to be done
1144
- deferQueue.push(scriptToExecute);
1145
- return;
1146
- }
1147
-
1148
- if (previousDeferDonePromise) {
1149
- deferQueue.push(scriptToExecute);
1150
- return;
1151
- }
1152
-
1153
- previousDeferDonePromise = performExecution(scriptToExecute);
1154
- await previousDeferDonePromise;
1155
- previousDeferDonePromise = null;
1156
- dequeue();
1157
- return;
1158
- }
1159
-
1160
- if (previousDonePromise) {
1161
- queue.push(scriptToExecute);
1162
- return;
1163
- }
1164
-
1165
- previousDonePromise = performExecution(scriptToExecute);
1166
- await previousDonePromise;
1167
- previousDonePromise = null;
1168
- dequeue();
1169
- };
1170
-
1171
- if (document.readyState !== "interactive" && document.readyState !== "complete") {
1172
- document.addEventListener("readystatechange", () => {
1173
- if (document.readyState === "interactive") {
1174
- const nextDefered = deferQueue.shift();
1175
-
1176
- if (nextDefered) {
1177
- __html_supervisor__.addScriptToExecute(nextDefered);
1178
- }
1179
- }
1180
- });
1181
- }
1182
-
1183
- __html_supervisor__.collectScriptResults = async () => {
1184
- collectCalled = true;
1185
-
1186
- if (pendingExecutionCount === 0) {
1187
- resolveScriptExecutionsPromise();
1188
- } else {
1189
- await scriptExecutionsPromise;
1190
- }
1191
-
1192
- let status = "completed";
1193
- let exceptionSource = "";
1194
- Object.keys(scriptExecutionResults).forEach(key => {
1195
- const scriptExecutionResult = scriptExecutionResults[key];
1196
-
1197
- if (scriptExecutionResult.status === "errored") {
1198
- status = "errored";
1199
- exceptionSource = scriptExecutionResult.exceptionSource;
1200
- }
1201
- });
1202
- return {
1203
- status,
1204
- ...(status === "errored" ? {
1205
- exceptionSource
1206
- } : {}),
1207
- startTime: getNavigationStartTime(),
1208
- endTime: Date.now(),
1209
- scriptExecutionResults
1210
- };
1211
- };
1212
-
1213
- const {
1214
- scriptsToExecute
1215
- } = __html_supervisor__;
1216
- const copy = scriptsToExecute.slice();
1217
- scriptsToExecute.length = 0;
1218
- copy.forEach(scriptToExecute => {
1219
- __html_supervisor__.addScriptToExecute(scriptToExecute);
1220
- });
1221
- };
1222
- const superviseScriptTypeModule = ({
1223
- src,
1224
- isInline
1225
- }) => {
1226
- __html_supervisor__.addScriptToExecute({
1227
- src,
1228
- type: "js_module",
1229
- isInline,
1230
- execute: () => import(new URL(src, document.location.href).href)
1231
- });
1232
- };
1233
-
1234
- export { installHtmlSupervisor, superviseScriptTypeModule };
1235
-
1236
- //# sourceMappingURL=html_supervisor_installer.js.map