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