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/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) {
@@ -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
- while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof()) {
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: () => true,
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,14 +1683,14 @@
1663
1683
  _node = this.componentOrFragmentDeclaration(value, ctx);
1664
1684
  } else {
1665
1685
  _node = this.createNode('text');
1666
- this.setProp(_node, 'text', String(value));
1686
+ this.setProp(_node, 'children', String(value));
1667
1687
  }
1668
1688
  } else {
1669
1689
  return this.dynamicDeclaration(data, value, ctx);
1670
1690
  }
1671
1691
  } else if (this.tokenizer.token.type === TokenType.String) {
1672
1692
  _node = this.createNode('text');
1673
- this.setProp(_node, 'text', String(value));
1693
+ this.setProp(_node, 'children', String(value));
1674
1694
  } else {
1675
1695
  _node = this.createNode(value);
1676
1696
  }
@@ -1751,7 +1771,7 @@
1751
1771
  if (isNewTextNode) {
1752
1772
  textNode = node.textNode = this.createNode('text');
1753
1773
  }
1754
- this.setProp(textNode, 'text', String(val));
1774
+ this.setProp(textNode, 'children', String(val));
1755
1775
  if (isNewTextNode) {
1756
1776
  if (isUpdate) {
1757
1777
  this.handleInsert(node.realParent, textNode, node.realBefore);
@@ -2364,7 +2384,9 @@
2364
2384
  }
2365
2385
  getAssignFn(data, expression) {
2366
2386
  const valueId = `value_bobe_${bobeShared.date32()}`;
2367
- 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
+ }));
2368
2390
  }
2369
2391
  condDeclaration(ctx) {
2370
2392
  const prevSibling = ctx.prevSibling;
@@ -2528,7 +2550,14 @@
2528
2550
  let key, eq;
2529
2551
  while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
2530
2552
  if (key == null) {
2531
- key = this.tokenizer.token.value;
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
+ }
2532
2561
  } else if (eq == null) {
2533
2562
  eq = '=';
2534
2563
  } else {