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.
@@ -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["Logic"] = 1] = "Logic";
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";
@@ -1475,9 +1476,6 @@ class Interpreter {
1475
1476
  constructor(tokenizer) {
1476
1477
  this.tokenizer = tokenizer;
1477
1478
  }
1478
- isLogicNode(node) {
1479
- return node && node.__logicType & LogicalBit;
1480
- }
1481
1479
  rootComponent = null;
1482
1480
  program(root, componentNode, before, ctxProvider) {
1483
1481
  this.rootComponent = componentNode;
@@ -1496,7 +1494,7 @@ class Interpreter {
1496
1494
  stack.push({
1497
1495
  node: ctxProvider,
1498
1496
  prev: null
1499
- }, (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider);
1497
+ }, (ctxProvider.__logicType && ctxProvider.effect ? NodeSort.EffectNode : 0) | NodeSort.CtxProvider);
1500
1498
  }
1501
1499
  const rootLen = stack.length;
1502
1500
  const ctx = this.ctx = {
@@ -1519,18 +1517,22 @@ class Interpreter {
1519
1517
  const token = this.tokenizer.token;
1520
1518
  if (token.type & TokenType.Indent) {
1521
1519
  this.tokenizer.nextToken();
1522
- const isLogicNode = this.isLogicNode(ctx.current);
1520
+ const isEffectNode = ctx.current && ctx.current.__logicType && ctx.current.effect;
1523
1521
  stack.push({
1524
1522
  node: ctx.current,
1525
1523
  prev: ctx.prevSibling
1526
- }, !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));
1524
+ }, !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));
1527
1525
  if (ctx.current.__logicType) {
1528
1526
  this.beforeLogicIndent?.(ctx.current);
1529
- if (isLogicNode) {
1527
+ if (isEffectNode) {
1530
1528
  setPulling(ctx.current.effect);
1531
1529
  if (ctx.current.__logicType & FakeType.ForItem) {
1532
1530
  ctx.prevSibling = ctx.current.realBefore;
1533
1531
  }
1532
+ if (ctx.current.__logicType & FakeType.Tp) {
1533
+ ctx.realParent = ctx.current.tpData[Keys.Raw].node;
1534
+ ctx.prevSibling = ctx.current.contentBefore;
1535
+ }
1534
1536
  }
1535
1537
  } else {
1536
1538
  if (ctx.current) {
@@ -1566,14 +1568,17 @@ class Interpreter {
1566
1568
  const prevSameType = stack.peekByType(NodeSort.Real);
1567
1569
  ctx.realParent = prevSameType?.node || root;
1568
1570
  } else {
1569
- if (sort & NodeSort.Logic) {
1570
- const parentLogic = stack.peekByType(NodeSort.Logic)?.node;
1571
+ if (sort & NodeSort.EffectNode) {
1572
+ const parentLogic = stack.peekByType(NodeSort.EffectNode)?.node;
1571
1573
  if (parentLogic) {
1572
1574
  setPulling(parentLogic.effect);
1573
1575
  } else {
1574
1576
  setPulling(rootPulling);
1575
1577
  }
1576
1578
  }
1579
+ if (parent.__logicType === FakeType.Tp) {
1580
+ ctx.realParent = parent.realParent;
1581
+ }
1577
1582
  if (sort & NodeSort.TokenizerSwitcher) {
1578
1583
  const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1579
1584
  if (parent.resumeSnapshot) {
@@ -1610,13 +1615,17 @@ class Interpreter {
1610
1615
  }
1611
1616
  return componentNode;
1612
1617
  }
1613
- insertAnchor(name = 'anchor', isBefore = false) {
1618
+ insertAnchor(node, name = 'anchor', isBefore = false) {
1614
1619
  const _this$ctx = this.ctx,
1615
1620
  realParent = _this$ctx.realParent,
1616
1621
  prevSibling = _this$ctx.prevSibling,
1617
1622
  stack = _this$ctx.stack,
1618
1623
  before = _this$ctx.before;
1624
+ _this$ctx.current;
1619
1625
  const afterAnchor = this.createAnchor(name, isBefore);
1626
+ if (!isBefore) {
1627
+ this.anchorRefBack(afterAnchor, node);
1628
+ }
1620
1629
  this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
1621
1630
  this.handleInsert(realParent, afterAnchor, prevSibling);
1622
1631
  return afterAnchor;
@@ -1661,6 +1670,8 @@ class Interpreter {
1661
1670
  return this.condDeclaration(ctx);
1662
1671
  } else if (value === 'context') {
1663
1672
  _node = this.createContextNode();
1673
+ } else if (value === 'tp') {
1674
+ return this.createTpNode();
1664
1675
  } else if (value === 'for') {
1665
1676
  return this.forDeclaration();
1666
1677
  } else if (hookType) {
@@ -1704,7 +1715,7 @@ class Interpreter {
1704
1715
  parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
1705
1716
  };
1706
1717
  let isUpdate = false;
1707
- node.realAfter = this.insertAnchor(`dynamic-after`);
1718
+ node.realAfter = this.insertAnchor(node, `dynamic-after`);
1708
1719
  node.effect = this.effect(({
1709
1720
  old,
1710
1721
  val
@@ -1784,6 +1795,93 @@ class Interpreter {
1784
1795
  });
1785
1796
  return node;
1786
1797
  }
1798
+ createTpNode() {
1799
+ const child = deepSignal({}, getPulling());
1800
+ const node = {
1801
+ __logicType: FakeType.Tp,
1802
+ data: this.getData(),
1803
+ realParent: null,
1804
+ realBefore: null,
1805
+ realAfter: null,
1806
+ contentBefore: null,
1807
+ contentAfter: null,
1808
+ effect: null,
1809
+ snapshot: null,
1810
+ tpData: child,
1811
+ owner: this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node
1812
+ };
1813
+ this.onePropParsed = createStoreOnePropParsed(child);
1814
+ this.tokenizer.nextToken();
1815
+ this.headerLineAndExtensions(node);
1816
+ this.onePropParsed = this.oneRealPropParsed;
1817
+ node.realAfter = this.insertAnchor(node, 'tp-after');
1818
+ const before = node.contentBefore = this.createAnchor('tp-content-before', true);
1819
+ const after = node.contentAfter = this.createAnchor('tp-content-after', true);
1820
+ let firstRender = true;
1821
+ node.effect = this.effect(({
1822
+ old: oldDom,
1823
+ val: dom
1824
+ }) => {
1825
+ const removeTpChild = () => {
1826
+ if (oldDom) {
1827
+ let point = before;
1828
+ do {
1829
+ const next = this.nextSib(point);
1830
+ this.remove(point, oldDom, null);
1831
+ if (point === after) break;
1832
+ point = next;
1833
+ } while (true);
1834
+ }
1835
+ };
1836
+ if (firstRender) {
1837
+ if (dom) {
1838
+ this.handleInsert(dom, after, null);
1839
+ this.handleInsert(dom, before, null);
1840
+ } else {
1841
+ if (this.tokenizer.token.type === TokenType.Indent) {
1842
+ const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 2] ?? 0;
1843
+ this.tokenizer.skip(dentLen);
1844
+ }
1845
+ }
1846
+ } else {
1847
+ if (dom) {
1848
+ if (oldDom) {
1849
+ let point = before,
1850
+ lastInsert = null;
1851
+ do {
1852
+ const next = this.nextSib(point);
1853
+ const fakeNode = point[FakeNode];
1854
+ if (fakeNode) {
1855
+ fakeNode.realParent = dom;
1856
+ }
1857
+ this.handleInsert(dom, point, lastInsert);
1858
+ if (point === after) break;
1859
+ lastInsert = point;
1860
+ point = next;
1861
+ } while (true);
1862
+ } else {
1863
+ this.handleInsert(dom, after, null);
1864
+ this.handleInsert(dom, before, null);
1865
+ this.tokenizer = node.owner.tokenizer;
1866
+ this.tokenizer.resume(node.snapshot);
1867
+ this.tokenizer.useDedentAsEof = false;
1868
+ this.program(dom, node.owner, before, node);
1869
+ }
1870
+ } else {
1871
+ removeTpChild();
1872
+ }
1873
+ }
1874
+ firstRender = false;
1875
+ return isDestroy => {
1876
+ if (isDestroy) {
1877
+ removeTpChild();
1878
+ }
1879
+ };
1880
+ }, [() => child.node], {
1881
+ type: 'render'
1882
+ });
1883
+ return node;
1884
+ }
1787
1885
  createContextNode() {
1788
1886
  const child = deepSignal({}, getPulling());
1789
1887
  const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
@@ -1798,7 +1896,7 @@ class Interpreter {
1798
1896
  realBefore: null,
1799
1897
  realAfter: null
1800
1898
  };
1801
- node.realAfter = this.insertAnchor('context-after');
1899
+ node.realAfter = this.insertAnchor(node, 'context-after');
1802
1900
  return node;
1803
1901
  }
1804
1902
  formatForCollection(collection) {
@@ -1891,13 +1989,12 @@ class Interpreter {
1891
1989
  const rawGetKey = new Function('data', `with(data){return (${keyExp})}`);
1892
1990
  forNode.getKey = data => rawGetKey(safe(data));
1893
1991
  }
1894
- window['for1'] = forNode;
1895
1992
  const data = this.getData();
1896
1993
  const cells = data[Keys.Meta].cells;
1897
1994
  const hasArrExpKey = Reflect.has(data[Keys.Raw], arrExp);
1898
1995
  const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new Computed(this.getFn(data, arrExp));
1899
1996
  forNode.arrSignal = arrSignal;
1900
- forNode.realAfter = this.insertAnchor('for-after');
1997
+ forNode.realAfter = this.insertAnchor(forNode, 'for-after');
1901
1998
  const _forNode$snapshot = forNode.snapshot;
1902
1999
  _forNode$snapshot.dentStack;
1903
2000
  _forNode$snapshot.isFirstToken;
@@ -1920,8 +2017,8 @@ class Interpreter {
1920
2017
  const len = arr.length;
1921
2018
  for (let i = len; i--;) {
1922
2019
  const item = this.createForItem(forNode, i, data);
1923
- item.realAfter = this.insertAnchor('for-item-after');
1924
- item.realBefore = this.insertAnchor('for-item-before', true);
2020
+ item.realAfter = this.insertAnchor(item, 'for-item-after');
2021
+ item.realBefore = this.insertAnchor(item, 'for-item-before', true);
1925
2022
  item.realParent = forNode.realParent;
1926
2023
  children[i] = item;
1927
2024
  }
@@ -2083,10 +2180,14 @@ class Interpreter {
2083
2180
  }, ScheduleType.Render);
2084
2181
  return forNode.children[0] || forNode;
2085
2182
  }
2183
+ anchorRefBack(anchor, node) {
2184
+ anchor[FakeNode] = node;
2185
+ }
2086
2186
  insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
2087
2187
  const item = this.createForItem(forNode, i, parentData);
2088
2188
  newChildren[i] = item;
2089
2189
  let realAfter = this.createAnchor('for-item-after');
2190
+ this.anchorRefBack(realAfter, item);
2090
2191
  this.handleInsert(forNode.realParent, realAfter, before);
2091
2192
  let realBefore = this.createAnchor('for-item-before', true);
2092
2193
  this.handleInsert(forNode.realParent, realBefore, before);
@@ -2257,7 +2358,7 @@ class Interpreter {
2257
2358
  resumeSnapshot
2258
2359
  };
2259
2360
  this.onePropParsed = onePropParsed;
2260
- node.realAfter = this.insertAnchor('component-after');
2361
+ node.realAfter = this.insertAnchor(node, 'component-after');
2261
2362
  return node;
2262
2363
  }
2263
2364
  getFn(data, expression) {
@@ -2352,7 +2453,7 @@ class Interpreter {
2352
2453
  break;
2353
2454
  }
2354
2455
  ifNode.condition = signal;
2355
- ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
2456
+ ifNode.realAfter = this.insertAnchor(ifNode, `${keyWord.value}-after`);
2356
2457
  const ef = this.effect(({
2357
2458
  val
2358
2459
  }) => {
@@ -2395,10 +2496,11 @@ class Interpreter {
2395
2496
  const tokenizer = this.tokenizer;
2396
2497
  do {
2397
2498
  const isComponent = _node.__logicType & TokenizerSwitcherBit;
2499
+ const isTp = _node.__logicType === FakeType.Tp;
2398
2500
  let snapshot, dentLen;
2399
2501
  const data = this.getData();
2400
2502
  const unHandledKey = this.attributeList(_node, data);
2401
- if (isComponent) {
2503
+ if (isComponent || isTp) {
2402
2504
  snapshot = tokenizer.snapshot(undefined, -1);
2403
2505
  dentLen = tokenizer.dentStack[tokenizer.dentStack.length - 1];
2404
2506
  }
@@ -2410,6 +2512,9 @@ class Interpreter {
2410
2512
  if ((tokenizer.token.type & TokenType.Pipe) === 0) {
2411
2513
  break;
2412
2514
  }
2515
+ } else if (isTp) {
2516
+ _node.snapshot = snapshot;
2517
+ break;
2413
2518
  } else {
2414
2519
  break;
2415
2520
  }