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