malinajs 0.7.0-a12 → 0.7.0-a13
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/CHANGELOG.md +2 -0
- package/malina.js +38 -16
- package/package.json +3 -3
- package/runtime.js +34 -17
package/CHANGELOG.md
CHANGED
package/malina.js
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
function detectExpressionType(name) {
|
|
73
73
|
if(isSimpleName(name)) return 'identifier';
|
|
74
74
|
|
|
75
|
-
let ast = acorn.parse(name, { allowReturnOutsideFunction: true });
|
|
75
|
+
let ast = acorn.parse(name, { allowReturnOutsideFunction: true, ecmaVersion: 'latest' });
|
|
76
76
|
|
|
77
77
|
function checkIdentificator(body) {
|
|
78
78
|
if(body.length != 1) return;
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
const extractKeywords = (exp) => {
|
|
142
|
-
let ast = acorn.parse(exp, { sourceType: 'module', ecmaVersion: 12 });
|
|
142
|
+
let ast = acorn.parse(exp, { sourceType: 'module', ecmaVersion: 12, ecmaVersion: 'latest' });
|
|
143
143
|
|
|
144
144
|
const keys = new Set();
|
|
145
145
|
const rec = (n) => {
|
|
@@ -180,9 +180,9 @@
|
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
|
|
183
|
-
const replaceKeyword = (exp, fn) => {
|
|
183
|
+
const replaceKeyword = (exp, fn, option) => {
|
|
184
184
|
let changed = false;
|
|
185
|
-
let r = parseJS(exp).transform((n, pk) => {
|
|
185
|
+
let r = parseJS(exp, option).transform((n, pk) => {
|
|
186
186
|
if(n.type != 'Identifier') return;
|
|
187
187
|
if(pk == 'property' || pk == 'params') return;
|
|
188
188
|
let name = fn(n.name);
|
|
@@ -195,9 +195,10 @@
|
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
const parseJS = (exp) => {
|
|
198
|
+
const parseJS = (exp, option) => {
|
|
199
199
|
let self = {};
|
|
200
|
-
self.ast = acorn.
|
|
200
|
+
if(option === true) self.ast = acorn.parse(exp, { ecmaVersion: 'latest' });
|
|
201
|
+
else self.ast = acorn.parseExpressionAt(exp, 0, { ecmaVersion: 'latest' });
|
|
201
202
|
|
|
202
203
|
self.transform = function(fn) {
|
|
203
204
|
const rec = (n, pk) => {
|
|
@@ -932,6 +933,22 @@
|
|
|
932
933
|
const readScript = (tag) => {
|
|
933
934
|
let endTag = `</${tag}>`;
|
|
934
935
|
let q, a, p, start = index;
|
|
936
|
+
|
|
937
|
+
const readRegExp = () => {
|
|
938
|
+
while(true) {
|
|
939
|
+
p = a;
|
|
940
|
+
a = readNext();
|
|
941
|
+
if(q) {
|
|
942
|
+
if(a != q) continue;
|
|
943
|
+
if(p == '\\') continue;
|
|
944
|
+
q = null;
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if(a == '[' && p != '\\') q = ']';
|
|
948
|
+
if(a == '/' && p != '\\') return;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
935
952
|
while(true) {
|
|
936
953
|
p = a;
|
|
937
954
|
a = readNext();
|
|
@@ -945,6 +962,10 @@
|
|
|
945
962
|
q = a;
|
|
946
963
|
continue;
|
|
947
964
|
}
|
|
965
|
+
if(a == '/') {
|
|
966
|
+
readRegExp();
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
948
969
|
if(a == '<') {
|
|
949
970
|
if(source.substring(index - 1, index + endTag.length - 1) == endTag) {
|
|
950
971
|
let end = index - 1;
|
|
@@ -1040,7 +1061,7 @@
|
|
|
1040
1061
|
|
|
1041
1062
|
while(index < source.length) {
|
|
1042
1063
|
let a = source[index];
|
|
1043
|
-
if(a === '<' && source[index+1].match(/\S/)) {
|
|
1064
|
+
if(a === '<' && source[index + 1].match(/\S/)) {
|
|
1044
1065
|
flushText();
|
|
1045
1066
|
|
|
1046
1067
|
if(source.substring(index, index + 4) === '<!--') {
|
|
@@ -1155,7 +1176,7 @@
|
|
|
1155
1176
|
let tag = {
|
|
1156
1177
|
type: 'await',
|
|
1157
1178
|
value: bind.value,
|
|
1158
|
-
parts: {main: []}
|
|
1179
|
+
parts: { main: [] }
|
|
1159
1180
|
};
|
|
1160
1181
|
push(tag);
|
|
1161
1182
|
go(tag, n => tag.parts.main.push(n));
|
|
@@ -1315,7 +1336,7 @@
|
|
|
1315
1336
|
if(isBlockComment) return;
|
|
1316
1337
|
this.script.comments.push({ start, end, value });
|
|
1317
1338
|
};
|
|
1318
|
-
this.script.ast = acorn.parse(source, { sourceType: 'module', ecmaVersion:
|
|
1339
|
+
this.script.ast = acorn.parse(source, { sourceType: 'module', ecmaVersion: 'latest', onComment });
|
|
1319
1340
|
|
|
1320
1341
|
if(source.includes('$props')) this.require('$props');
|
|
1321
1342
|
if(source.includes('$attributes')) this.require('$attributes');
|
|
@@ -2026,7 +2047,7 @@
|
|
|
2026
2047
|
if(!exp.endsWith(';')) exp += ';';
|
|
2027
2048
|
binds.push(xNode('block', {
|
|
2028
2049
|
body: [
|
|
2029
|
-
replaceKeyword(exp, (name) => name == '$element' ? textNode.bindName() : null)
|
|
2050
|
+
replaceKeyword(exp, (name) => name == '$element' ? textNode.bindName() : null, true)
|
|
2030
2051
|
]
|
|
2031
2052
|
}));
|
|
2032
2053
|
});
|
|
@@ -2257,7 +2278,7 @@
|
|
|
2257
2278
|
|
|
2258
2279
|
if(node.children?.length) {
|
|
2259
2280
|
let i = node.children.length - 1;
|
|
2260
|
-
for(;i >= 0;i--) {
|
|
2281
|
+
for(;i >= 0; i--) {
|
|
2261
2282
|
let n = node.children[i];
|
|
2262
2283
|
|
|
2263
2284
|
if(mark(n)) {
|
|
@@ -2379,7 +2400,8 @@
|
|
|
2379
2400
|
}
|
|
2380
2401
|
} else {
|
|
2381
2402
|
if(n._boundName) {
|
|
2382
|
-
ctx.write(true, `let ${n._boundName} = ${base._boundName}`);
|
|
2403
|
+
if(base) ctx.write(true, `let ${n._boundName} = ${base._boundName}`);
|
|
2404
|
+
else ctx.write(true, `let ${n._boundName} = ${path.join('.')}.firstChild`);
|
|
2383
2405
|
while(shift--) ctx.write('.nextSibling');
|
|
2384
2406
|
ctx.write(';');
|
|
2385
2407
|
walk(n, [n._boundName]);
|
|
@@ -5118,7 +5140,7 @@
|
|
|
5118
5140
|
return {
|
|
5119
5141
|
bind: xNode('block', {
|
|
5120
5142
|
body: [
|
|
5121
|
-
replaceKeyword(exp, (name) => name == '$element' ? element.bindName() : null)
|
|
5143
|
+
replaceKeyword(exp, (name) => name == '$element' ? element.bindName() : null, true)
|
|
5122
5144
|
]
|
|
5123
5145
|
})
|
|
5124
5146
|
};
|
|
@@ -5601,7 +5623,7 @@
|
|
|
5601
5623
|
ctx.write(true, `}`);
|
|
5602
5624
|
}
|
|
5603
5625
|
ctx.write(`, [`);
|
|
5604
|
-
n.elseBlock && n.parts.push({block: n.elseBlock});
|
|
5626
|
+
n.elseBlock && n.parts.push({ block: n.elseBlock });
|
|
5605
5627
|
n.parts.forEach((p, i) => {
|
|
5606
5628
|
if(i) ctx.write(', ');
|
|
5607
5629
|
ctx.add(p.block);
|
|
@@ -6430,7 +6452,7 @@
|
|
|
6430
6452
|
exp = unwrapExp(prop.value);
|
|
6431
6453
|
exp = replaceKeyword(exp, (name) => {
|
|
6432
6454
|
if(name == '$element') return requireElement();
|
|
6433
|
-
});
|
|
6455
|
+
}, true);
|
|
6434
6456
|
} else if(!handler) handler = event;
|
|
6435
6457
|
|
|
6436
6458
|
this.detectDependency(exp || handler);
|
|
@@ -6529,7 +6551,7 @@
|
|
|
6529
6551
|
return { event, fn, rootModifier };
|
|
6530
6552
|
}
|
|
6531
6553
|
|
|
6532
|
-
const version = '0.7.0-
|
|
6554
|
+
const version = '0.7.0-a13';
|
|
6533
6555
|
|
|
6534
6556
|
|
|
6535
6557
|
async function compile(source, config = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "malinajs",
|
|
3
|
-
"version": "0.7.0-
|
|
3
|
+
"version": "0.7.0-a13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "npm run build",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"fix": "npx standardx --fix ./src/"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"acorn": "^7.
|
|
20
|
-
"astring": "^1.8.
|
|
19
|
+
"acorn": "^8.7.1",
|
|
20
|
+
"astring": "^1.8.3",
|
|
21
21
|
"css-tree": "^1.0.0-alpha.39"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
package/runtime.js
CHANGED
|
@@ -24,8 +24,16 @@ const safeGroupCall = list => {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const safeCallMount = (mountList, destroyList) => {
|
|
28
|
+
mountList.forEach(fn => {
|
|
29
|
+
let r = safeCall(fn);
|
|
30
|
+
r && destroyList.push(r);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let current_destroyList, current_mountList, current_cd, destroyResults;
|
|
28
35
|
const $onDestroy = fn => fn && current_destroyList.push(fn);
|
|
36
|
+
const $onMount = fn => current_mountList.push(fn);
|
|
29
37
|
|
|
30
38
|
function WatchObject(fn, cb) {
|
|
31
39
|
this.fn = fn;
|
|
@@ -341,7 +349,6 @@ function $$addEventForComponent(list, event, fn) {
|
|
|
341
349
|
|
|
342
350
|
|
|
343
351
|
let current_component, $context;
|
|
344
|
-
const $onMount = fn => current_component._m.push(fn);
|
|
345
352
|
|
|
346
353
|
|
|
347
354
|
const makeApply = () => {
|
|
@@ -378,8 +385,7 @@ const makeComponent = (init) => {
|
|
|
378
385
|
$component = current_component = {
|
|
379
386
|
$option,
|
|
380
387
|
context: $context,
|
|
381
|
-
exported: {}
|
|
382
|
-
_m: []
|
|
388
|
+
exported: {}
|
|
383
389
|
};
|
|
384
390
|
current_cd = null;
|
|
385
391
|
|
|
@@ -391,7 +397,6 @@ const makeComponent = (init) => {
|
|
|
391
397
|
current_cd = prev_cd;
|
|
392
398
|
}
|
|
393
399
|
|
|
394
|
-
$component._m.forEach(fn => $onDestroy(safeCall(fn)));
|
|
395
400
|
return $component;
|
|
396
401
|
};
|
|
397
402
|
};
|
|
@@ -545,7 +550,7 @@ const bindAction = (element, action, fn, subscribe) => {
|
|
|
545
550
|
else {
|
|
546
551
|
$onDestroy(handler?.destroy);
|
|
547
552
|
subscribe?.(fn, handler, value);
|
|
548
|
-
handler?.init && $
|
|
553
|
+
handler?.init && $onMount(handler.init);
|
|
549
554
|
}
|
|
550
555
|
};
|
|
551
556
|
|
|
@@ -796,6 +801,7 @@ const makeRootEvent = (root) => {
|
|
|
796
801
|
|
|
797
802
|
const mount = (label, component, option) => {
|
|
798
803
|
let app, first, last, destroyList = current_destroyList = [];
|
|
804
|
+
current_mountList = [];
|
|
799
805
|
try {
|
|
800
806
|
app = component(option);
|
|
801
807
|
let $dom = app.$dom;
|
|
@@ -805,8 +811,10 @@ const mount = (label, component, option) => {
|
|
|
805
811
|
last = $dom.lastChild;
|
|
806
812
|
} else first = last = $dom;
|
|
807
813
|
label.appendChild($dom);
|
|
814
|
+
safeCallMount(current_mountList, destroyList);
|
|
808
815
|
} finally {
|
|
809
816
|
current_destroyList = null;
|
|
817
|
+
current_mountList = null;
|
|
810
818
|
}
|
|
811
819
|
app.destroy = () => {
|
|
812
820
|
safeGroupCall(destroyList);
|
|
@@ -817,12 +825,15 @@ const mount = (label, component, option) => {
|
|
|
817
825
|
|
|
818
826
|
const mountStatic = (label, component, option) => {
|
|
819
827
|
current_destroyList = [];
|
|
828
|
+
current_mountList = [];
|
|
820
829
|
try {
|
|
821
830
|
let app = component(option);
|
|
822
831
|
label.appendChild(app.$dom);
|
|
832
|
+
safeGroupCall(current_mountList);
|
|
823
833
|
return app;
|
|
824
834
|
} finally {
|
|
825
835
|
current_destroyList = null;
|
|
836
|
+
current_mountList = null;
|
|
826
837
|
}
|
|
827
838
|
};
|
|
828
839
|
|
|
@@ -900,11 +911,13 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
900
911
|
function createBlock(builder) {
|
|
901
912
|
let $dom;
|
|
902
913
|
destroyList = current_destroyList = [];
|
|
914
|
+
let mountList = current_mountList = [];
|
|
903
915
|
$cd = current_cd = cd_new();
|
|
904
916
|
try {
|
|
905
917
|
$dom = builder();
|
|
906
918
|
} finally {
|
|
907
919
|
current_destroyList = null;
|
|
920
|
+
current_mountList = null;
|
|
908
921
|
current_cd = null;
|
|
909
922
|
}
|
|
910
923
|
cd_attach2(parentCD, $cd);
|
|
@@ -914,6 +927,7 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
914
927
|
} else first = last = $dom;
|
|
915
928
|
if(parentLabel) label.appendChild($dom);
|
|
916
929
|
else insertAfter(label, $dom);
|
|
930
|
+
safeCallMount(mountList, destroyList);
|
|
917
931
|
}
|
|
918
932
|
|
|
919
933
|
function destroyBlock() {
|
|
@@ -970,12 +984,11 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
|
|
|
970
984
|
if(!builder) return;
|
|
971
985
|
destroyList = current_destroyList = [];
|
|
972
986
|
$cd = current_cd = cd_new();
|
|
973
|
-
let $dom;
|
|
987
|
+
let $dom, mountList = current_mountList = [];
|
|
974
988
|
try {
|
|
975
989
|
$dom = builder(value);
|
|
976
990
|
} finally {
|
|
977
|
-
current_destroyList = null;
|
|
978
|
-
current_cd = null;
|
|
991
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
979
992
|
}
|
|
980
993
|
cd_attach2(parentCD, $cd);
|
|
981
994
|
if($dom.nodeType == 11) {
|
|
@@ -983,6 +996,7 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
|
|
|
983
996
|
last = $dom.lastChild;
|
|
984
997
|
} else first = last = $dom;
|
|
985
998
|
insertAfter(label, $dom);
|
|
999
|
+
safeCallMount(mountList, destroyList);
|
|
986
1000
|
cd_component(parentCD).apply();
|
|
987
1001
|
}
|
|
988
1002
|
|
|
@@ -1044,8 +1058,8 @@ const makeEachElseBlock = (fn) => {
|
|
|
1044
1058
|
$$removeElements(first, last);
|
|
1045
1059
|
cd_detach($cd);
|
|
1046
1060
|
safeGroupCall(destroyList);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1061
|
+
};
|
|
1062
|
+
};
|
|
1049
1063
|
};
|
|
1050
1064
|
|
|
1051
1065
|
|
|
@@ -1176,22 +1190,25 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1176
1190
|
} else {
|
|
1177
1191
|
let $dom, rebind,
|
|
1178
1192
|
d = current_destroyList = [],
|
|
1193
|
+
m = current_mountList = [],
|
|
1179
1194
|
$cd = current_cd = cd_new();
|
|
1180
1195
|
try {
|
|
1181
1196
|
([$dom, rebind] = bind(item, i));
|
|
1182
1197
|
} finally {
|
|
1183
|
-
current_destroyList = null;
|
|
1184
|
-
current_cd = null;
|
|
1198
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
1185
1199
|
}
|
|
1186
|
-
|
|
1187
|
-
else d = null;
|
|
1188
|
-
ctx = { $cd, d, rebind };
|
|
1200
|
+
ctx = { $cd, rebind };
|
|
1189
1201
|
cd_attach2(eachCD, $cd);
|
|
1190
1202
|
if($dom.nodeType == 11) {
|
|
1191
1203
|
ctx.first = $dom.firstChild;
|
|
1192
1204
|
ctx.last = $dom.lastChild;
|
|
1193
1205
|
} else ctx.first = ctx.last = $dom;
|
|
1194
1206
|
parentNode.insertBefore($dom, prevNode?.nextSibling);
|
|
1207
|
+
safeCallMount(m, d);
|
|
1208
|
+
if(d.length) {
|
|
1209
|
+
ctx.d = d;
|
|
1210
|
+
p_destroy = 1;
|
|
1211
|
+
}
|
|
1195
1212
|
}
|
|
1196
1213
|
prevNode = ctx.last;
|
|
1197
1214
|
newMapping.set(key, ctx);
|
|
@@ -1245,4 +1262,4 @@ const makeSlot = (fr, fn) => {
|
|
|
1245
1262
|
};
|
|
1246
1263
|
};
|
|
1247
1264
|
|
|
1248
|
-
export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $context, $digest, $makeEmitter, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callExportedFragment, cd_attach, cd_attach2, cd_component, cd_detach, cd_new, cloneDeep, configure, createTextNode, current_cd, current_component, current_destroyList, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|
|
1265
|
+
export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $context, $digest, $makeEmitter, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callExportedFragment, cd_attach, cd_attach2, cd_component, cd_detach, cd_new, cloneDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|