bobe 0.0.60 → 0.0.61
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/bobe.cjs.js +127 -22
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +127 -22
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +127 -22
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +127 -22
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +18 -5
- package/dist/index.umd.js +127 -22
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.esm.js
CHANGED
|
@@ -33,15 +33,15 @@ let FakeType = function (FakeType) {
|
|
|
33
33
|
FakeType[FakeType["ForItem"] = 64] = "ForItem";
|
|
34
34
|
FakeType[FakeType["Context"] = 128] = "Context";
|
|
35
35
|
FakeType[FakeType["DynamicText"] = 256] = "DynamicText";
|
|
36
|
+
FakeType[FakeType["Tp"] = 512] = "Tp";
|
|
36
37
|
return FakeType;
|
|
37
38
|
}({});
|
|
38
39
|
const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
|
|
39
|
-
const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
|
|
40
40
|
const CtxProviderBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment | FakeType.DynamicText;
|
|
41
|
-
const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context;
|
|
41
|
+
const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context | FakeType.Tp;
|
|
42
42
|
const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
|
|
43
43
|
let NodeSort = function (NodeSort) {
|
|
44
|
-
NodeSort[NodeSort["
|
|
44
|
+
NodeSort[NodeSort["EffectNode"] = 1] = "EffectNode";
|
|
45
45
|
NodeSort[NodeSort["Real"] = 2] = "Real";
|
|
46
46
|
NodeSort[NodeSort["Component"] = 4] = "Component";
|
|
47
47
|
NodeSort[NodeSort["CtxProvider"] = 8] = "CtxProvider";
|
|
@@ -54,6 +54,7 @@ let NodeSort = function (NodeSort) {
|
|
|
54
54
|
TerpEvt["HandledComponentNode"] = "handled-component-node";
|
|
55
55
|
return TerpEvt;
|
|
56
56
|
})({});
|
|
57
|
+
const FakeNode = Symbol('fake-node');
|
|
57
58
|
let ParseErrorCode = function (ParseErrorCode) {
|
|
58
59
|
ParseErrorCode[ParseErrorCode["UNCLOSED_BRACE"] = 9001] = "UNCLOSED_BRACE";
|
|
59
60
|
ParseErrorCode[ParseErrorCode["UNCLOSED_STRING"] = 9002] = "UNCLOSED_STRING";
|
|
@@ -1448,9 +1449,6 @@ class Interpreter {
|
|
|
1448
1449
|
constructor(tokenizer) {
|
|
1449
1450
|
this.tokenizer = tokenizer;
|
|
1450
1451
|
}
|
|
1451
|
-
isLogicNode(node) {
|
|
1452
|
-
return node && node.__logicType & LogicalBit;
|
|
1453
|
-
}
|
|
1454
1452
|
rootComponent = null;
|
|
1455
1453
|
program(root, componentNode, before, ctxProvider) {
|
|
1456
1454
|
this.rootComponent = componentNode;
|
|
@@ -1469,7 +1467,7 @@ class Interpreter {
|
|
|
1469
1467
|
stack.push({
|
|
1470
1468
|
node: ctxProvider,
|
|
1471
1469
|
prev: null
|
|
1472
|
-
}, (ctxProvider.__logicType
|
|
1470
|
+
}, (ctxProvider.__logicType && ctxProvider.effect ? NodeSort.EffectNode : 0) | NodeSort.CtxProvider);
|
|
1473
1471
|
}
|
|
1474
1472
|
const rootLen = stack.length;
|
|
1475
1473
|
const ctx = this.ctx = {
|
|
@@ -1492,18 +1490,22 @@ class Interpreter {
|
|
|
1492
1490
|
const token = this.tokenizer.token;
|
|
1493
1491
|
if (token.type & TokenType.Indent) {
|
|
1494
1492
|
this.tokenizer.nextToken();
|
|
1495
|
-
const
|
|
1493
|
+
const isEffectNode = ctx.current && ctx.current.__logicType && ctx.current.effect;
|
|
1496
1494
|
stack.push({
|
|
1497
1495
|
node: ctx.current,
|
|
1498
1496
|
prev: ctx.prevSibling
|
|
1499
|
-
}, !ctx.current.__logicType ? NodeSort.Real : (
|
|
1497
|
+
}, !ctx.current.__logicType ? NodeSort.Real : (isEffectNode ? NodeSort.EffectNode : 0) | (ctx.current.__logicType & TokenizerSwitcherBit ? NodeSort.TokenizerSwitcher : 0) | (ctx.current.__logicType & ContextBit ? NodeSort.Context : 0) | (ctx.current.__logicType === FakeType.Component ? NodeSort.Component : 0) | (ctx.current.__logicType & CtxProviderBit ? NodeSort.CtxProvider : 0));
|
|
1500
1498
|
if (ctx.current.__logicType) {
|
|
1501
1499
|
this.beforeLogicIndent?.(ctx.current);
|
|
1502
|
-
if (
|
|
1500
|
+
if (isEffectNode) {
|
|
1503
1501
|
setPulling(ctx.current.effect);
|
|
1504
1502
|
if (ctx.current.__logicType & FakeType.ForItem) {
|
|
1505
1503
|
ctx.prevSibling = ctx.current.realBefore;
|
|
1506
1504
|
}
|
|
1505
|
+
if (ctx.current.__logicType & FakeType.Tp) {
|
|
1506
|
+
ctx.realParent = ctx.current.tpData[Keys.Raw].node;
|
|
1507
|
+
ctx.prevSibling = ctx.current.contentBefore;
|
|
1508
|
+
}
|
|
1507
1509
|
}
|
|
1508
1510
|
} else {
|
|
1509
1511
|
if (ctx.current) {
|
|
@@ -1539,14 +1541,17 @@ class Interpreter {
|
|
|
1539
1541
|
const prevSameType = stack.peekByType(NodeSort.Real);
|
|
1540
1542
|
ctx.realParent = prevSameType?.node || root;
|
|
1541
1543
|
} else {
|
|
1542
|
-
if (sort & NodeSort.
|
|
1543
|
-
const parentLogic = stack.peekByType(NodeSort.
|
|
1544
|
+
if (sort & NodeSort.EffectNode) {
|
|
1545
|
+
const parentLogic = stack.peekByType(NodeSort.EffectNode)?.node;
|
|
1544
1546
|
if (parentLogic) {
|
|
1545
1547
|
setPulling(parentLogic.effect);
|
|
1546
1548
|
} else {
|
|
1547
1549
|
setPulling(rootPulling);
|
|
1548
1550
|
}
|
|
1549
1551
|
}
|
|
1552
|
+
if (parent.__logicType === FakeType.Tp) {
|
|
1553
|
+
ctx.realParent = parent.realParent;
|
|
1554
|
+
}
|
|
1550
1555
|
if (sort & NodeSort.TokenizerSwitcher) {
|
|
1551
1556
|
const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
|
|
1552
1557
|
if (parent.resumeSnapshot) {
|
|
@@ -1583,13 +1588,17 @@ class Interpreter {
|
|
|
1583
1588
|
}
|
|
1584
1589
|
return componentNode;
|
|
1585
1590
|
}
|
|
1586
|
-
insertAnchor(name = 'anchor', isBefore = false) {
|
|
1591
|
+
insertAnchor(node, name = 'anchor', isBefore = false) {
|
|
1587
1592
|
const _this$ctx = this.ctx,
|
|
1588
1593
|
realParent = _this$ctx.realParent,
|
|
1589
1594
|
prevSibling = _this$ctx.prevSibling,
|
|
1590
1595
|
stack = _this$ctx.stack,
|
|
1591
1596
|
before = _this$ctx.before;
|
|
1597
|
+
_this$ctx.current;
|
|
1592
1598
|
const afterAnchor = this.createAnchor(name, isBefore);
|
|
1599
|
+
if (!isBefore) {
|
|
1600
|
+
this.anchorRefBack(afterAnchor, node);
|
|
1601
|
+
}
|
|
1593
1602
|
this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
|
|
1594
1603
|
this.handleInsert(realParent, afterAnchor, prevSibling);
|
|
1595
1604
|
return afterAnchor;
|
|
@@ -1634,6 +1643,8 @@ class Interpreter {
|
|
|
1634
1643
|
return this.condDeclaration(ctx);
|
|
1635
1644
|
} else if (value === 'context') {
|
|
1636
1645
|
_node = this.createContextNode();
|
|
1646
|
+
} else if (value === 'tp') {
|
|
1647
|
+
return this.createTpNode();
|
|
1637
1648
|
} else if (value === 'for') {
|
|
1638
1649
|
return this.forDeclaration();
|
|
1639
1650
|
} else if (hookType) {
|
|
@@ -1677,7 +1688,7 @@ class Interpreter {
|
|
|
1677
1688
|
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1678
1689
|
};
|
|
1679
1690
|
let isUpdate = false;
|
|
1680
|
-
node.realAfter = this.insertAnchor(`dynamic-after`);
|
|
1691
|
+
node.realAfter = this.insertAnchor(node, `dynamic-after`);
|
|
1681
1692
|
node.effect = this.effect(({
|
|
1682
1693
|
old,
|
|
1683
1694
|
val
|
|
@@ -1757,6 +1768,93 @@ class Interpreter {
|
|
|
1757
1768
|
});
|
|
1758
1769
|
return node;
|
|
1759
1770
|
}
|
|
1771
|
+
createTpNode() {
|
|
1772
|
+
const child = deepSignal({}, getPulling());
|
|
1773
|
+
const node = {
|
|
1774
|
+
__logicType: FakeType.Tp,
|
|
1775
|
+
data: this.getData(),
|
|
1776
|
+
realParent: null,
|
|
1777
|
+
realBefore: null,
|
|
1778
|
+
realAfter: null,
|
|
1779
|
+
contentBefore: null,
|
|
1780
|
+
contentAfter: null,
|
|
1781
|
+
effect: null,
|
|
1782
|
+
snapshot: null,
|
|
1783
|
+
tpData: child,
|
|
1784
|
+
owner: this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node
|
|
1785
|
+
};
|
|
1786
|
+
this.onePropParsed = createStoreOnePropParsed(child);
|
|
1787
|
+
this.tokenizer.nextToken();
|
|
1788
|
+
this.headerLineAndExtensions(node);
|
|
1789
|
+
this.onePropParsed = this.oneRealPropParsed;
|
|
1790
|
+
node.realAfter = this.insertAnchor(node, 'tp-after');
|
|
1791
|
+
const before = node.contentBefore = this.createAnchor('tp-content-before', true);
|
|
1792
|
+
const after = node.contentAfter = this.createAnchor('tp-content-after', true);
|
|
1793
|
+
let firstRender = true;
|
|
1794
|
+
node.effect = this.effect(({
|
|
1795
|
+
old: oldDom,
|
|
1796
|
+
val: dom
|
|
1797
|
+
}) => {
|
|
1798
|
+
const removeTpChild = () => {
|
|
1799
|
+
if (oldDom) {
|
|
1800
|
+
let point = before;
|
|
1801
|
+
do {
|
|
1802
|
+
const next = this.nextSib(point);
|
|
1803
|
+
this.remove(point, oldDom, null);
|
|
1804
|
+
if (point === after) break;
|
|
1805
|
+
point = next;
|
|
1806
|
+
} while (true);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
if (firstRender) {
|
|
1810
|
+
if (dom) {
|
|
1811
|
+
this.handleInsert(dom, after, null);
|
|
1812
|
+
this.handleInsert(dom, before, null);
|
|
1813
|
+
} else {
|
|
1814
|
+
if (this.tokenizer.token.type === TokenType.Indent) {
|
|
1815
|
+
const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 2] ?? 0;
|
|
1816
|
+
this.tokenizer.skip(dentLen);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
} else {
|
|
1820
|
+
if (dom) {
|
|
1821
|
+
if (oldDom) {
|
|
1822
|
+
let point = before,
|
|
1823
|
+
lastInsert = null;
|
|
1824
|
+
do {
|
|
1825
|
+
const next = this.nextSib(point);
|
|
1826
|
+
const fakeNode = point[FakeNode];
|
|
1827
|
+
if (fakeNode) {
|
|
1828
|
+
fakeNode.realParent = dom;
|
|
1829
|
+
}
|
|
1830
|
+
this.handleInsert(dom, point, lastInsert);
|
|
1831
|
+
if (point === after) break;
|
|
1832
|
+
lastInsert = point;
|
|
1833
|
+
point = next;
|
|
1834
|
+
} while (true);
|
|
1835
|
+
} else {
|
|
1836
|
+
this.handleInsert(dom, after, null);
|
|
1837
|
+
this.handleInsert(dom, before, null);
|
|
1838
|
+
this.tokenizer = node.owner.tokenizer;
|
|
1839
|
+
this.tokenizer.resume(node.snapshot);
|
|
1840
|
+
this.tokenizer.useDedentAsEof = false;
|
|
1841
|
+
this.program(dom, node.owner, before, node);
|
|
1842
|
+
}
|
|
1843
|
+
} else {
|
|
1844
|
+
removeTpChild();
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
firstRender = false;
|
|
1848
|
+
return isDestroy => {
|
|
1849
|
+
if (isDestroy) {
|
|
1850
|
+
removeTpChild();
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
}, [() => child.node], {
|
|
1854
|
+
type: 'render'
|
|
1855
|
+
});
|
|
1856
|
+
return node;
|
|
1857
|
+
}
|
|
1760
1858
|
createContextNode() {
|
|
1761
1859
|
const child = deepSignal({}, getPulling());
|
|
1762
1860
|
const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
|
|
@@ -1771,7 +1869,7 @@ class Interpreter {
|
|
|
1771
1869
|
realBefore: null,
|
|
1772
1870
|
realAfter: null
|
|
1773
1871
|
};
|
|
1774
|
-
node.realAfter = this.insertAnchor('context-after');
|
|
1872
|
+
node.realAfter = this.insertAnchor(node, 'context-after');
|
|
1775
1873
|
return node;
|
|
1776
1874
|
}
|
|
1777
1875
|
formatForCollection(collection) {
|
|
@@ -1864,13 +1962,12 @@ class Interpreter {
|
|
|
1864
1962
|
const rawGetKey = new Function('data', `with(data){return (${keyExp})}`);
|
|
1865
1963
|
forNode.getKey = data => rawGetKey(safe(data));
|
|
1866
1964
|
}
|
|
1867
|
-
window['for1'] = forNode;
|
|
1868
1965
|
const data = this.getData();
|
|
1869
1966
|
const cells = data[Keys.Meta].cells;
|
|
1870
1967
|
const hasArrExpKey = Reflect.has(data[Keys.Raw], arrExp);
|
|
1871
1968
|
const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new Computed(this.getFn(data, arrExp));
|
|
1872
1969
|
forNode.arrSignal = arrSignal;
|
|
1873
|
-
forNode.realAfter = this.insertAnchor('for-after');
|
|
1970
|
+
forNode.realAfter = this.insertAnchor(forNode, 'for-after');
|
|
1874
1971
|
const _forNode$snapshot = forNode.snapshot;
|
|
1875
1972
|
_forNode$snapshot.dentStack;
|
|
1876
1973
|
_forNode$snapshot.isFirstToken;
|
|
@@ -1893,8 +1990,8 @@ class Interpreter {
|
|
|
1893
1990
|
const len = arr.length;
|
|
1894
1991
|
for (let i = len; i--;) {
|
|
1895
1992
|
const item = this.createForItem(forNode, i, data);
|
|
1896
|
-
item.realAfter = this.insertAnchor('for-item-after');
|
|
1897
|
-
item.realBefore = this.insertAnchor('for-item-before', true);
|
|
1993
|
+
item.realAfter = this.insertAnchor(item, 'for-item-after');
|
|
1994
|
+
item.realBefore = this.insertAnchor(item, 'for-item-before', true);
|
|
1898
1995
|
item.realParent = forNode.realParent;
|
|
1899
1996
|
children[i] = item;
|
|
1900
1997
|
}
|
|
@@ -2056,10 +2153,14 @@ class Interpreter {
|
|
|
2056
2153
|
}, ScheduleType.Render);
|
|
2057
2154
|
return forNode.children[0] || forNode;
|
|
2058
2155
|
}
|
|
2156
|
+
anchorRefBack(anchor, node) {
|
|
2157
|
+
anchor[FakeNode] = node;
|
|
2158
|
+
}
|
|
2059
2159
|
insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
|
|
2060
2160
|
const item = this.createForItem(forNode, i, parentData);
|
|
2061
2161
|
newChildren[i] = item;
|
|
2062
2162
|
let realAfter = this.createAnchor('for-item-after');
|
|
2163
|
+
this.anchorRefBack(realAfter, item);
|
|
2063
2164
|
this.handleInsert(forNode.realParent, realAfter, before);
|
|
2064
2165
|
let realBefore = this.createAnchor('for-item-before', true);
|
|
2065
2166
|
this.handleInsert(forNode.realParent, realBefore, before);
|
|
@@ -2230,7 +2331,7 @@ class Interpreter {
|
|
|
2230
2331
|
resumeSnapshot
|
|
2231
2332
|
};
|
|
2232
2333
|
this.onePropParsed = onePropParsed;
|
|
2233
|
-
node.realAfter = this.insertAnchor('component-after');
|
|
2334
|
+
node.realAfter = this.insertAnchor(node, 'component-after');
|
|
2234
2335
|
return node;
|
|
2235
2336
|
}
|
|
2236
2337
|
getFn(data, expression) {
|
|
@@ -2325,7 +2426,7 @@ class Interpreter {
|
|
|
2325
2426
|
break;
|
|
2326
2427
|
}
|
|
2327
2428
|
ifNode.condition = signal;
|
|
2328
|
-
ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
|
|
2429
|
+
ifNode.realAfter = this.insertAnchor(ifNode, `${keyWord.value}-after`);
|
|
2329
2430
|
const ef = this.effect(({
|
|
2330
2431
|
val
|
|
2331
2432
|
}) => {
|
|
@@ -2368,10 +2469,11 @@ class Interpreter {
|
|
|
2368
2469
|
const tokenizer = this.tokenizer;
|
|
2369
2470
|
do {
|
|
2370
2471
|
const isComponent = _node.__logicType & TokenizerSwitcherBit;
|
|
2472
|
+
const isTp = _node.__logicType === FakeType.Tp;
|
|
2371
2473
|
let snapshot, dentLen;
|
|
2372
2474
|
const data = this.getData();
|
|
2373
2475
|
const unHandledKey = this.attributeList(_node, data);
|
|
2374
|
-
if (isComponent) {
|
|
2476
|
+
if (isComponent || isTp) {
|
|
2375
2477
|
snapshot = tokenizer.snapshot(undefined, -1);
|
|
2376
2478
|
dentLen = tokenizer.dentStack[tokenizer.dentStack.length - 1];
|
|
2377
2479
|
}
|
|
@@ -2383,6 +2485,9 @@ class Interpreter {
|
|
|
2383
2485
|
if ((tokenizer.token.type & TokenType.Pipe) === 0) {
|
|
2384
2486
|
break;
|
|
2385
2487
|
}
|
|
2488
|
+
} else if (isTp) {
|
|
2489
|
+
_node.snapshot = snapshot;
|
|
2490
|
+
break;
|
|
2386
2491
|
} else {
|
|
2387
2492
|
break;
|
|
2388
2493
|
}
|