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.
- package/dist/bobe.cjs.js +142 -32
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +142 -32
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +144 -35
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +144 -35
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +35 -25
- package/dist/index.umd.js +142 -32
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.cjs.js
CHANGED
|
@@ -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) {
|
|
@@ -243,6 +244,7 @@ class Tokenizer {
|
|
|
243
244
|
}
|
|
244
245
|
isEof() {
|
|
245
246
|
if (!this.token) return false;
|
|
247
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
246
248
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
247
249
|
}
|
|
248
250
|
setToken(type, value, dt = 1) {
|
|
@@ -1417,6 +1419,17 @@ function macInc(arr) {
|
|
|
1417
1419
|
}
|
|
1418
1420
|
return candyLast;
|
|
1419
1421
|
}
|
|
1422
|
+
class InlineFragment {
|
|
1423
|
+
[aoye.Keys.ProxyFreeObject] = true;
|
|
1424
|
+
constructor(snapshot, data, key, tokenizer) {
|
|
1425
|
+
this.snapshot = snapshot;
|
|
1426
|
+
this.data = data;
|
|
1427
|
+
this.key = key;
|
|
1428
|
+
this.tokenizer = tokenizer;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
|
|
1432
|
+
const isRenderAble = val => aoye.isStore(val) || isUI(val) || val instanceof InlineFragment;
|
|
1420
1433
|
|
|
1421
1434
|
const KEY_INDEX = '__BOBE_KEY_INDEX';
|
|
1422
1435
|
let _ctxStack;
|
|
@@ -1473,7 +1486,7 @@ class Interpreter {
|
|
|
1473
1486
|
stack.push({
|
|
1474
1487
|
node: ctx.current,
|
|
1475
1488
|
prev: ctx.prevSibling
|
|
1476
|
-
}, !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
|
|
1489
|
+
}, !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));
|
|
1477
1490
|
if (ctx.current.__logicType) {
|
|
1478
1491
|
if (isLogicNode) {
|
|
1479
1492
|
aoye.setPulling(ctx.current.effect);
|
|
@@ -1607,21 +1620,14 @@ class Interpreter {
|
|
|
1607
1620
|
} else if (hookType) {
|
|
1608
1621
|
const data = this.getData();
|
|
1609
1622
|
if (hookType === 'static') {
|
|
1610
|
-
if (
|
|
1623
|
+
if (isRenderAble(value)) {
|
|
1611
1624
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1612
1625
|
} else {
|
|
1613
|
-
throw new SyntaxError(`declaration 不支持 ${value} 类型的静态插值`);
|
|
1614
|
-
}
|
|
1615
|
-
} else {
|
|
1616
|
-
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
1617
|
-
const val = data[aoye.Keys.Raw][value];
|
|
1618
|
-
if (typeof val === 'function' || val instanceof InlineFragment) {
|
|
1619
|
-
_node = this.componentOrFragmentDeclaration(val, ctx);
|
|
1620
|
-
} else {
|
|
1621
|
-
const str = valueIsMapKey ? value : this.getFn(data, value);
|
|
1622
1626
|
_node = this.createNode('text');
|
|
1623
|
-
|
|
1627
|
+
_node.text = String(value);
|
|
1624
1628
|
}
|
|
1629
|
+
} else {
|
|
1630
|
+
return this.dynamicDeclaration(data, value, ctx);
|
|
1625
1631
|
}
|
|
1626
1632
|
} else {
|
|
1627
1633
|
_node = this.createNode(value);
|
|
@@ -1639,6 +1645,96 @@ class Interpreter {
|
|
|
1639
1645
|
}
|
|
1640
1646
|
return _node;
|
|
1641
1647
|
}
|
|
1648
|
+
dynamicDeclaration(pData, value, ctx) {
|
|
1649
|
+
const valueIsMapKey = Reflect.has(pData[aoye.Keys.Raw], value);
|
|
1650
|
+
let node = {
|
|
1651
|
+
__logicType: null,
|
|
1652
|
+
realParent: null,
|
|
1653
|
+
tokenizer: null,
|
|
1654
|
+
effect: null,
|
|
1655
|
+
textNode: null,
|
|
1656
|
+
owner: ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node,
|
|
1657
|
+
snapshot: this.tokenizer.snapshot(['dentStack']),
|
|
1658
|
+
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1659
|
+
};
|
|
1660
|
+
let isUpdate = false;
|
|
1661
|
+
node.realAfter = this.insertAfterAnchor(`dynamic-after`);
|
|
1662
|
+
node.effect = this.effect(({
|
|
1663
|
+
old,
|
|
1664
|
+
val
|
|
1665
|
+
}) => {
|
|
1666
|
+
let oldLogicType = node.__logicType,
|
|
1667
|
+
oldTextNode = node.textNode;
|
|
1668
|
+
if (oldLogicType) {
|
|
1669
|
+
this.removeLogicNode(node);
|
|
1670
|
+
bobeShared.pickInPlace(node, ['realParent', 'realBefore', 'realAfter',, 'owner', 'snapshot', 'parentDataProvider']);
|
|
1671
|
+
}
|
|
1672
|
+
if (isRenderAble(val)) {
|
|
1673
|
+
if (oldTextNode) {
|
|
1674
|
+
this.remove(oldTextNode);
|
|
1675
|
+
}
|
|
1676
|
+
const info = this.createComponentData(val);
|
|
1677
|
+
info.__logicType;
|
|
1678
|
+
Object.assign(node, info);
|
|
1679
|
+
this.onePropParsed = info.onePropParsed;
|
|
1680
|
+
if (isUpdate) {
|
|
1681
|
+
this.tokenizer = node.owner.tokenizer;
|
|
1682
|
+
this.tokenizer.resume(node.snapshot);
|
|
1683
|
+
this.ctx.stack.push({
|
|
1684
|
+
node: node.parentDataProvider,
|
|
1685
|
+
prev: null
|
|
1686
|
+
}, NodeSort.CtxProvider);
|
|
1687
|
+
}
|
|
1688
|
+
this.tokenizer.nextToken();
|
|
1689
|
+
this.headerLineAndExtensions(node);
|
|
1690
|
+
if (isUpdate) {
|
|
1691
|
+
this.ctx.stack.pop();
|
|
1692
|
+
}
|
|
1693
|
+
this.onePropParsed = this.oneRealPropParsed;
|
|
1694
|
+
this.tokenizer = node.tokenizer;
|
|
1695
|
+
if (node.fragmentSnapshot) {
|
|
1696
|
+
this.tokenizer.resume(node.fragmentSnapshot);
|
|
1697
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1698
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1699
|
+
}
|
|
1700
|
+
if (isUpdate) {
|
|
1701
|
+
this.program(node.realParent, node.owner, node.realBefore, node);
|
|
1702
|
+
}
|
|
1703
|
+
} else {
|
|
1704
|
+
node.__logicType = FakeType.DynamicText;
|
|
1705
|
+
let textNode = oldTextNode;
|
|
1706
|
+
const isNewTextNode = !textNode;
|
|
1707
|
+
if (isNewTextNode) {
|
|
1708
|
+
textNode = node.textNode = this.createNode('text');
|
|
1709
|
+
}
|
|
1710
|
+
textNode.text = String(val);
|
|
1711
|
+
if (isNewTextNode) {
|
|
1712
|
+
if (isUpdate) {
|
|
1713
|
+
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
1714
|
+
} else {
|
|
1715
|
+
this.tokenizer.nextToken();
|
|
1716
|
+
this.headerLineAndExtensions(node);
|
|
1717
|
+
const _this$ctx2 = this.ctx,
|
|
1718
|
+
realParent = _this$ctx2.realParent,
|
|
1719
|
+
prevSibling = _this$ctx2.prevSibling;
|
|
1720
|
+
this.handleInsert(realParent, textNode, prevSibling);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
isUpdate = true;
|
|
1725
|
+
return isDestroy => {
|
|
1726
|
+
if (isDestroy) {
|
|
1727
|
+
this.removeLogicNode(node);
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
}, [() => {
|
|
1731
|
+
const val = valueIsMapKey ? pData[value] : this.getFn(pData, value)();
|
|
1732
|
+
return val;
|
|
1733
|
+
}], {
|
|
1734
|
+
type: 'render'
|
|
1735
|
+
});
|
|
1736
|
+
return node;
|
|
1737
|
+
}
|
|
1642
1738
|
createContextNode() {
|
|
1643
1739
|
const child = aoye.deepSignal({}, aoye.getPulling());
|
|
1644
1740
|
const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
|
|
@@ -2057,20 +2153,22 @@ class Interpreter {
|
|
|
2057
2153
|
}
|
|
2058
2154
|
}
|
|
2059
2155
|
oneRealPropParsed = this.onePropParsed.bind(this);
|
|
2060
|
-
|
|
2061
|
-
let
|
|
2156
|
+
createComponentData(ComponentOrRender) {
|
|
2157
|
+
let tokenizer, child, fragmentSnapshot, resumeSnapshot, __logicType;
|
|
2062
2158
|
const isCC = ComponentOrRender.prototype instanceof aoye.Store;
|
|
2063
2159
|
if (isCC) {
|
|
2064
|
-
Component = ComponentOrRender;
|
|
2160
|
+
const Component = ComponentOrRender;
|
|
2065
2161
|
child = Component.new();
|
|
2066
2162
|
tokenizer = child.ui(true);
|
|
2163
|
+
__logicType = FakeType.Component;
|
|
2067
2164
|
} else if (ComponentOrRender instanceof InlineFragment) {
|
|
2068
2165
|
const conf = ComponentOrRender;
|
|
2069
2166
|
child = aoye.deepSignal({}, aoye.getPulling(), true);
|
|
2070
2167
|
Object.setPrototypeOf(child, conf.data);
|
|
2071
2168
|
tokenizer = conf.tokenizer;
|
|
2072
2169
|
fragmentSnapshot = conf.snapshot;
|
|
2073
|
-
|
|
2170
|
+
__logicType = FakeType.Fragment;
|
|
2171
|
+
resumeSnapshot = tokenizer.snapshot(['dentStack', 'token', 'needIndent', 'isFirstToken', 'isFirstToken', 'useDedentAsEof']);
|
|
2074
2172
|
} else {
|
|
2075
2173
|
const render = ComponentOrRender;
|
|
2076
2174
|
const boundStore = render.boundStore;
|
|
@@ -2079,18 +2177,36 @@ class Interpreter {
|
|
|
2079
2177
|
Object.setPrototypeOf(child, boundStore);
|
|
2080
2178
|
}
|
|
2081
2179
|
tokenizer = render(true);
|
|
2180
|
+
__logicType = FakeType.Fragment;
|
|
2082
2181
|
}
|
|
2182
|
+
return {
|
|
2183
|
+
data: child,
|
|
2184
|
+
tokenizer,
|
|
2185
|
+
onePropParsed: createStoreOnePropParsed(child),
|
|
2186
|
+
fragmentSnapshot,
|
|
2187
|
+
resumeSnapshot,
|
|
2188
|
+
__logicType
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
componentOrFragmentDeclaration(ComponentOrRender, ctx) {
|
|
2192
|
+
const _this$createComponent = this.createComponentData(ComponentOrRender),
|
|
2193
|
+
data = _this$createComponent.data,
|
|
2194
|
+
tokenizer = _this$createComponent.tokenizer,
|
|
2195
|
+
onePropParsed = _this$createComponent.onePropParsed,
|
|
2196
|
+
fragmentSnapshot = _this$createComponent.fragmentSnapshot,
|
|
2197
|
+
resumeSnapshot = _this$createComponent.resumeSnapshot,
|
|
2198
|
+
__logicType = _this$createComponent.__logicType;
|
|
2083
2199
|
const node = {
|
|
2084
|
-
__logicType
|
|
2200
|
+
__logicType,
|
|
2085
2201
|
realParent: ctx.realParent,
|
|
2086
2202
|
realBefore: null,
|
|
2087
2203
|
realAfter: null,
|
|
2088
|
-
data
|
|
2204
|
+
data,
|
|
2089
2205
|
tokenizer,
|
|
2090
2206
|
fragmentSnapshot,
|
|
2091
2207
|
resumeSnapshot
|
|
2092
2208
|
};
|
|
2093
|
-
this.onePropParsed =
|
|
2209
|
+
this.onePropParsed = onePropParsed;
|
|
2094
2210
|
node.realAfter = this.insertAfterAnchor('component-after');
|
|
2095
2211
|
return node;
|
|
2096
2212
|
}
|
|
@@ -2273,7 +2389,7 @@ class Interpreter {
|
|
|
2273
2389
|
if (key === 'ref') {
|
|
2274
2390
|
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2275
2391
|
let refValue = _node;
|
|
2276
|
-
if (_node.__logicType
|
|
2392
|
+
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
2277
2393
|
refValue = _node.data;
|
|
2278
2394
|
} else {
|
|
2279
2395
|
refValue[aoye.Keys.ProxyFreeObject] = true;
|
|
@@ -2299,8 +2415,8 @@ class Interpreter {
|
|
|
2299
2415
|
} else {
|
|
2300
2416
|
this.onePropParsed(data, _node, key, value, false, isFn, hookI);
|
|
2301
2417
|
}
|
|
2302
|
-
key =
|
|
2303
|
-
eq =
|
|
2418
|
+
key = undefined;
|
|
2419
|
+
eq = undefined;
|
|
2304
2420
|
}
|
|
2305
2421
|
this.tokenizer.nextToken();
|
|
2306
2422
|
}
|
|
@@ -2388,15 +2504,6 @@ function createStoreOnePropParsed(child) {
|
|
|
2388
2504
|
};
|
|
2389
2505
|
return onePropParsed;
|
|
2390
2506
|
}
|
|
2391
|
-
class InlineFragment {
|
|
2392
|
-
[aoye.Keys.ProxyFreeObject] = true;
|
|
2393
|
-
constructor(snapshot, data, key, tokenizer) {
|
|
2394
|
-
this.snapshot = snapshot;
|
|
2395
|
-
this.data = data;
|
|
2396
|
-
this.key = key;
|
|
2397
|
-
this.tokenizer = tokenizer;
|
|
2398
|
-
}
|
|
2399
|
-
}
|
|
2400
2507
|
|
|
2401
2508
|
function bobe(fragments, ...values) {
|
|
2402
2509
|
const ui = function ui(isSub) {
|
|
@@ -2409,6 +2516,7 @@ function bobe(fragments, ...values) {
|
|
|
2409
2516
|
return tokenizer;
|
|
2410
2517
|
};
|
|
2411
2518
|
ui.boundStore = aoye.Store.Current;
|
|
2519
|
+
ui.__BOBE_IS_UI = true;
|
|
2412
2520
|
return ui;
|
|
2413
2521
|
}
|
|
2414
2522
|
function customRender(option) {
|
|
@@ -2424,6 +2532,7 @@ function customRender(option) {
|
|
|
2424
2532
|
tokenizer
|
|
2425
2533
|
};
|
|
2426
2534
|
terp.program(root, componentNode);
|
|
2535
|
+
aoye.flushMicroEffectManual();
|
|
2427
2536
|
return [componentNode, store];
|
|
2428
2537
|
};
|
|
2429
2538
|
}
|
|
@@ -2472,6 +2581,7 @@ Object.defineProperty(exports, "Store", {
|
|
|
2472
2581
|
get: function () { return aoye.Store; }
|
|
2473
2582
|
});
|
|
2474
2583
|
exports.Compiler = Compiler;
|
|
2584
|
+
exports.FakeType = FakeType;
|
|
2475
2585
|
exports.NodeType = NodeType;
|
|
2476
2586
|
exports.ParseSyntaxError = ParseSyntaxError;
|
|
2477
2587
|
exports.Tokenizer = Tokenizer;
|