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.
- package/dist/lilact.development.js +147 -66
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +28 -28
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +28 -28
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- package/docs/functions/components.cloneComponent.html +1 -1
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.hotReloadRoot.html +1 -0
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/components.replaceAllComponentInstances.html +1 -0
- package/docs/functions/components.replaceComponentEntity.html +1 -0
- package/docs/functions/run.lazy.html +1 -1
- package/docs/functions/run.run.html +1 -1
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/modules/components.html +1 -1
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +147 -66
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +28 -28
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +28 -28
- package/docs/variables/components.cloneElement.html +1 -1
- package/examples/index.html +1 -1
- package/examples/lilact.development.js +147 -66
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +28 -28
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +28 -28
- package/package.json +1 -1
- package/src/components.jsx +200 -82
- package/src/jsx.js +7 -32
- package/src/lilact.jsx +1 -1
- package/src/run.jsx +86 -59
package/package.json
CHANGED
package/src/components.jsx
CHANGED
|
@@ -39,47 +39,134 @@ const SVG_NS = "http://www.w3.org/2000/svg";
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
function getComponentEntity(entity) {
|
|
42
|
-
|
|
43
|
-
? entity.component
|
|
44
|
-
: entity;
|
|
42
|
+
return entity?.[MEMOIZED] ? entity.component : entity;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
const core = comp?.[CORE];
|
|
45
|
+
const componentInstances = new Map();
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
47
|
+
function registerComponentCore(core) {
|
|
48
|
+
const entity = getComponentEntity(core.entity);
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
const newEntity = getComponentEntity(nextEntity);
|
|
50
|
+
if (typeof entity !== "function") return;
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
52
|
+
let instances = componentInstances.get(entity);
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
if (!instances) {
|
|
55
|
+
instances = new Set();
|
|
56
|
+
componentInstances.set(entity, instances);
|
|
57
|
+
}
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
59
|
+
instances.add(core);
|
|
60
|
+
core.registered_entity = entity;
|
|
61
|
+
}
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
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
|
|
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 (
|
|
108
|
-
|
|
192
|
+
if (bucket && bucket.length > bucket[IDX]) {
|
|
193
|
+
componentCore = bucket[bucket[IDX]];
|
|
109
194
|
bucket[IDX]++;
|
|
110
195
|
|
|
111
|
-
const oldEntity = getComponentEntity(
|
|
196
|
+
const oldEntity = getComponentEntity(componentCore.entity);
|
|
112
197
|
const newEntity = getComponentEntity(nextEntity);
|
|
113
198
|
|
|
114
199
|
const incompatible =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
200
|
+
typeof oldEntity !== typeof newEntity ||
|
|
201
|
+
(
|
|
202
|
+
typeof oldEntity === "function" &&
|
|
203
|
+
isClass(oldEntity) !== isClass(newEntity)
|
|
204
|
+
);
|
|
205
|
+
|
|
119
206
|
if (incompatible) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
replaceComponentEntity(
|
|
207
|
+
componentCore = construct_func();
|
|
208
|
+
}
|
|
209
|
+
else if (newEntity) {
|
|
210
|
+
replaceComponentEntity(componentCore, newEntity);
|
|
124
211
|
}
|
|
125
212
|
} else {
|
|
126
|
-
|
|
213
|
+
componentCore = construct_func();
|
|
127
214
|
}
|
|
128
215
|
|
|
129
216
|
bucket = this.new_map.get(key);
|
|
130
217
|
|
|
131
|
-
if (bucket
|
|
132
|
-
bucket.push(
|
|
218
|
+
if (bucket) {
|
|
219
|
+
bucket.push(componentCore);
|
|
133
220
|
} else {
|
|
134
|
-
bucket = [
|
|
221
|
+
bucket = [componentCore];
|
|
135
222
|
this.new_map.set(key, bucket);
|
|
136
223
|
bucket[IDX] = 0;
|
|
137
224
|
}
|
|
138
225
|
|
|
139
|
-
if (
|
|
140
|
-
|
|
226
|
+
if (componentCore) {
|
|
227
|
+
componentCore.parent ??= this.owner;
|
|
141
228
|
}
|
|
142
229
|
|
|
143
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1099
|
-
|
|
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
|
|
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
|
|
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
|
|
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
package/src/run.jsx
CHANGED
|
@@ -245,76 +245,102 @@ export function require(path)
|
|
|
245
245
|
|
|
246
246
|
|
|
247
247
|
function makeImportsObject(mod, options = {}) {
|
|
248
|
-
|
|
248
|
+
mod.importsObject ??= {};
|
|
249
249
|
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
for (const key of Object.keys(mod.importsObject)) {
|
|
251
|
+
delete mod.importsObject[key];
|
|
252
|
+
}
|
|
252
253
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
forceReload: options.forceReload,
|
|
256
|
-
});
|
|
254
|
+
for (const path in mod.meta.imports) {
|
|
255
|
+
const imps = mod.meta.imports[path];
|
|
257
256
|
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
const exps = loadModule(path, {
|
|
258
|
+
requirer: mod,
|
|
259
|
+
forceReload: options.forceReload,
|
|
260
|
+
});
|
|
260
261
|
|
|
261
|
-
|
|
262
|
+
for (const i in imps.named_imports) {
|
|
263
|
+
if (i === "") continue;
|
|
262
264
|
|
|
263
|
-
|
|
264
|
-
throw new Error(
|
|
265
|
-
`Imported module does not export any "${i}".`
|
|
266
|
-
);
|
|
267
|
-
}
|
|
265
|
+
const exportedName = imps.named_imports[i];
|
|
268
266
|
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
throw new Error(
|
|
275
|
-
`Imported module does not export a default.`
|
|
276
|
-
);
|
|
277
|
-
}
|
|
273
|
+
mod.importsObject[i] = exps[exportedName];
|
|
274
|
+
}
|
|
278
275
|
|
|
279
|
-
|
|
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
|
-
|
|
283
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
322
|
+
jsx,
|
|
323
|
+
path = `InlineJSX-${++Lilact.eval_num}`,
|
|
324
|
+
options = {}
|
|
293
325
|
) {
|
|
294
326
|
let module = required_scripts[path];
|
|
295
327
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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:
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
}
|