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
|
@@ -253,7 +253,6 @@ class Tokenizer {
|
|
|
253
253
|
}
|
|
254
254
|
isEof() {
|
|
255
255
|
if (!this.token) return false;
|
|
256
|
-
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
257
256
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
258
257
|
}
|
|
259
258
|
setToken(type, value, dt = 1) {
|
|
@@ -282,6 +281,7 @@ class Tokenizer {
|
|
|
282
281
|
if (this.isEof()) {
|
|
283
282
|
return this.token;
|
|
284
283
|
}
|
|
284
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return this.token;
|
|
285
285
|
this.token = undefined;
|
|
286
286
|
if (this.waitingTokens.len) {
|
|
287
287
|
const item = this.waitingTokens.shift();
|
|
@@ -1504,6 +1504,9 @@ class Interpreter {
|
|
|
1504
1504
|
if (this.tokenizer.isEof()) {
|
|
1505
1505
|
if (!ctx.prevSibling) ctx.prevSibling = before;
|
|
1506
1506
|
this.handleInsert(root, ctx.current, ctx.prevSibling, componentNode);
|
|
1507
|
+
if (ctx.current) {
|
|
1508
|
+
ctx.current.__logicType ? this.leaveLogicNode?.(ctx.current, false) : this.leaveNode?.(ctx.current, false);
|
|
1509
|
+
}
|
|
1507
1510
|
break;
|
|
1508
1511
|
}
|
|
1509
1512
|
const token = this.tokenizer.token;
|
|
@@ -1515,6 +1518,7 @@ class Interpreter {
|
|
|
1515
1518
|
prev: ctx.prevSibling
|
|
1516
1519
|
}, !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));
|
|
1517
1520
|
if (ctx.current.__logicType) {
|
|
1521
|
+
this.beforeLogicIndent?.(ctx.current);
|
|
1518
1522
|
if (isLogicNode) {
|
|
1519
1523
|
aoye.setPulling(ctx.current.effect);
|
|
1520
1524
|
if (ctx.current.__logicType & FakeType.ForItem) {
|
|
@@ -1523,6 +1527,12 @@ class Interpreter {
|
|
|
1523
1527
|
}
|
|
1524
1528
|
} else {
|
|
1525
1529
|
if (ctx.current) {
|
|
1530
|
+
if (this.beforeIndent?.(ctx.current) === false) {
|
|
1531
|
+
const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 1];
|
|
1532
|
+
this.tokenizer.skip(dentLen);
|
|
1533
|
+
ctx.current = null;
|
|
1534
|
+
continue;
|
|
1535
|
+
}
|
|
1526
1536
|
ctx.realParent = ctx.current;
|
|
1527
1537
|
}
|
|
1528
1538
|
ctx.prevSibling = null;
|
|
@@ -1535,6 +1545,7 @@ class Interpreter {
|
|
|
1535
1545
|
ctx.prevSibling = before;
|
|
1536
1546
|
}
|
|
1537
1547
|
this.handleInsert(ctx.realParent, ctx.current, ctx.prevSibling);
|
|
1548
|
+
ctx.current.__logicType ? this.leaveLogicNode?.(ctx.current, false) : this.leaveNode?.(ctx.current, false);
|
|
1538
1549
|
}
|
|
1539
1550
|
if (this.tokenizer.token.type & TokenType.Dedent) {
|
|
1540
1551
|
this.tokenizer.nextToken();
|
|
@@ -1569,6 +1580,7 @@ class Interpreter {
|
|
|
1569
1580
|
const i = forNode.i,
|
|
1570
1581
|
arr = forNode.arr,
|
|
1571
1582
|
snapshot = forNode.snapshot;
|
|
1583
|
+
this.leaveLogicNode?.(parent, false);
|
|
1572
1584
|
if (i + 1 < arr.length) {
|
|
1573
1585
|
this.tokenizer.resume(snapshot);
|
|
1574
1586
|
this.tokenizer.nextToken();
|
|
@@ -1591,13 +1603,13 @@ class Interpreter {
|
|
|
1591
1603
|
}
|
|
1592
1604
|
return componentNode;
|
|
1593
1605
|
}
|
|
1594
|
-
|
|
1606
|
+
insertAnchor(name = 'anchor', isBefore = false) {
|
|
1595
1607
|
const _this$ctx = this.ctx,
|
|
1596
1608
|
realParent = _this$ctx.realParent,
|
|
1597
1609
|
prevSibling = _this$ctx.prevSibling,
|
|
1598
1610
|
stack = _this$ctx.stack,
|
|
1599
1611
|
before = _this$ctx.before;
|
|
1600
|
-
const afterAnchor = this.createAnchor(name);
|
|
1612
|
+
const afterAnchor = this.createAnchor(name, isBefore);
|
|
1601
1613
|
this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
|
|
1602
1614
|
this.handleInsert(realParent, afterAnchor, prevSibling);
|
|
1603
1615
|
return afterAnchor;
|
|
@@ -1651,7 +1663,7 @@ class Interpreter {
|
|
|
1651
1663
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1652
1664
|
} else {
|
|
1653
1665
|
_node = this.createNode('text');
|
|
1654
|
-
_node
|
|
1666
|
+
this.setProp(_node, 'text', String(value));
|
|
1655
1667
|
}
|
|
1656
1668
|
} else {
|
|
1657
1669
|
return this.dynamicDeclaration(data, value, ctx);
|
|
@@ -1685,7 +1697,7 @@ class Interpreter {
|
|
|
1685
1697
|
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1686
1698
|
};
|
|
1687
1699
|
let isUpdate = false;
|
|
1688
|
-
node.realAfter = this.
|
|
1700
|
+
node.realAfter = this.insertAnchor(`dynamic-after`);
|
|
1689
1701
|
node.effect = this.effect(({
|
|
1690
1702
|
old,
|
|
1691
1703
|
val
|
|
@@ -1721,11 +1733,13 @@ class Interpreter {
|
|
|
1721
1733
|
this.tokenizer = node.tokenizer;
|
|
1722
1734
|
if (node.fragmentSnapshot) {
|
|
1723
1735
|
this.tokenizer.resume(node.fragmentSnapshot);
|
|
1724
|
-
this.tokenizer.useDedentAsEof = true;
|
|
1725
|
-
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1726
1736
|
}
|
|
1727
1737
|
if (isUpdate) {
|
|
1738
|
+
this.tokenizer.useDedentAsEof = false;
|
|
1728
1739
|
this.program(node.realParent, node.owner, node.realBefore, node);
|
|
1740
|
+
} else {
|
|
1741
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1742
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1729
1743
|
}
|
|
1730
1744
|
} else {
|
|
1731
1745
|
node.__logicType = FakeType.DynamicText;
|
|
@@ -1734,7 +1748,7 @@ class Interpreter {
|
|
|
1734
1748
|
if (isNewTextNode) {
|
|
1735
1749
|
textNode = node.textNode = this.createNode('text');
|
|
1736
1750
|
}
|
|
1737
|
-
textNode
|
|
1751
|
+
this.setProp(textNode, 'text', String(val));
|
|
1738
1752
|
if (isNewTextNode) {
|
|
1739
1753
|
if (isUpdate) {
|
|
1740
1754
|
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
@@ -1746,6 +1760,7 @@ class Interpreter {
|
|
|
1746
1760
|
prevSibling = _this$ctx2.prevSibling;
|
|
1747
1761
|
this.handleInsert(realParent, textNode, prevSibling);
|
|
1748
1762
|
}
|
|
1763
|
+
this.leaveNode?.(textNode, false);
|
|
1749
1764
|
}
|
|
1750
1765
|
}
|
|
1751
1766
|
isUpdate = true;
|
|
@@ -1776,7 +1791,7 @@ class Interpreter {
|
|
|
1776
1791
|
realBefore: null,
|
|
1777
1792
|
realAfter: null
|
|
1778
1793
|
};
|
|
1779
|
-
node.realAfter = this.
|
|
1794
|
+
node.realAfter = this.insertAnchor('context-after');
|
|
1780
1795
|
return node;
|
|
1781
1796
|
}
|
|
1782
1797
|
formatForCollection(collection) {
|
|
@@ -1874,7 +1889,7 @@ class Interpreter {
|
|
|
1874
1889
|
const hasArrExpKey = Reflect.has(data[aoye.Keys.Raw], arrExp);
|
|
1875
1890
|
const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new aoye.Computed(this.getFn(data, arrExp));
|
|
1876
1891
|
forNode.arrSignal = arrSignal;
|
|
1877
|
-
forNode.realAfter = this.
|
|
1892
|
+
forNode.realAfter = this.insertAnchor('for-after');
|
|
1878
1893
|
const _forNode$snapshot = forNode.snapshot;
|
|
1879
1894
|
_forNode$snapshot.dentStack;
|
|
1880
1895
|
_forNode$snapshot.isFirstToken;
|
|
@@ -1897,8 +1912,8 @@ class Interpreter {
|
|
|
1897
1912
|
const len = arr.length;
|
|
1898
1913
|
for (let i = len; i--;) {
|
|
1899
1914
|
const item = this.createForItem(forNode, i, data);
|
|
1900
|
-
item.realAfter = this.
|
|
1901
|
-
item.realBefore = this.
|
|
1915
|
+
item.realAfter = this.insertAnchor('for-item-after');
|
|
1916
|
+
item.realBefore = this.insertAnchor('for-item-before', true);
|
|
1902
1917
|
item.realParent = forNode.realParent;
|
|
1903
1918
|
children[i] = item;
|
|
1904
1919
|
}
|
|
@@ -2065,7 +2080,7 @@ class Interpreter {
|
|
|
2065
2080
|
newChildren[i] = item;
|
|
2066
2081
|
let realAfter = this.createAnchor('for-item-after');
|
|
2067
2082
|
this.handleInsert(forNode.realParent, realAfter, before);
|
|
2068
|
-
let realBefore = this.createAnchor('for-item-before');
|
|
2083
|
+
let realBefore = this.createAnchor('for-item-before', true);
|
|
2069
2084
|
this.handleInsert(forNode.realParent, realBefore, before);
|
|
2070
2085
|
item.realBefore = realBefore;
|
|
2071
2086
|
item.realAfter = realAfter;
|
|
@@ -2234,7 +2249,7 @@ class Interpreter {
|
|
|
2234
2249
|
resumeSnapshot
|
|
2235
2250
|
};
|
|
2236
2251
|
this.onePropParsed = onePropParsed;
|
|
2237
|
-
node.realAfter = this.
|
|
2252
|
+
node.realAfter = this.insertAnchor('component-after');
|
|
2238
2253
|
return node;
|
|
2239
2254
|
}
|
|
2240
2255
|
getFn(data, expression) {
|
|
@@ -2329,7 +2344,7 @@ class Interpreter {
|
|
|
2329
2344
|
break;
|
|
2330
2345
|
}
|
|
2331
2346
|
ifNode.condition = signal;
|
|
2332
|
-
ifNode.realAfter = this.
|
|
2347
|
+
ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
|
|
2333
2348
|
const ef = this.effect(({
|
|
2334
2349
|
val
|
|
2335
2350
|
}) => {
|
|
@@ -2413,7 +2428,51 @@ class Interpreter {
|
|
|
2413
2428
|
hookI = _this$tokenizer$_hook4[2];
|
|
2414
2429
|
const rawVal = data[aoye.Keys.Raw][value];
|
|
2415
2430
|
const isFn = typeof rawVal === 'function';
|
|
2416
|
-
if (key === '
|
|
2431
|
+
if (key === 'props') {
|
|
2432
|
+
let prevKeys = new Set();
|
|
2433
|
+
const savedDefaults = new Map();
|
|
2434
|
+
new this.Effect(() => {
|
|
2435
|
+
const props = isFn ? rawVal : Reflect.has(data[aoye.Keys.Raw], value) ? data[value] : this.getFn(data, value)();
|
|
2436
|
+
const isComponent = _node.__logicType & TokenizerSwitcherBit;
|
|
2437
|
+
const rawTarget = isComponent ? _node.data[aoye.Keys.Raw] : null;
|
|
2438
|
+
const cleanupKeys = keysToClean => {
|
|
2439
|
+
for (const k of keysToClean) {
|
|
2440
|
+
if (k.startsWith('on')) continue;
|
|
2441
|
+
if (isComponent) {
|
|
2442
|
+
_node.data[k] = savedDefaults.has(k) ? savedDefaults.get(k) : undefined;
|
|
2443
|
+
} else {
|
|
2444
|
+
this.setProp(_node, k, undefined, hookI);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
if (!props || typeof props !== 'object') {
|
|
2449
|
+
cleanupKeys(prevKeys);
|
|
2450
|
+
prevKeys.clear();
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2453
|
+
props[aoye.Keys.Iterator];
|
|
2454
|
+
const raw = props[aoye.Keys.Raw] || props;
|
|
2455
|
+
const keys = Object.keys(raw);
|
|
2456
|
+
const newKeys = new Set();
|
|
2457
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2458
|
+
const k = keys[i];
|
|
2459
|
+
newKeys.add(k);
|
|
2460
|
+
prevKeys.delete(k);
|
|
2461
|
+
if (isComponent) {
|
|
2462
|
+
const savedK = savedDefaults.has(k);
|
|
2463
|
+
if (!savedK && Object.prototype.hasOwnProperty.call(rawTarget, k)) {
|
|
2464
|
+
savedDefaults.set(k, rawTarget[k]);
|
|
2465
|
+
}
|
|
2466
|
+
const val = props[k];
|
|
2467
|
+
_node.data[k] = val === undefined && savedK ? savedDefaults.get(k) : val;
|
|
2468
|
+
} else {
|
|
2469
|
+
this.onePropParsed(props, _node, k, k, true, false, hookI);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
cleanupKeys(prevKeys);
|
|
2473
|
+
prevKeys = newKeys;
|
|
2474
|
+
}, aoye.ScheduleType.Render);
|
|
2475
|
+
} else if (key === 'ref') {
|
|
2417
2476
|
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2418
2477
|
let refValue = _node;
|
|
2419
2478
|
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
@@ -2470,10 +2529,11 @@ class Interpreter {
|
|
|
2470
2529
|
firstChild(node) {
|
|
2471
2530
|
return node.firstChild;
|
|
2472
2531
|
}
|
|
2473
|
-
createAnchor(name) {
|
|
2532
|
+
createAnchor(name, isBefore) {
|
|
2474
2533
|
return {
|
|
2475
2534
|
name,
|
|
2476
|
-
nextSibling: null
|
|
2535
|
+
nextSibling: null,
|
|
2536
|
+
isBefore
|
|
2477
2537
|
};
|
|
2478
2538
|
}
|
|
2479
2539
|
insertAfter(parent, node, prev) {
|
|
@@ -2559,6 +2619,7 @@ function customRender(option) {
|
|
|
2559
2619
|
tokenizer
|
|
2560
2620
|
};
|
|
2561
2621
|
terp.program(root, componentNode);
|
|
2622
|
+
option.onBeforeFlush?.();
|
|
2562
2623
|
aoye.flushMicroEffectManual();
|
|
2563
2624
|
return [componentNode, store];
|
|
2564
2625
|
};
|