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 | TokenType.StaticInsExp ;
|
|
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) {
|
|
@@ -1145,9 +1146,9 @@ class Compiler {
|
|
|
1145
1146
|
const tagToken = this.tokenizer.token;
|
|
1146
1147
|
if (!(tagToken.type & TokenType.Identifier)) {
|
|
1147
1148
|
this.addError(ParseErrorCode.INVALID_TAG_NAME, `无效的标签名,期望标识符但得到 "${tagToken.value}"`, tagToken.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1148
|
-
|
|
1149
|
+
do {
|
|
1149
1150
|
this.tokenizer.nextToken();
|
|
1150
|
-
}
|
|
1151
|
+
} while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof());
|
|
1151
1152
|
return null;
|
|
1152
1153
|
}
|
|
1153
1154
|
const tagName = tagToken.value;
|
|
@@ -1253,6 +1254,17 @@ class Compiler {
|
|
|
1253
1254
|
}
|
|
1254
1255
|
parseProperty(node) {
|
|
1255
1256
|
node.type = NodeType.Property;
|
|
1257
|
+
if (this.tokenizer.token.type & ChildrenSugarType) {
|
|
1258
|
+
node.key = {
|
|
1259
|
+
type: NodeType.PropertyKey,
|
|
1260
|
+
key: 'children',
|
|
1261
|
+
loc: this.tokenizer.token.loc ?? this.tokenizer.emptyLoc()
|
|
1262
|
+
};
|
|
1263
|
+
node.value = this.parseJsExp();
|
|
1264
|
+
this.tokenizer.nextToken();
|
|
1265
|
+
this.handleKeyValueLoc(node);
|
|
1266
|
+
return node;
|
|
1267
|
+
}
|
|
1256
1268
|
if (this.tokenizer.token.type !== TokenType.Identifier) {
|
|
1257
1269
|
this.addError(ParseErrorCode.INVALID_PROP_KEY, `属性名 "${this.tokenizer.token.value}" 不合法`, this.tokenizer.token.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1258
1270
|
this.tokenizer.nextToken();
|
|
@@ -1458,14 +1470,22 @@ class InlineFragment {
|
|
|
1458
1470
|
}
|
|
1459
1471
|
const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
|
|
1460
1472
|
const isRenderAble = val => aoye.isStore(val) || isUI(val) || val instanceof InlineFragment;
|
|
1473
|
+
const SAFE_HAS = () => true;
|
|
1461
1474
|
const SAFE_HANDLER = {
|
|
1462
|
-
has:
|
|
1463
|
-
get: (t, k) =>
|
|
1464
|
-
if (typeof k === 'symbol') return t[k];
|
|
1465
|
-
return t[k];
|
|
1466
|
-
}
|
|
1475
|
+
has: SAFE_HAS,
|
|
1476
|
+
get: (t, k, r) => Reflect.get(t, k, r)
|
|
1467
1477
|
};
|
|
1468
1478
|
const safe = data => new Proxy(data, SAFE_HANDLER);
|
|
1479
|
+
const safeExclude = (data, excludes) => {
|
|
1480
|
+
const proxy = new Proxy(data, SAFE_HANDLER);
|
|
1481
|
+
return new Proxy(proxy, {
|
|
1482
|
+
has: SAFE_HAS,
|
|
1483
|
+
get(t, k, r) {
|
|
1484
|
+
if (k === Symbol.unscopables) return excludes;
|
|
1485
|
+
return Reflect.get(t, k, r);
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
};
|
|
1469
1489
|
|
|
1470
1490
|
const KEY_INDEX = '__BOBE_KEY_INDEX';
|
|
1471
1491
|
let _ctxStack;
|
|
@@ -1689,14 +1709,14 @@ class Interpreter {
|
|
|
1689
1709
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1690
1710
|
} else {
|
|
1691
1711
|
_node = this.createNode('text');
|
|
1692
|
-
this.setProp(_node, '
|
|
1712
|
+
this.setProp(_node, 'children', String(value));
|
|
1693
1713
|
}
|
|
1694
1714
|
} else {
|
|
1695
1715
|
return this.dynamicDeclaration(data, value, ctx);
|
|
1696
1716
|
}
|
|
1697
1717
|
} else if (this.tokenizer.token.type === TokenType.String) {
|
|
1698
1718
|
_node = this.createNode('text');
|
|
1699
|
-
this.setProp(_node, '
|
|
1719
|
+
this.setProp(_node, 'children', String(value));
|
|
1700
1720
|
} else {
|
|
1701
1721
|
_node = this.createNode(value);
|
|
1702
1722
|
}
|
|
@@ -1777,7 +1797,7 @@ class Interpreter {
|
|
|
1777
1797
|
if (isNewTextNode) {
|
|
1778
1798
|
textNode = node.textNode = this.createNode('text');
|
|
1779
1799
|
}
|
|
1780
|
-
this.setProp(textNode, '
|
|
1800
|
+
this.setProp(textNode, 'children', String(val));
|
|
1781
1801
|
if (isNewTextNode) {
|
|
1782
1802
|
if (isUpdate) {
|
|
1783
1803
|
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
@@ -2390,7 +2410,9 @@ class Interpreter {
|
|
|
2390
2410
|
}
|
|
2391
2411
|
getAssignFn(data, expression) {
|
|
2392
2412
|
const valueId = `value_bobe_${bobeShared.date32()}`;
|
|
2393
|
-
return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, data
|
|
2413
|
+
return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, safeExclude(data, {
|
|
2414
|
+
[valueId]: true
|
|
2415
|
+
}));
|
|
2394
2416
|
}
|
|
2395
2417
|
condDeclaration(ctx) {
|
|
2396
2418
|
const prevSibling = ctx.prevSibling;
|
|
@@ -2554,7 +2576,14 @@ class Interpreter {
|
|
|
2554
2576
|
let key, eq;
|
|
2555
2577
|
while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
|
|
2556
2578
|
if (key == null) {
|
|
2557
|
-
|
|
2579
|
+
const keyValue = this.tokenizer.token.value;
|
|
2580
|
+
if (this.tokenizer.token.type & ChildrenSugarType || typeof keyValue === 'string' && keyValue.startsWith(this.tokenizer.HookId)) {
|
|
2581
|
+
key = 'children';
|
|
2582
|
+
eq = '=';
|
|
2583
|
+
continue;
|
|
2584
|
+
} else {
|
|
2585
|
+
key = this.tokenizer.token.value;
|
|
2586
|
+
}
|
|
2558
2587
|
} else if (eq == null) {
|
|
2559
2588
|
eq = '=';
|
|
2560
2589
|
} else {
|
|
@@ -2818,4 +2847,4 @@ exports.bobe = bobe;
|
|
|
2818
2847
|
exports.context = context;
|
|
2819
2848
|
exports.customRender = customRender;
|
|
2820
2849
|
exports.effect = effect;
|
|
2821
|
-
//# sourceMappingURL=bobe.compiler.cjs.
|
|
2850
|
+
//# sourceMappingURL=bobe.compiler.cjs.map
|