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