bobe 0.0.54 → 0.0.57

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,11 +33,12 @@ let FakeType = function (FakeType) {
33
33
  FakeType[FakeType["Fragment"] = 32] = "Fragment";
34
34
  FakeType[FakeType["ForItem"] = 64] = "ForItem";
35
35
  FakeType[FakeType["Context"] = 128] = "Context";
36
+ FakeType[FakeType["DynamicText"] = 256] = "DynamicText";
36
37
  return FakeType;
37
38
  }({});
38
39
  const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
39
40
  const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
40
- FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment;
41
+ const CtxProviderBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment | FakeType.DynamicText;
41
42
  const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context;
42
43
  const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
43
44
  let NodeSort = function (NodeSort) {
@@ -252,6 +253,7 @@ class Tokenizer {
252
253
  }
253
254
  isEof() {
254
255
  if (!this.token) return false;
256
+ if (this.i >= this.code.length && !this.waitingTokens.len) return true;
255
257
  return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
256
258
  }
257
259
  setToken(type, value, dt = 1) {
@@ -1444,6 +1446,17 @@ function macInc(arr) {
1444
1446
  }
1445
1447
  return candyLast;
1446
1448
  }
1449
+ class InlineFragment {
1450
+ [aoye.Keys.ProxyFreeObject] = true;
1451
+ constructor(snapshot, data, key, tokenizer) {
1452
+ this.snapshot = snapshot;
1453
+ this.data = data;
1454
+ this.key = key;
1455
+ this.tokenizer = tokenizer;
1456
+ }
1457
+ }
1458
+ const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
1459
+ const isRenderAble = val => aoye.isStore(val) || isUI(val) || val instanceof InlineFragment;
1447
1460
 
1448
1461
  const KEY_INDEX = '__BOBE_KEY_INDEX';
1449
1462
  let _ctxStack;
@@ -1500,7 +1513,7 @@ class Interpreter {
1500
1513
  stack.push({
1501
1514
  node: ctx.current,
1502
1515
  prev: ctx.prevSibling
1503
- }, !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 !== FakeType.Context ? NodeSort.CtxProvider : 0));
1516
+ }, !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));
1504
1517
  if (ctx.current.__logicType) {
1505
1518
  if (isLogicNode) {
1506
1519
  aoye.setPulling(ctx.current.effect);
@@ -1634,21 +1647,14 @@ class Interpreter {
1634
1647
  } else if (hookType) {
1635
1648
  const data = this.getData();
1636
1649
  if (hookType === 'static') {
1637
- if (typeof value === 'function') {
1650
+ if (isRenderAble(value)) {
1638
1651
  _node = this.componentOrFragmentDeclaration(value, ctx);
1639
1652
  } else {
1640
- throw new SyntaxError(`declaration 不支持 ${value} 类型的静态插值`);
1641
- }
1642
- } else {
1643
- const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
1644
- const val = data[aoye.Keys.Raw][value];
1645
- if (typeof val === 'function' || val instanceof InlineFragment) {
1646
- _node = this.componentOrFragmentDeclaration(val, ctx);
1647
- } else {
1648
- const str = valueIsMapKey ? value : this.getFn(data, value);
1649
1653
  _node = this.createNode('text');
1650
- this.onePropParsed(data, _node, 'text', str, valueIsMapKey, false);
1654
+ _node.text = String(value);
1651
1655
  }
1656
+ } else {
1657
+ return this.dynamicDeclaration(data, value, ctx);
1652
1658
  }
1653
1659
  } else {
1654
1660
  _node = this.createNode(value);
@@ -1666,6 +1672,96 @@ class Interpreter {
1666
1672
  }
1667
1673
  return _node;
1668
1674
  }
1675
+ dynamicDeclaration(pData, value, ctx) {
1676
+ const valueIsMapKey = Reflect.has(pData[aoye.Keys.Raw], value);
1677
+ let node = {
1678
+ __logicType: null,
1679
+ realParent: null,
1680
+ tokenizer: null,
1681
+ effect: null,
1682
+ textNode: null,
1683
+ owner: ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node,
1684
+ snapshot: this.tokenizer.snapshot(['dentStack']),
1685
+ parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
1686
+ };
1687
+ let isUpdate = false;
1688
+ node.realAfter = this.insertAfterAnchor(`dynamic-after`);
1689
+ node.effect = this.effect(({
1690
+ old,
1691
+ val
1692
+ }) => {
1693
+ let oldLogicType = node.__logicType,
1694
+ oldTextNode = node.textNode;
1695
+ if (oldLogicType) {
1696
+ this.removeLogicNode(node);
1697
+ bobeShared.pickInPlace(node, ['realParent', 'realBefore', 'realAfter',, 'owner', 'snapshot', 'parentDataProvider']);
1698
+ }
1699
+ if (isRenderAble(val)) {
1700
+ if (oldTextNode) {
1701
+ this.remove(oldTextNode);
1702
+ }
1703
+ const info = this.createComponentData(val);
1704
+ info.__logicType;
1705
+ Object.assign(node, info);
1706
+ this.onePropParsed = info.onePropParsed;
1707
+ if (isUpdate) {
1708
+ this.tokenizer = node.owner.tokenizer;
1709
+ this.tokenizer.resume(node.snapshot);
1710
+ this.ctx.stack.push({
1711
+ node: node.parentDataProvider,
1712
+ prev: null
1713
+ }, NodeSort.CtxProvider);
1714
+ }
1715
+ this.tokenizer.nextToken();
1716
+ this.headerLineAndExtensions(node);
1717
+ if (isUpdate) {
1718
+ this.ctx.stack.pop();
1719
+ }
1720
+ this.onePropParsed = this.oneRealPropParsed;
1721
+ this.tokenizer = node.tokenizer;
1722
+ if (node.fragmentSnapshot) {
1723
+ this.tokenizer.resume(node.fragmentSnapshot);
1724
+ this.tokenizer.useDedentAsEof = true;
1725
+ this.tokenizer.initIndentWhenUseDedentAsEof();
1726
+ }
1727
+ if (isUpdate) {
1728
+ this.program(node.realParent, node.owner, node.realBefore, node);
1729
+ }
1730
+ } else {
1731
+ node.__logicType = FakeType.DynamicText;
1732
+ let textNode = oldTextNode;
1733
+ const isNewTextNode = !textNode;
1734
+ if (isNewTextNode) {
1735
+ textNode = node.textNode = this.createNode('text');
1736
+ }
1737
+ textNode.text = String(val);
1738
+ if (isNewTextNode) {
1739
+ if (isUpdate) {
1740
+ this.handleInsert(node.realParent, textNode, node.realBefore);
1741
+ } else {
1742
+ this.tokenizer.nextToken();
1743
+ this.headerLineAndExtensions(node);
1744
+ const _this$ctx2 = this.ctx,
1745
+ realParent = _this$ctx2.realParent,
1746
+ prevSibling = _this$ctx2.prevSibling;
1747
+ this.handleInsert(realParent, textNode, prevSibling);
1748
+ }
1749
+ }
1750
+ }
1751
+ isUpdate = true;
1752
+ return isDestroy => {
1753
+ if (isDestroy) {
1754
+ this.removeLogicNode(node);
1755
+ }
1756
+ };
1757
+ }, [() => {
1758
+ const val = valueIsMapKey ? pData[value] : this.getFn(pData, value)();
1759
+ return val;
1760
+ }], {
1761
+ type: 'render'
1762
+ });
1763
+ return node;
1764
+ }
1669
1765
  createContextNode() {
1670
1766
  const child = aoye.deepSignal({}, aoye.getPulling());
1671
1767
  const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
@@ -2084,20 +2180,22 @@ class Interpreter {
2084
2180
  }
2085
2181
  }
2086
2182
  oneRealPropParsed = this.onePropParsed.bind(this);
2087
- componentOrFragmentDeclaration(ComponentOrRender, ctx) {
2088
- let Component, tokenizer, child, fragmentSnapshot, resumeSnapshot;
2183
+ createComponentData(ComponentOrRender) {
2184
+ let tokenizer, child, fragmentSnapshot, resumeSnapshot, __logicType;
2089
2185
  const isCC = ComponentOrRender.prototype instanceof aoye.Store;
2090
2186
  if (isCC) {
2091
- Component = ComponentOrRender;
2187
+ const Component = ComponentOrRender;
2092
2188
  child = Component.new();
2093
2189
  tokenizer = child.ui(true);
2190
+ __logicType = FakeType.Component;
2094
2191
  } else if (ComponentOrRender instanceof InlineFragment) {
2095
2192
  const conf = ComponentOrRender;
2096
2193
  child = aoye.deepSignal({}, aoye.getPulling(), true);
2097
2194
  Object.setPrototypeOf(child, conf.data);
2098
2195
  tokenizer = conf.tokenizer;
2099
2196
  fragmentSnapshot = conf.snapshot;
2100
- resumeSnapshot = tokenizer.snapshot(['token', 'needIndent', 'isFirstToken', 'dentStack', 'isFirstToken', 'useDedentAsEof']);
2197
+ __logicType = FakeType.Fragment;
2198
+ resumeSnapshot = tokenizer.snapshot(['dentStack', 'token', 'needIndent', 'isFirstToken', 'isFirstToken', 'useDedentAsEof']);
2101
2199
  } else {
2102
2200
  const render = ComponentOrRender;
2103
2201
  const boundStore = render.boundStore;
@@ -2106,18 +2204,36 @@ class Interpreter {
2106
2204
  Object.setPrototypeOf(child, boundStore);
2107
2205
  }
2108
2206
  tokenizer = render(true);
2207
+ __logicType = FakeType.Fragment;
2109
2208
  }
2209
+ return {
2210
+ data: child,
2211
+ tokenizer,
2212
+ onePropParsed: createStoreOnePropParsed(child),
2213
+ fragmentSnapshot,
2214
+ resumeSnapshot,
2215
+ __logicType
2216
+ };
2217
+ }
2218
+ componentOrFragmentDeclaration(ComponentOrRender, ctx) {
2219
+ const _this$createComponent = this.createComponentData(ComponentOrRender),
2220
+ data = _this$createComponent.data,
2221
+ tokenizer = _this$createComponent.tokenizer,
2222
+ onePropParsed = _this$createComponent.onePropParsed,
2223
+ fragmentSnapshot = _this$createComponent.fragmentSnapshot,
2224
+ resumeSnapshot = _this$createComponent.resumeSnapshot,
2225
+ __logicType = _this$createComponent.__logicType;
2110
2226
  const node = {
2111
- __logicType: isCC ? FakeType.Component : FakeType.Fragment,
2227
+ __logicType,
2112
2228
  realParent: ctx.realParent,
2113
2229
  realBefore: null,
2114
2230
  realAfter: null,
2115
- data: child,
2231
+ data,
2116
2232
  tokenizer,
2117
2233
  fragmentSnapshot,
2118
2234
  resumeSnapshot
2119
2235
  };
2120
- this.onePropParsed = createStoreOnePropParsed(child);
2236
+ this.onePropParsed = onePropParsed;
2121
2237
  node.realAfter = this.insertAfterAnchor('component-after');
2122
2238
  return node;
2123
2239
  }
@@ -2300,7 +2416,7 @@ class Interpreter {
2300
2416
  if (key === 'ref') {
2301
2417
  const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
2302
2418
  let refValue = _node;
2303
- if (_node.__logicType === FakeType.Component) {
2419
+ if (_node.__logicType & TokenizerSwitcherBit) {
2304
2420
  refValue = _node.data;
2305
2421
  } else {
2306
2422
  refValue[aoye.Keys.ProxyFreeObject] = true;
@@ -2326,8 +2442,8 @@ class Interpreter {
2326
2442
  } else {
2327
2443
  this.onePropParsed(data, _node, key, value, false, isFn, hookI);
2328
2444
  }
2329
- key = null;
2330
- eq = null;
2445
+ key = undefined;
2446
+ eq = undefined;
2331
2447
  }
2332
2448
  this.tokenizer.nextToken();
2333
2449
  }
@@ -2415,15 +2531,6 @@ function createStoreOnePropParsed(child) {
2415
2531
  };
2416
2532
  return onePropParsed;
2417
2533
  }
2418
- class InlineFragment {
2419
- [aoye.Keys.ProxyFreeObject] = true;
2420
- constructor(snapshot, data, key, tokenizer) {
2421
- this.snapshot = snapshot;
2422
- this.data = data;
2423
- this.key = key;
2424
- this.tokenizer = tokenizer;
2425
- }
2426
- }
2427
2534
 
2428
2535
  function bobe(fragments, ...values) {
2429
2536
  const ui = function ui(isSub) {
@@ -2436,6 +2543,7 @@ function bobe(fragments, ...values) {
2436
2543
  return tokenizer;
2437
2544
  };
2438
2545
  ui.boundStore = aoye.Store.Current;
2546
+ ui.__BOBE_IS_UI = true;
2439
2547
  return ui;
2440
2548
  }
2441
2549
  function customRender(option) {
@@ -2451,6 +2559,7 @@ function customRender(option) {
2451
2559
  tokenizer
2452
2560
  };
2453
2561
  terp.program(root, componentNode);
2562
+ aoye.flushMicroEffectManual();
2454
2563
  return [componentNode, store];
2455
2564
  };
2456
2565
  }
@@ -2499,6 +2608,7 @@ Object.defineProperty(exports, "Store", {
2499
2608
  get: function () { return aoye.Store; }
2500
2609
  });
2501
2610
  exports.Compiler = Compiler;
2611
+ exports.FakeType = FakeType;
2502
2612
  exports.NodeType = NodeType;
2503
2613
  exports.ParseSyntaxError = ParseSyntaxError;
2504
2614
  exports.Tokenizer = Tokenizer;