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.
@@ -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) {
@@ -1123,7 +1124,7 @@ class Compiler {
1123
1124
  if (value === 'for') {
1124
1125
  return this.parseLoopNode();
1125
1126
  }
1126
- if (hookType) {
1127
+ if (hookType || this.tokenizer.token.type & TokenType.String) {
1127
1128
  return this.parseComponentNode();
1128
1129
  }
1129
1130
  return this.parseElementNode();
@@ -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,11 +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
  }
1716
+ } else if (this.tokenizer.token.type === TokenType.String) {
1717
+ _node = this.createNode('text');
1718
+ this.setProp(_node, 'children', String(value));
1696
1719
  } else {
1697
1720
  _node = this.createNode(value);
1698
1721
  }
@@ -1773,7 +1796,7 @@ class Interpreter {
1773
1796
  if (isNewTextNode) {
1774
1797
  textNode = node.textNode = this.createNode('text');
1775
1798
  }
1776
- this.setProp(textNode, 'text', String(val));
1799
+ this.setProp(textNode, 'children', String(val));
1777
1800
  if (isNewTextNode) {
1778
1801
  if (isUpdate) {
1779
1802
  this.handleInsert(node.realParent, textNode, node.realBefore);
@@ -2386,7 +2409,9 @@ class Interpreter {
2386
2409
  }
2387
2410
  getAssignFn(data, expression) {
2388
2411
  const valueId = `value_bobe_${date32()}`;
2389
- 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
+ }));
2390
2415
  }
2391
2416
  condDeclaration(ctx) {
2392
2417
  const prevSibling = ctx.prevSibling;
@@ -2550,7 +2575,14 @@ class Interpreter {
2550
2575
  let key, eq;
2551
2576
  while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
2552
2577
  if (key == null) {
2553
- 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
+ }
2554
2586
  } else if (eq == null) {
2555
2587
  eq = '=';
2556
2588
  } else {