bobe 0.0.57 → 0.0.59
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 +79 -18
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +79 -18
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +79 -18
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +79 -18
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.umd.js +79 -18
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.cjs.js
CHANGED
|
@@ -244,7 +244,6 @@ class Tokenizer {
|
|
|
244
244
|
}
|
|
245
245
|
isEof() {
|
|
246
246
|
if (!this.token) return false;
|
|
247
|
-
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
248
247
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
249
248
|
}
|
|
250
249
|
setToken(type, value, dt = 1) {
|
|
@@ -261,6 +260,7 @@ class Tokenizer {
|
|
|
261
260
|
if (this.isEof()) {
|
|
262
261
|
return this.token;
|
|
263
262
|
}
|
|
263
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return this.token;
|
|
264
264
|
this.token = undefined;
|
|
265
265
|
if (this.waitingTokens.len) {
|
|
266
266
|
const item = this.waitingTokens.shift();
|
|
@@ -1477,6 +1477,9 @@ class Interpreter {
|
|
|
1477
1477
|
if (this.tokenizer.isEof()) {
|
|
1478
1478
|
if (!ctx.prevSibling) ctx.prevSibling = before;
|
|
1479
1479
|
this.handleInsert(root, ctx.current, ctx.prevSibling, componentNode);
|
|
1480
|
+
if (ctx.current) {
|
|
1481
|
+
ctx.current.__logicType ? this.leaveLogicNode?.(ctx.current, false) : this.leaveNode?.(ctx.current, false);
|
|
1482
|
+
}
|
|
1480
1483
|
break;
|
|
1481
1484
|
}
|
|
1482
1485
|
const token = this.tokenizer.token;
|
|
@@ -1488,6 +1491,7 @@ class Interpreter {
|
|
|
1488
1491
|
prev: ctx.prevSibling
|
|
1489
1492
|
}, !ctx.current.__logicType ? NodeSort.Real : (ctx.current.__logicType & LogicalBit ? NodeSort.Logic : 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));
|
|
1490
1493
|
if (ctx.current.__logicType) {
|
|
1494
|
+
this.beforeLogicIndent?.(ctx.current);
|
|
1491
1495
|
if (isLogicNode) {
|
|
1492
1496
|
aoye.setPulling(ctx.current.effect);
|
|
1493
1497
|
if (ctx.current.__logicType & FakeType.ForItem) {
|
|
@@ -1496,6 +1500,12 @@ class Interpreter {
|
|
|
1496
1500
|
}
|
|
1497
1501
|
} else {
|
|
1498
1502
|
if (ctx.current) {
|
|
1503
|
+
if (this.beforeIndent?.(ctx.current) === false) {
|
|
1504
|
+
const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 1];
|
|
1505
|
+
this.tokenizer.skip(dentLen);
|
|
1506
|
+
ctx.current = null;
|
|
1507
|
+
continue;
|
|
1508
|
+
}
|
|
1499
1509
|
ctx.realParent = ctx.current;
|
|
1500
1510
|
}
|
|
1501
1511
|
ctx.prevSibling = null;
|
|
@@ -1508,6 +1518,7 @@ class Interpreter {
|
|
|
1508
1518
|
ctx.prevSibling = before;
|
|
1509
1519
|
}
|
|
1510
1520
|
this.handleInsert(ctx.realParent, ctx.current, ctx.prevSibling);
|
|
1521
|
+
ctx.current.__logicType ? this.leaveLogicNode?.(ctx.current, false) : this.leaveNode?.(ctx.current, false);
|
|
1511
1522
|
}
|
|
1512
1523
|
if (this.tokenizer.token.type & TokenType.Dedent) {
|
|
1513
1524
|
this.tokenizer.nextToken();
|
|
@@ -1542,6 +1553,7 @@ class Interpreter {
|
|
|
1542
1553
|
const i = forNode.i,
|
|
1543
1554
|
arr = forNode.arr,
|
|
1544
1555
|
snapshot = forNode.snapshot;
|
|
1556
|
+
this.leaveLogicNode?.(parent, false);
|
|
1545
1557
|
if (i + 1 < arr.length) {
|
|
1546
1558
|
this.tokenizer.resume(snapshot);
|
|
1547
1559
|
this.tokenizer.nextToken();
|
|
@@ -1564,13 +1576,13 @@ class Interpreter {
|
|
|
1564
1576
|
}
|
|
1565
1577
|
return componentNode;
|
|
1566
1578
|
}
|
|
1567
|
-
|
|
1579
|
+
insertAnchor(name = 'anchor', isBefore = false) {
|
|
1568
1580
|
const _this$ctx = this.ctx,
|
|
1569
1581
|
realParent = _this$ctx.realParent,
|
|
1570
1582
|
prevSibling = _this$ctx.prevSibling,
|
|
1571
1583
|
stack = _this$ctx.stack,
|
|
1572
1584
|
before = _this$ctx.before;
|
|
1573
|
-
const afterAnchor = this.createAnchor(name);
|
|
1585
|
+
const afterAnchor = this.createAnchor(name, isBefore);
|
|
1574
1586
|
this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
|
|
1575
1587
|
this.handleInsert(realParent, afterAnchor, prevSibling);
|
|
1576
1588
|
return afterAnchor;
|
|
@@ -1624,7 +1636,7 @@ class Interpreter {
|
|
|
1624
1636
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1625
1637
|
} else {
|
|
1626
1638
|
_node = this.createNode('text');
|
|
1627
|
-
_node
|
|
1639
|
+
this.setProp(_node, 'text', String(value));
|
|
1628
1640
|
}
|
|
1629
1641
|
} else {
|
|
1630
1642
|
return this.dynamicDeclaration(data, value, ctx);
|
|
@@ -1658,7 +1670,7 @@ class Interpreter {
|
|
|
1658
1670
|
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1659
1671
|
};
|
|
1660
1672
|
let isUpdate = false;
|
|
1661
|
-
node.realAfter = this.
|
|
1673
|
+
node.realAfter = this.insertAnchor(`dynamic-after`);
|
|
1662
1674
|
node.effect = this.effect(({
|
|
1663
1675
|
old,
|
|
1664
1676
|
val
|
|
@@ -1694,11 +1706,13 @@ class Interpreter {
|
|
|
1694
1706
|
this.tokenizer = node.tokenizer;
|
|
1695
1707
|
if (node.fragmentSnapshot) {
|
|
1696
1708
|
this.tokenizer.resume(node.fragmentSnapshot);
|
|
1697
|
-
this.tokenizer.useDedentAsEof = true;
|
|
1698
|
-
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1699
1709
|
}
|
|
1700
1710
|
if (isUpdate) {
|
|
1711
|
+
this.tokenizer.useDedentAsEof = false;
|
|
1701
1712
|
this.program(node.realParent, node.owner, node.realBefore, node);
|
|
1713
|
+
} else {
|
|
1714
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1715
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1702
1716
|
}
|
|
1703
1717
|
} else {
|
|
1704
1718
|
node.__logicType = FakeType.DynamicText;
|
|
@@ -1707,7 +1721,7 @@ class Interpreter {
|
|
|
1707
1721
|
if (isNewTextNode) {
|
|
1708
1722
|
textNode = node.textNode = this.createNode('text');
|
|
1709
1723
|
}
|
|
1710
|
-
textNode
|
|
1724
|
+
this.setProp(textNode, 'text', String(val));
|
|
1711
1725
|
if (isNewTextNode) {
|
|
1712
1726
|
if (isUpdate) {
|
|
1713
1727
|
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
@@ -1719,6 +1733,7 @@ class Interpreter {
|
|
|
1719
1733
|
prevSibling = _this$ctx2.prevSibling;
|
|
1720
1734
|
this.handleInsert(realParent, textNode, prevSibling);
|
|
1721
1735
|
}
|
|
1736
|
+
this.leaveNode?.(textNode, false);
|
|
1722
1737
|
}
|
|
1723
1738
|
}
|
|
1724
1739
|
isUpdate = true;
|
|
@@ -1749,7 +1764,7 @@ class Interpreter {
|
|
|
1749
1764
|
realBefore: null,
|
|
1750
1765
|
realAfter: null
|
|
1751
1766
|
};
|
|
1752
|
-
node.realAfter = this.
|
|
1767
|
+
node.realAfter = this.insertAnchor('context-after');
|
|
1753
1768
|
return node;
|
|
1754
1769
|
}
|
|
1755
1770
|
formatForCollection(collection) {
|
|
@@ -1847,7 +1862,7 @@ class Interpreter {
|
|
|
1847
1862
|
const hasArrExpKey = Reflect.has(data[aoye.Keys.Raw], arrExp);
|
|
1848
1863
|
const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new aoye.Computed(this.getFn(data, arrExp));
|
|
1849
1864
|
forNode.arrSignal = arrSignal;
|
|
1850
|
-
forNode.realAfter = this.
|
|
1865
|
+
forNode.realAfter = this.insertAnchor('for-after');
|
|
1851
1866
|
const _forNode$snapshot = forNode.snapshot;
|
|
1852
1867
|
_forNode$snapshot.dentStack;
|
|
1853
1868
|
_forNode$snapshot.isFirstToken;
|
|
@@ -1870,8 +1885,8 @@ class Interpreter {
|
|
|
1870
1885
|
const len = arr.length;
|
|
1871
1886
|
for (let i = len; i--;) {
|
|
1872
1887
|
const item = this.createForItem(forNode, i, data);
|
|
1873
|
-
item.realAfter = this.
|
|
1874
|
-
item.realBefore = this.
|
|
1888
|
+
item.realAfter = this.insertAnchor('for-item-after');
|
|
1889
|
+
item.realBefore = this.insertAnchor('for-item-before', true);
|
|
1875
1890
|
item.realParent = forNode.realParent;
|
|
1876
1891
|
children[i] = item;
|
|
1877
1892
|
}
|
|
@@ -2038,7 +2053,7 @@ class Interpreter {
|
|
|
2038
2053
|
newChildren[i] = item;
|
|
2039
2054
|
let realAfter = this.createAnchor('for-item-after');
|
|
2040
2055
|
this.handleInsert(forNode.realParent, realAfter, before);
|
|
2041
|
-
let realBefore = this.createAnchor('for-item-before');
|
|
2056
|
+
let realBefore = this.createAnchor('for-item-before', true);
|
|
2042
2057
|
this.handleInsert(forNode.realParent, realBefore, before);
|
|
2043
2058
|
item.realBefore = realBefore;
|
|
2044
2059
|
item.realAfter = realAfter;
|
|
@@ -2207,7 +2222,7 @@ class Interpreter {
|
|
|
2207
2222
|
resumeSnapshot
|
|
2208
2223
|
};
|
|
2209
2224
|
this.onePropParsed = onePropParsed;
|
|
2210
|
-
node.realAfter = this.
|
|
2225
|
+
node.realAfter = this.insertAnchor('component-after');
|
|
2211
2226
|
return node;
|
|
2212
2227
|
}
|
|
2213
2228
|
getFn(data, expression) {
|
|
@@ -2302,7 +2317,7 @@ class Interpreter {
|
|
|
2302
2317
|
break;
|
|
2303
2318
|
}
|
|
2304
2319
|
ifNode.condition = signal;
|
|
2305
|
-
ifNode.realAfter = this.
|
|
2320
|
+
ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
|
|
2306
2321
|
const ef = this.effect(({
|
|
2307
2322
|
val
|
|
2308
2323
|
}) => {
|
|
@@ -2386,7 +2401,51 @@ class Interpreter {
|
|
|
2386
2401
|
hookI = _this$tokenizer$_hook4[2];
|
|
2387
2402
|
const rawVal = data[aoye.Keys.Raw][value];
|
|
2388
2403
|
const isFn = typeof rawVal === 'function';
|
|
2389
|
-
if (key === '
|
|
2404
|
+
if (key === 'props') {
|
|
2405
|
+
let prevKeys = new Set();
|
|
2406
|
+
const savedDefaults = new Map();
|
|
2407
|
+
new this.Effect(() => {
|
|
2408
|
+
const props = isFn ? rawVal : Reflect.has(data[aoye.Keys.Raw], value) ? data[value] : this.getFn(data, value)();
|
|
2409
|
+
const isComponent = _node.__logicType & TokenizerSwitcherBit;
|
|
2410
|
+
const rawTarget = isComponent ? _node.data[aoye.Keys.Raw] : null;
|
|
2411
|
+
const cleanupKeys = keysToClean => {
|
|
2412
|
+
for (const k of keysToClean) {
|
|
2413
|
+
if (k.startsWith('on')) continue;
|
|
2414
|
+
if (isComponent) {
|
|
2415
|
+
_node.data[k] = savedDefaults.has(k) ? savedDefaults.get(k) : undefined;
|
|
2416
|
+
} else {
|
|
2417
|
+
this.setProp(_node, k, undefined, hookI);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
if (!props || typeof props !== 'object') {
|
|
2422
|
+
cleanupKeys(prevKeys);
|
|
2423
|
+
prevKeys.clear();
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
props[aoye.Keys.Iterator];
|
|
2427
|
+
const raw = props[aoye.Keys.Raw] || props;
|
|
2428
|
+
const keys = Object.keys(raw);
|
|
2429
|
+
const newKeys = new Set();
|
|
2430
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2431
|
+
const k = keys[i];
|
|
2432
|
+
newKeys.add(k);
|
|
2433
|
+
prevKeys.delete(k);
|
|
2434
|
+
if (isComponent) {
|
|
2435
|
+
const savedK = savedDefaults.has(k);
|
|
2436
|
+
if (!savedK && Object.prototype.hasOwnProperty.call(rawTarget, k)) {
|
|
2437
|
+
savedDefaults.set(k, rawTarget[k]);
|
|
2438
|
+
}
|
|
2439
|
+
const val = props[k];
|
|
2440
|
+
_node.data[k] = val === undefined && savedK ? savedDefaults.get(k) : val;
|
|
2441
|
+
} else {
|
|
2442
|
+
this.onePropParsed(props, _node, k, k, true, false, hookI);
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
cleanupKeys(prevKeys);
|
|
2446
|
+
prevKeys = newKeys;
|
|
2447
|
+
}, aoye.ScheduleType.Render);
|
|
2448
|
+
} else if (key === 'ref') {
|
|
2390
2449
|
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2391
2450
|
let refValue = _node;
|
|
2392
2451
|
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
@@ -2443,10 +2502,11 @@ class Interpreter {
|
|
|
2443
2502
|
firstChild(node) {
|
|
2444
2503
|
return node.firstChild;
|
|
2445
2504
|
}
|
|
2446
|
-
createAnchor(name) {
|
|
2505
|
+
createAnchor(name, isBefore) {
|
|
2447
2506
|
return {
|
|
2448
2507
|
name,
|
|
2449
|
-
nextSibling: null
|
|
2508
|
+
nextSibling: null,
|
|
2509
|
+
isBefore
|
|
2450
2510
|
};
|
|
2451
2511
|
}
|
|
2452
2512
|
insertAfter(parent, node, prev) {
|
|
@@ -2532,6 +2592,7 @@ function customRender(option) {
|
|
|
2532
2592
|
tokenizer
|
|
2533
2593
|
};
|
|
2534
2594
|
terp.program(root, componentNode);
|
|
2595
|
+
option.onBeforeFlush?.();
|
|
2535
2596
|
aoye.flushMicroEffectManual();
|
|
2536
2597
|
return [componentNode, store];
|
|
2537
2598
|
};
|