bobe 0.0.67 → 0.0.69
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 → bobe.cjs} +42 -13
- package/dist/bobe.cjs.map +1 -0
- package/dist/{bobe.compiler.cjs.js → bobe.compiler.cjs} +42 -13
- package/dist/bobe.compiler.cjs.map +1 -0
- package/dist/bobe.compiler.esm.js +41 -12
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +41 -12
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.umd.js +41 -12
- package/dist/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/dist/bobe.cjs.js.map +0 -1
- package/dist/bobe.compiler.cjs.js.map +0 -1
|
@@ -22,6 +22,7 @@ let TokenType = function (TokenType) {
|
|
|
22
22
|
TokenType[TokenType["Comment"] = 32768] = "Comment";
|
|
23
23
|
return TokenType;
|
|
24
24
|
}({});
|
|
25
|
+
const ChildrenSugarType = TokenType.String | TokenType.InsertionExp;
|
|
25
26
|
const BaseTokenType = TokenType.String | TokenType.Number | TokenType.Boolean | TokenType.Null | TokenType.Undefined;
|
|
26
27
|
const ValueTokenType = BaseTokenType | TokenType.InsertionExp | TokenType.StaticInsExp;
|
|
27
28
|
let FakeType = function (FakeType) {
|
|
@@ -1118,9 +1119,9 @@ class Compiler {
|
|
|
1118
1119
|
const tagToken = this.tokenizer.token;
|
|
1119
1120
|
if (!(tagToken.type & TokenType.Identifier)) {
|
|
1120
1121
|
this.addError(ParseErrorCode.INVALID_TAG_NAME, `无效的标签名,期望标识符但得到 "${tagToken.value}"`, tagToken.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1121
|
-
|
|
1122
|
+
do {
|
|
1122
1123
|
this.tokenizer.nextToken();
|
|
1123
|
-
}
|
|
1124
|
+
} while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof());
|
|
1124
1125
|
return null;
|
|
1125
1126
|
}
|
|
1126
1127
|
const tagName = tagToken.value;
|
|
@@ -1226,6 +1227,17 @@ class Compiler {
|
|
|
1226
1227
|
}
|
|
1227
1228
|
parseProperty(node) {
|
|
1228
1229
|
node.type = NodeType.Property;
|
|
1230
|
+
if (this.tokenizer.token.type & ChildrenSugarType) {
|
|
1231
|
+
node.key = {
|
|
1232
|
+
type: NodeType.PropertyKey,
|
|
1233
|
+
key: 'children',
|
|
1234
|
+
loc: this.tokenizer.token.loc ?? this.tokenizer.emptyLoc()
|
|
1235
|
+
};
|
|
1236
|
+
node.value = this.parseJsExp();
|
|
1237
|
+
this.tokenizer.nextToken();
|
|
1238
|
+
this.handleKeyValueLoc(node);
|
|
1239
|
+
return node;
|
|
1240
|
+
}
|
|
1229
1241
|
if (this.tokenizer.token.type !== TokenType.Identifier) {
|
|
1230
1242
|
this.addError(ParseErrorCode.INVALID_PROP_KEY, `属性名 "${this.tokenizer.token.value}" 不合法`, this.tokenizer.token.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1231
1243
|
this.tokenizer.nextToken();
|
|
@@ -1431,14 +1443,22 @@ class InlineFragment {
|
|
|
1431
1443
|
}
|
|
1432
1444
|
const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
|
|
1433
1445
|
const isRenderAble = val => aoye.isStore(val) || isUI(val) || val instanceof InlineFragment;
|
|
1446
|
+
const SAFE_HAS = () => true;
|
|
1434
1447
|
const SAFE_HANDLER = {
|
|
1435
|
-
has:
|
|
1436
|
-
get: (t, k) =>
|
|
1437
|
-
if (typeof k === 'symbol') return t[k];
|
|
1438
|
-
return t[k];
|
|
1439
|
-
}
|
|
1448
|
+
has: SAFE_HAS,
|
|
1449
|
+
get: (t, k, r) => Reflect.get(t, k, r)
|
|
1440
1450
|
};
|
|
1441
1451
|
const safe = data => new Proxy(data, SAFE_HANDLER);
|
|
1452
|
+
const safeExclude = (data, excludes) => {
|
|
1453
|
+
const proxy = new Proxy(data, SAFE_HANDLER);
|
|
1454
|
+
return new Proxy(proxy, {
|
|
1455
|
+
has: SAFE_HAS,
|
|
1456
|
+
get(t, k, r) {
|
|
1457
|
+
if (k === Symbol.unscopables) return excludes;
|
|
1458
|
+
return Reflect.get(t, k, r);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
};
|
|
1442
1462
|
|
|
1443
1463
|
const KEY_INDEX = '__BOBE_KEY_INDEX';
|
|
1444
1464
|
let _ctxStack;
|
|
@@ -1662,14 +1682,14 @@ class Interpreter {
|
|
|
1662
1682
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1663
1683
|
} else {
|
|
1664
1684
|
_node = this.createNode('text');
|
|
1665
|
-
this.setProp(_node, '
|
|
1685
|
+
this.setProp(_node, 'children', String(value));
|
|
1666
1686
|
}
|
|
1667
1687
|
} else {
|
|
1668
1688
|
return this.dynamicDeclaration(data, value, ctx);
|
|
1669
1689
|
}
|
|
1670
1690
|
} else if (this.tokenizer.token.type === TokenType.String) {
|
|
1671
1691
|
_node = this.createNode('text');
|
|
1672
|
-
this.setProp(_node, '
|
|
1692
|
+
this.setProp(_node, 'children', String(value));
|
|
1673
1693
|
} else {
|
|
1674
1694
|
_node = this.createNode(value);
|
|
1675
1695
|
}
|
|
@@ -1750,7 +1770,7 @@ class Interpreter {
|
|
|
1750
1770
|
if (isNewTextNode) {
|
|
1751
1771
|
textNode = node.textNode = this.createNode('text');
|
|
1752
1772
|
}
|
|
1753
|
-
this.setProp(textNode, '
|
|
1773
|
+
this.setProp(textNode, 'children', String(val));
|
|
1754
1774
|
if (isNewTextNode) {
|
|
1755
1775
|
if (isUpdate) {
|
|
1756
1776
|
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
@@ -2363,7 +2383,9 @@ class Interpreter {
|
|
|
2363
2383
|
}
|
|
2364
2384
|
getAssignFn(data, expression) {
|
|
2365
2385
|
const valueId = `value_bobe_${bobeShared.date32()}`;
|
|
2366
|
-
return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, data
|
|
2386
|
+
return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, safeExclude(data, {
|
|
2387
|
+
[valueId]: true
|
|
2388
|
+
}));
|
|
2367
2389
|
}
|
|
2368
2390
|
condDeclaration(ctx) {
|
|
2369
2391
|
const prevSibling = ctx.prevSibling;
|
|
@@ -2527,7 +2549,14 @@ class Interpreter {
|
|
|
2527
2549
|
let key, eq;
|
|
2528
2550
|
while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
|
|
2529
2551
|
if (key == null) {
|
|
2530
|
-
|
|
2552
|
+
const keyValue = this.tokenizer.token.value;
|
|
2553
|
+
if (this.tokenizer.token.type & ChildrenSugarType || typeof keyValue === 'string' && keyValue.startsWith(this.tokenizer.HookId)) {
|
|
2554
|
+
key = 'children';
|
|
2555
|
+
eq = '=';
|
|
2556
|
+
continue;
|
|
2557
|
+
} else {
|
|
2558
|
+
key = this.tokenizer.token.value;
|
|
2559
|
+
}
|
|
2531
2560
|
} else if (eq == null) {
|
|
2532
2561
|
eq = '=';
|
|
2533
2562
|
} else {
|
|
@@ -2791,4 +2820,4 @@ exports.bobe = bobe;
|
|
|
2791
2820
|
exports.context = context;
|
|
2792
2821
|
exports.customRender = customRender;
|
|
2793
2822
|
exports.effect = effect;
|
|
2794
|
-
//# sourceMappingURL=bobe.cjs.
|
|
2823
|
+
//# sourceMappingURL=bobe.cjs.map
|