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