lilact 0.29.3 → 0.30.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 (45) hide show
  1. package/dist/lilact.development.js +147 -66
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +28 -28
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +28 -28
  6. package/docs/assets/hierarchy.js +1 -1
  7. package/docs/assets/navigation.js +1 -1
  8. package/docs/assets/search.js +1 -1
  9. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  10. package/docs/classes/accessories.Suspense.html +7 -7
  11. package/docs/classes/components.Component.html +11 -11
  12. package/docs/classes/components.HTMLComponent.html +11 -11
  13. package/docs/classes/components.RootComponent.html +11 -11
  14. package/docs/functions/components.cloneComponent.html +1 -1
  15. package/docs/functions/components.createComponent.html +1 -1
  16. package/docs/functions/components.createPortal.html +1 -1
  17. package/docs/functions/components.createRoot.html +1 -1
  18. package/docs/functions/components.hotReloadRoot.html +1 -0
  19. package/docs/functions/components.memo.html +1 -1
  20. package/docs/functions/components.render.html +1 -1
  21. package/docs/functions/components.replaceAllComponentInstances.html +1 -0
  22. package/docs/functions/components.replaceComponentEntity.html +1 -0
  23. package/docs/functions/run.lazy.html +1 -1
  24. package/docs/functions/run.run.html +1 -1
  25. package/docs/functions/run.runScripts.html +1 -1
  26. package/docs/hierarchy.html +1 -1
  27. package/docs/modules/components.html +1 -1
  28. package/docs/static/index.html +1 -1
  29. package/docs/static/lilact.development.js +147 -66
  30. package/docs/static/lilact.development.js.map +3 -3
  31. package/docs/static/lilact.development.min.js +28 -28
  32. package/docs/static/lilact.development.min.js.map +3 -3
  33. package/docs/static/lilact.production.min.js +28 -28
  34. package/docs/variables/components.cloneElement.html +1 -1
  35. package/examples/index.html +1 -1
  36. package/examples/lilact.development.js +147 -66
  37. package/examples/lilact.development.js.map +3 -3
  38. package/examples/lilact.development.min.js +28 -28
  39. package/examples/lilact.development.min.js.map +3 -3
  40. package/examples/lilact.production.min.js +28 -28
  41. package/package.json +1 -1
  42. package/src/components.jsx +200 -82
  43. package/src/jsx.js +7 -32
  44. package/src/lilact.jsx +1 -1
  45. package/src/run.jsx +86 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.29.3",
3
+ "version": "0.30.1",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
6
  "homepage": "https://arashkazemi.github.io/lilact/",
@@ -39,47 +39,134 @@ const SVG_NS = "http://www.w3.org/2000/svg";
39
39
 
40
40
 
41
41
  function getComponentEntity(entity) {
42
- return entity?.[MEMOIZED]
43
- ? entity.component
44
- : entity;
42
+ return entity?.[MEMOIZED] ? entity.component : entity;
45
43
  }
46
44
 
47
- function replaceComponentEntity(comp, nextEntity) {
48
- const core = comp?.[CORE];
45
+ const componentInstances = new Map();
49
46
 
50
- if (!core || typeof nextEntity !== "function") {
51
- return;
52
- }
47
+ function registerComponentCore(core) {
48
+ const entity = getComponentEntity(core.entity);
53
49
 
54
- const oldEntity = getComponentEntity(core.entity);
55
- const newEntity = getComponentEntity(nextEntity);
50
+ if (typeof entity !== "function") return;
56
51
 
57
- if (oldEntity === newEntity) {
58
- return;
59
- }
52
+ let instances = componentInstances.get(entity);
60
53
 
61
- const oldIsClass = isClass(oldEntity);
62
- const newIsClass = isClass(newEntity);
54
+ if (!instances) {
55
+ instances = new Set();
56
+ componentInstances.set(entity, instances);
57
+ }
63
58
 
64
- // A function component and a class component have different instance
65
- // semantics. Let the cache create a fresh instance in that case.
66
- if (oldIsClass !== newIsClass) {
67
- return false;
68
- }
59
+ instances.add(core);
60
+ core.registered_entity = entity;
61
+ }
69
62
 
70
- if (newIsClass) {
71
- // Preserve the existing instance and state, but use the new class
72
- // prototype and therefore the new render/lifecycle methods.
73
- Object.setPrototypeOf(comp, newEntity.prototype);
74
- } else {
75
- // Preserve hooks and state, but replace the function implementation.
76
- comp.render = newEntity.bind(comp);
77
- }
63
+ function unregisterComponentCore(core) {
64
+ const entity = core.registered_entity;
65
+ if (!entity) return;
66
+
67
+ const instances = componentInstances.get(entity);
68
+
69
+ if (instances) {
70
+ instances.delete(core);
78
71
 
79
- core.entity = newEntity;
80
- return true;
72
+ if (instances.size === 0) {
73
+ componentInstances.delete(entity);
74
+ }
75
+ }
76
+
77
+ delete core.registered_entity;
81
78
  }
82
79
 
80
+ function moveComponentCore(core, oldEntity, newEntity) {
81
+ const oldInstances = componentInstances.get(oldEntity);
82
+
83
+ if (oldInstances) {
84
+ oldInstances.delete(core);
85
+
86
+ if (oldInstances.size === 0) {
87
+ componentInstances.delete(oldEntity);
88
+ }
89
+ }
90
+
91
+ let newInstances = componentInstances.get(newEntity);
92
+
93
+ if (!newInstances) {
94
+ newInstances = new Set();
95
+ componentInstances.set(newEntity, newInstances);
96
+ }
97
+
98
+ newInstances.add(core);
99
+ core.registered_entity = newEntity;
100
+ }
101
+
102
+ export function replaceComponentEntity(componentCore, nextEntity) {
103
+ if (!componentCore || typeof nextEntity !== "function") {
104
+ return false;
105
+ }
106
+
107
+ const oldEntity = getComponentEntity(componentCore.entity);
108
+ const newEntity = getComponentEntity(nextEntity);
109
+
110
+ if (oldEntity === newEntity) {
111
+ return true;
112
+ }
113
+
114
+ const component = componentCore.component;
115
+
116
+ if (!component) {
117
+ return false;
118
+ }
119
+
120
+ if (
121
+ typeof oldEntity !== "function" ||
122
+ typeof newEntity !== "function" ||
123
+ isClass(oldEntity) !== isClass(newEntity)
124
+ ) {
125
+ return false;
126
+ }
127
+
128
+ if (isClass(newEntity)) {
129
+ Object.setPrototypeOf(component, newEntity.prototype);
130
+ } else {
131
+ component.render = newEntity.bind(component);
132
+ }
133
+
134
+ componentCore.entity = newEntity;
135
+ moveComponentCore(componentCore, oldEntity, newEntity);
136
+
137
+ return true;
138
+ }
139
+
140
+ export function replaceAllComponentInstances(oldEntity, newEntity) {
141
+ oldEntity = getComponentEntity(oldEntity);
142
+ newEntity = getComponentEntity(newEntity);
143
+
144
+ if (
145
+ typeof oldEntity !== "function" ||
146
+ typeof newEntity !== "function"
147
+ ) {
148
+ return 0;
149
+ }
150
+
151
+ const instances = componentInstances.get(oldEntity);
152
+
153
+ if (!instances) {
154
+ return 0;
155
+ }
156
+
157
+ let count = 0;
158
+
159
+ for (const core of [...instances]) {
160
+ if (!replaceComponentEntity(core, newEntity)) {
161
+ continue;
162
+ }
163
+
164
+ core.apply(core.props, core.state);
165
+ count++;
166
+ }
167
+
168
+ return count;
169
+ }
83
170
 
84
171
  /*
85
172
  ComponentCache is for internal use. It is the heart of the JSX runtime,
@@ -99,48 +186,48 @@ class ComponentCache
99
186
  }
100
187
 
101
188
  pick(key, construct_func, nextEntity) {
102
- let comp;
189
+ let componentCore;
103
190
  let bucket = this.current_map.get(key);
104
- const reusable =
105
- bucket && bucket.length > bucket[IDX];
106
191
 
107
- if (reusable) {
108
- comp = bucket[bucket[IDX]];
192
+ if (bucket && bucket.length > bucket[IDX]) {
193
+ componentCore = bucket[bucket[IDX]];
109
194
  bucket[IDX]++;
110
195
 
111
- const oldEntity = getComponentEntity(comp?.[CORE]?.entity);
196
+ const oldEntity = getComponentEntity(componentCore.entity);
112
197
  const newEntity = getComponentEntity(nextEntity);
113
198
 
114
199
  const incompatible =
115
- typeof oldEntity === "function" &&
116
- typeof newEntity === "function" &&
117
- isClass(oldEntity) !== isClass(newEntity);
118
-
200
+ typeof oldEntity !== typeof newEntity ||
201
+ (
202
+ typeof oldEntity === "function" &&
203
+ isClass(oldEntity) !== isClass(newEntity)
204
+ );
205
+
119
206
  if (incompatible) {
120
- // Do not reuse a class instance as a function component or vice versa.
121
- comp = construct_func();
122
- } else {
123
- replaceComponentEntity(comp, nextEntity);
207
+ componentCore = construct_func();
208
+ }
209
+ else if (newEntity) {
210
+ replaceComponentEntity(componentCore, newEntity);
124
211
  }
125
212
  } else {
126
- comp = construct_func();
213
+ componentCore = construct_func();
127
214
  }
128
215
 
129
216
  bucket = this.new_map.get(key);
130
217
 
131
- if (bucket !== undefined) {
132
- bucket.push(comp);
218
+ if (bucket) {
219
+ bucket.push(componentCore);
133
220
  } else {
134
- bucket = [comp];
221
+ bucket = [componentCore];
135
222
  this.new_map.set(key, bucket);
136
223
  bucket[IDX] = 0;
137
224
  }
138
225
 
139
- if (comp[CORE]) {
140
- comp[CORE].parent ??= this.owner;
226
+ if (componentCore) {
227
+ componentCore.parent ??= this.owner;
141
228
  }
142
229
 
143
- return comp;
230
+ return componentCore;
144
231
  }
145
232
 
146
233
  commit()
@@ -393,7 +480,8 @@ class ComponentCore
393
480
 
394
481
  async cleanup()
395
482
  {
396
- try {
483
+ unregisterComponentCore(this);
484
+ try {
397
485
  const promises = [];
398
486
 
399
487
  if(this.props?.ref) {
@@ -794,8 +882,9 @@ function constructFunc(core, parent) // returns {text} or component, and not com
794
882
  }
795
883
 
796
884
  comp[CORE].entity = entity;
885
+ registerComponentCore(comp[CORE]);
797
886
 
798
- if(core.container) {
887
+ if (core.container) {
799
888
  comp[CORE].container = core.container;
800
889
  }
801
890
  }
@@ -807,36 +896,37 @@ function constructFunc(core, parent) // returns {text} or component, and not com
807
896
  return comp;
808
897
  }
809
898
 
810
-
811
899
  function prepareCore(parent, core) {
812
- try {
813
- parent.cache ??= new ComponentCache(parent);
814
-
815
- const isText = core[TEXT] !== undefined;
816
- const key = isText
817
- ? ':text:'
818
- : core.props?.key;
819
-
820
- const entity = isText || core instanceof ComponentCore
821
- ? undefined
822
- : core.entity;
823
-
824
- return parent.cache.pick(
825
- key,
826
- () => (
827
- isText || core instanceof ComponentCore
828
- ? core
829
- : constructFunc(core, parent)[CORE]
830
- ),
831
- entity
832
- );
833
- } catch (e) {
834
- if (core?.component?.componentDidCatch) {
835
- core.component.componentDidCatch(e);
836
- } else {
837
- throw e;
838
- }
839
- }
900
+ try {
901
+ parent.cache ??= new ComponentCache(parent);
902
+
903
+ const isText = core[TEXT] !== undefined;
904
+
905
+ const key = isText
906
+ ? ':text:'
907
+ : core.props?.key;
908
+
909
+ const entity =
910
+ isText || core instanceof ComponentCore
911
+ ? undefined
912
+ : core.entity;
913
+
914
+ return parent.cache.pick(
915
+ key,
916
+ () => (
917
+ isText || core instanceof ComponentCore
918
+ ? core
919
+ : constructFunc(core, parent)[CORE]
920
+ ),
921
+ entity
922
+ );
923
+ } catch (e) {
924
+ if (core?.component?.componentDidCatch) {
925
+ core.component.componentDidCatch(e);
926
+ } else {
927
+ throw e;
928
+ }
929
+ }
840
930
  }
841
931
 
842
932
 
@@ -1272,6 +1362,7 @@ export function createRoot(element)
1272
1362
  let root;
1273
1363
 
1274
1364
  return {
1365
+
1275
1366
  render(component) {
1276
1367
  if(!root) {
1277
1368
  root = new RootComponent( element, {children:[component]} );
@@ -1289,10 +1380,37 @@ export function createRoot(element)
1289
1380
  root.cleanup();
1290
1381
  element.innerHTML="";
1291
1382
  }
1383
+ },
1384
+
1385
+ getCore() {
1386
+ console.log(root, root[CORE]);
1387
+ return root[CORE];
1292
1388
  }
1293
1389
  }
1294
1390
  }
1295
1391
 
1392
+
1393
+
1394
+ export function hotReloadRoot(rootCore, nextEntity, props) {
1395
+ if (!rootCore || !rootCore.component) {
1396
+ throw new Error("Invalid root component.");
1397
+ }
1398
+
1399
+ const replaced = replaceComponentEntity(rootCore, nextEntity);
1400
+
1401
+ if (!replaced) {
1402
+ throw new Error(
1403
+ "Cannot hot-reload the root from a class component to a function component, or vice versa."
1404
+ );
1405
+ }
1406
+
1407
+ rootCore.apply(props === undefined ? rootCore.props : {...rootCore.props, ...props});
1408
+
1409
+ return rootCore;
1410
+ }
1411
+
1412
+
1413
+
1296
1414
  /**
1297
1415
  * Creates a portal — a way to render children into a DOM node
1298
1416
  * that exists outside the current component hierarchy.
package/src/jsx.js CHANGED
@@ -981,9 +981,6 @@ export function transpileJSX( jsx, {
981
981
  injectTraceLabels = false,
982
982
  discardComments = false,
983
983
  produceCJS = false,
984
- referentiateImports = false,
985
- importsObject = "Lilact.scriptImportsObject", // first letter must be capital so components work as expected
986
- importsObjectVar = "LilactImports", // first letter must be capital so components work as expected
987
984
  logErrors = false,
988
985
 
989
986
  // lilact internal
@@ -1086,41 +1083,26 @@ export function transpileJSX( jsx, {
1086
1083
 
1087
1084
  const codify = (outlen, node, is_attr=false, is_xml=false)=> {
1088
1085
 
1089
- flattened_nodes.push(node);
1090
1086
 
1091
- if(typeof(node)!=='object') {
1092
- if(referentiateImports && typeof(node)==='string') {
1093
- if(meta?.imported_names.has(node)) {
1094
- let j = flattened_nodes.length-2;
1095
- while( (typeof(flattened_nodes[j])==='string' && flattened_nodes[j].trim()==='') ||
1096
- (typeof(flattened_nodes[j])==='object' && flattened_nodes[j].type==='comment') ) j--;
1087
+ flattened_nodes.push(node);
1097
1088
 
1098
- if( typeof(flattened_nodes[j])!=='string' || flattened_nodes[j]!==".") {
1099
- return importsObjectVar+"."+node;
1100
- }
1101
- }
1102
- }
1103
- return node;
1104
- }
1105
- if(node===null) return '';
1089
+ if(typeof(node)!=='object') return node;
1090
+ if(!node) return '';
1106
1091
 
1107
1092
  node.out_index = outlen;
1108
1093
 
1109
- //console.log("CODIFY", node, node.out_index);
1110
-
1111
1094
  if(node.type==='string') return jsx.substring(node.begin, node.end);
1112
- if(node.type==='import') return referentiateImports?'':node.cjs;
1095
+ if(node.type==='import') return node.cjs;
1113
1096
  if(node.type==='export') return node.cjs;
1114
1097
  if(node.type==='regex') return jsx.substring(node.begin, node.end);
1115
1098
  if(node.type==='comment') return (discardComments || is_attr)?'':jsx.substring(node.begin, node.end);
1116
1099
  if(node.type==='directive') return node.value;
1117
1100
 
1118
-
1119
1101
  if(node.type==='parenthesis') {
1120
1102
  let out = "(";
1121
1103
 
1122
1104
  if(node.out) {
1123
- if(produceCJS || referentiateImports) processImportExports(node, jsx, meta);
1105
+ if(produceCJS) processImportExports(node, jsx, meta);
1124
1106
  for(const ch of node.out) {
1125
1107
  out+=codify(outlen+out.length-1, ch);
1126
1108
  }
@@ -1132,7 +1114,7 @@ export function transpileJSX( jsx, {
1132
1114
  let out = "";
1133
1115
 
1134
1116
  if(node.out) {
1135
- if(produceCJS || referentiateImports) processImportExports(node, jsx, meta);
1117
+ if(produceCJS) processImportExports(node, jsx, meta);
1136
1118
  for(const ch of node.out) {
1137
1119
  if(is_xml && ch.type==='comment') continue;
1138
1120
  out+=codify( outlen + out.length - (is_attr?1:0), ch);
@@ -1153,10 +1135,6 @@ export function transpileJSX( jsx, {
1153
1135
 
1154
1136
  if(node.type==='xml') {
1155
1137
 
1156
- if(referentiateImports && meta?.imported_names?.has(node.tag) && node.tag[0]===node.tag[0].toUpperCase()) {
1157
- node.tag=importsObjectVar+"."+node.tag;
1158
- }
1159
-
1160
1138
  if(node.tag.length===0) {
1161
1139
  node.tag = fragment;
1162
1140
  }
@@ -1207,9 +1185,6 @@ export function transpileJSX( jsx, {
1207
1185
  if(injectTraceLabels) {
1208
1186
  out=`/*LILACTBLOCK${++blocksInfo.counter}:0,0:<EXEC>*/try{`
1209
1187
  }
1210
- if(referentiateImports) {
1211
- out+=`const ${importsObjectVar} = ${importsObject};`;
1212
- }
1213
1188
  out+=codify(out.length, json);
1214
1189
 
1215
1190
  if(injectTraceLabels) {
@@ -1225,7 +1200,7 @@ export function transpileJSX( jsx, {
1225
1200
  if(appendSourcemap) {
1226
1201
  out += inline_sm;
1227
1202
  }
1228
- //console.log(out);
1203
+ // console.log(out);
1229
1204
 
1230
1205
  return out;
1231
1206
  }
package/src/lilact.jsx CHANGED
@@ -94,7 +94,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
94
94
  export const Lilact =
95
95
  {
96
96
 
97
- VERSION: "RC.5",
97
+ VERSION: "RC.6",
98
98
 
99
99
  // Configuration
100
100
 
package/src/run.jsx CHANGED
@@ -245,76 +245,102 @@ export function require(path)
245
245
 
246
246
 
247
247
  function makeImportsObject(mod, options = {}) {
248
- mod.importsObject = {};
248
+ mod.importsObject ??= {};
249
249
 
250
- for (const path in mod.meta.imports) {
251
- const imps = mod.meta.imports[path];
250
+ for (const key of Object.keys(mod.importsObject)) {
251
+ delete mod.importsObject[key];
252
+ }
252
253
 
253
- const exps = loadModule(path, {
254
- requirer: mod,
255
- forceReload: options.forceReload,
256
- });
254
+ for (const path in mod.meta.imports) {
255
+ const imps = mod.meta.imports[path];
257
256
 
258
- for (const i in imps.named_imports) {
259
- if (i === '') continue;
257
+ const exps = loadModule(path, {
258
+ requirer: mod,
259
+ forceReload: options.forceReload,
260
+ });
260
261
 
261
- const exportedName = imps.named_imports[i];
262
+ for (const i in imps.named_imports) {
263
+ if (i === "") continue;
262
264
 
263
- if (!Object.prototype.hasOwnProperty.call(exps, exportedName)) {
264
- throw new Error(
265
- `Imported module does not export any "${i}".`
266
- );
267
- }
265
+ const exportedName = imps.named_imports[i];
268
266
 
269
- mod.importsObject[i] = exps[exportedName];
270
- }
267
+ if (!Object.prototype.hasOwnProperty.call(exps, exportedName)) {
268
+ throw new Error(
269
+ `Imported module does not export any "${i}".`
270
+ );
271
+ }
271
272
 
272
- for (const i of imps.import_defaults) {
273
- if (!Object.prototype.hasOwnProperty.call(exps, 'default')) {
274
- throw new Error(
275
- `Imported module does not export a default.`
276
- );
277
- }
273
+ mod.importsObject[i] = exps[exportedName];
274
+ }
278
275
 
279
- mod.importsObject[i] = exps.default;
280
- }
276
+ for (const i of imps.import_defaults) {
277
+ if (!Object.prototype.hasOwnProperty.call(exps, "default")) {
278
+ throw new Error(
279
+ "Imported module does not export a default."
280
+ );
281
+ }
281
282
 
282
- for (const i of imps.import_stars) {
283
- mod.importsObject[i] = { ...exps };
284
- }
285
- }
283
+ mod.importsObject[i] = exps.default;
284
+ }
285
+
286
+ for (const i of imps.import_stars) {
287
+ mod.importsObject[i] = { ...exps };
288
+ }
289
+ }
290
+
291
+ return mod.importsObject;
292
+ }
293
+
294
+
295
+ function exportEntries(value) {
296
+ return value && typeof value === "object"
297
+ ? value
298
+ : { default: value };
299
+ }
300
+
301
+ function replaceReloadedExports(previousExports, nextExports) {
302
+ if (!previousExports) return;
303
+
304
+ const oldExports = exportEntries(previousExports);
305
+ const newExports = exportEntries(nextExports);
306
+
307
+ for (const name of Object.keys(oldExports)) {
308
+ const oldExport = oldExports[name];
309
+ const newExport = newExports[name];
310
+
311
+ if (
312
+ typeof oldExport === "function" &&
313
+ typeof newExport === "function"
314
+ ) {
315
+ Lilact.replaceAllComponentInstances(oldExport, newExport);
316
+ }
317
+ }
286
318
  }
287
319
 
288
320
 
289
321
  export function run(
290
- jsx,
291
- path = `InlineJSX-${++Lilact.eval_num}`,
292
- options = {}
322
+ jsx,
323
+ path = `InlineJSX-${++Lilact.eval_num}`,
324
+ options = {}
293
325
  ) {
294
326
  let module = required_scripts[path];
295
327
 
296
- /*
297
- * A module may already have been created by require() while its source is
298
- * being fetched. Reuse that module so the request and its exports remain
299
- * associated with the same entry.
300
- */
328
+ const previousExports =
329
+ module?.loaded
330
+ ? module.exports
331
+ : undefined;
332
+
301
333
  if (!module) {
302
334
  module = createModule(path, {
303
335
  code: jsx,
304
336
  });
305
337
  } else {
306
- /*
307
- * Preserve module.request. It may represent the request that led to this
308
- * run() call, and clearing it here would make retry/deduplication logic
309
- * fragile.
310
- */
311
338
  module.path = path;
312
339
  module.code = String(jsx);
313
340
  module.mappings = [];
314
341
  module.exports = {};
315
342
  module.loaded = false;
316
343
  module.error = undefined;
317
- module.importsObject = undefined;
318
344
  module.meta = {};
319
345
  }
320
346
 
@@ -328,18 +354,19 @@ export function run(
328
354
  factory: "createComponent",
329
355
  appendSourcemap: true,
330
356
  injectTraceLabels: true,
331
- produceCJS: false,
332
- referentiateImports: true,
357
+ produceCJS: true,
333
358
  blocksInfo: Lilact.blocksInfo,
334
359
  });
335
- }
336
- catch (value) {
360
+ } catch (value) {
337
361
  const error = asError(value);
362
+
338
363
  error.fileName ??= path;
339
- error.lilact_source ??= {path};
364
+ error.lilact_source ??= { path };
340
365
  error.sourcePhase = "transpile";
366
+
341
367
  module.error = error;
342
368
  Lilact.error = error;
369
+
343
370
  throw error;
344
371
  }
345
372
 
@@ -347,28 +374,28 @@ export function run(
347
374
  Lilact.scanBlockLabels(processed, path);
348
375
  }
349
376
 
350
- /*
351
- * sourceURL helps when the browser includes eval locations in its stack.
352
- * It is not used as the authoritative source; the catch block below is.
353
- */
354
-
355
377
  try {
356
378
  globalThis.Lilact = Lilact;
357
379
  globalThis.createComponent = Lilact.createComponent;
358
380
  globalThis.Fragment = Lilact.Fragment;
359
381
 
360
- makeImportsObject(module, options);
361
-
362
- Lilact.scriptImportsObject = module.importsObject;
363
382
  const result = eval(processed);
383
+
364
384
  module.loaded = true;
365
385
 
366
- return isEmpty(module.exports) ? result : module.exports;
367
- }
368
- catch (value) {
386
+ const nextExports = isEmpty(module.exports)
387
+ ? result
388
+ : module.exports;
389
+
390
+ replaceReloadedExports(previousExports, nextExports);
391
+
392
+ return nextExports;
393
+ } catch (value) {
369
394
  const error = report(value, path);
395
+
370
396
  error.sourcePhase ??= "runtime";
371
397
  module.error = error;
398
+
372
399
  throw error;
373
400
  }
374
401
  }