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.
@@ -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) {
@@ -1097,7 +1098,7 @@ class Compiler {
1097
1098
  if (value === 'for') {
1098
1099
  return this.parseLoopNode();
1099
1100
  }
1100
- if (hookType) {
1101
+ if (hookType || this.tokenizer.token.type & TokenType.String) {
1101
1102
  return this.parseComponentNode();
1102
1103
  }
1103
1104
  return this.parseElementNode();
@@ -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
- while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof()) {
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: () => true,
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,11 +1682,14 @@ class Interpreter {
1662
1682
  _node = this.componentOrFragmentDeclaration(value, ctx);
1663
1683
  } else {
1664
1684
  _node = this.createNode('text');
1665
- this.setProp(_node, 'text', String(value));
1685
+ this.setProp(_node, 'children', String(value));
1666
1686
  }
1667
1687
  } else {
1668
1688
  return this.dynamicDeclaration(data, value, ctx);
1669
1689
  }
1690
+ } else if (this.tokenizer.token.type === TokenType.String) {
1691
+ _node = this.createNode('text');
1692
+ this.setProp(_node, 'children', String(value));
1670
1693
  } else {
1671
1694
  _node = this.createNode(value);
1672
1695
  }
@@ -1747,7 +1770,7 @@ class Interpreter {
1747
1770
  if (isNewTextNode) {
1748
1771
  textNode = node.textNode = this.createNode('text');
1749
1772
  }
1750
- this.setProp(textNode, 'text', String(val));
1773
+ this.setProp(textNode, 'children', String(val));
1751
1774
  if (isNewTextNode) {
1752
1775
  if (isUpdate) {
1753
1776
  this.handleInsert(node.realParent, textNode, node.realBefore);
@@ -2360,7 +2383,9 @@ class Interpreter {
2360
2383
  }
2361
2384
  getAssignFn(data, expression) {
2362
2385
  const valueId = `value_bobe_${bobeShared.date32()}`;
2363
- 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
+ }));
2364
2389
  }
2365
2390
  condDeclaration(ctx) {
2366
2391
  const prevSibling = ctx.prevSibling;
@@ -2524,7 +2549,14 @@ class Interpreter {
2524
2549
  let key, eq;
2525
2550
  while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
2526
2551
  if (key == null) {
2527
- key = this.tokenizer.token.value;
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
+ }
2528
2560
  } else if (eq == null) {
2529
2561
  eq = '=';
2530
2562
  } else {
@@ -2788,4 +2820,4 @@ exports.bobe = bobe;
2788
2820
  exports.context = context;
2789
2821
  exports.customRender = customRender;
2790
2822
  exports.effect = effect;
2791
- //# sourceMappingURL=bobe.cjs.js.map
2823
+ //# sourceMappingURL=bobe.cjs.map