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