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.
package/dist/bobe.esm.js CHANGED
@@ -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;
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) {
@@ -1096,7 +1097,7 @@ class Compiler {
1096
1097
  if (value === 'for') {
1097
1098
  return this.parseLoopNode();
1098
1099
  }
1099
- if (hookType) {
1100
+ if (hookType || this.tokenizer.token.type & TokenType.String) {
1100
1101
  return this.parseComponentNode();
1101
1102
  }
1102
1103
  return this.parseElementNode();
@@ -1117,9 +1118,9 @@ class Compiler {
1117
1118
  const tagToken = this.tokenizer.token;
1118
1119
  if (!(tagToken.type & TokenType.Identifier)) {
1119
1120
  this.addError(ParseErrorCode.INVALID_TAG_NAME, `无效的标签名,期望标识符但得到 "${tagToken.value}"`, tagToken.loc ?? this.tokenizer.emptyLoc(), node);
1120
- while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof()) {
1121
+ do {
1121
1122
  this.tokenizer.nextToken();
1122
- }
1123
+ } while (!(this.tokenizer.token.type & TokenType.NewLine) && !this.tokenizer.isEof());
1123
1124
  return null;
1124
1125
  }
1125
1126
  const tagName = tagToken.value;
@@ -1225,6 +1226,17 @@ class Compiler {
1225
1226
  }
1226
1227
  parseProperty(node) {
1227
1228
  node.type = NodeType.Property;
1229
+ if (this.tokenizer.token.type & ChildrenSugarType) {
1230
+ node.key = {
1231
+ type: NodeType.PropertyKey,
1232
+ key: 'children',
1233
+ loc: this.tokenizer.token.loc ?? this.tokenizer.emptyLoc()
1234
+ };
1235
+ node.value = this.parseJsExp();
1236
+ this.tokenizer.nextToken();
1237
+ this.handleKeyValueLoc(node);
1238
+ return node;
1239
+ }
1228
1240
  if (this.tokenizer.token.type !== TokenType.Identifier) {
1229
1241
  this.addError(ParseErrorCode.INVALID_PROP_KEY, `属性名 "${this.tokenizer.token.value}" 不合法`, this.tokenizer.token.loc ?? this.tokenizer.emptyLoc(), node);
1230
1242
  this.tokenizer.nextToken();
@@ -1430,14 +1442,22 @@ class InlineFragment {
1430
1442
  }
1431
1443
  const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
1432
1444
  const isRenderAble = val => isStore(val) || isUI(val) || val instanceof InlineFragment;
1445
+ const SAFE_HAS = () => true;
1433
1446
  const SAFE_HANDLER = {
1434
- has: () => true,
1435
- get: (t, k) => {
1436
- if (typeof k === 'symbol') return t[k];
1437
- return t[k];
1438
- }
1447
+ has: SAFE_HAS,
1448
+ get: (t, k, r) => Reflect.get(t, k, r)
1439
1449
  };
1440
1450
  const safe = data => new Proxy(data, SAFE_HANDLER);
1451
+ const safeExclude = (data, excludes) => {
1452
+ const proxy = new Proxy(data, SAFE_HANDLER);
1453
+ return new Proxy(proxy, {
1454
+ has: SAFE_HAS,
1455
+ get(t, k, r) {
1456
+ if (k === Symbol.unscopables) return excludes;
1457
+ return Reflect.get(t, k, r);
1458
+ }
1459
+ });
1460
+ };
1441
1461
 
1442
1462
  const KEY_INDEX = '__BOBE_KEY_INDEX';
1443
1463
  let _ctxStack;
@@ -1661,11 +1681,14 @@ class Interpreter {
1661
1681
  _node = this.componentOrFragmentDeclaration(value, ctx);
1662
1682
  } else {
1663
1683
  _node = this.createNode('text');
1664
- this.setProp(_node, 'text', String(value));
1684
+ this.setProp(_node, 'children', String(value));
1665
1685
  }
1666
1686
  } else {
1667
1687
  return this.dynamicDeclaration(data, value, ctx);
1668
1688
  }
1689
+ } else if (this.tokenizer.token.type === TokenType.String) {
1690
+ _node = this.createNode('text');
1691
+ this.setProp(_node, 'children', String(value));
1669
1692
  } else {
1670
1693
  _node = this.createNode(value);
1671
1694
  }
@@ -1746,7 +1769,7 @@ class Interpreter {
1746
1769
  if (isNewTextNode) {
1747
1770
  textNode = node.textNode = this.createNode('text');
1748
1771
  }
1749
- this.setProp(textNode, 'text', String(val));
1772
+ this.setProp(textNode, 'children', String(val));
1750
1773
  if (isNewTextNode) {
1751
1774
  if (isUpdate) {
1752
1775
  this.handleInsert(node.realParent, textNode, node.realBefore);
@@ -2359,7 +2382,9 @@ class Interpreter {
2359
2382
  }
2360
2383
  getAssignFn(data, expression) {
2361
2384
  const valueId = `value_bobe_${date32()}`;
2362
- return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, data);
2385
+ return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, safeExclude(data, {
2386
+ [valueId]: true
2387
+ }));
2363
2388
  }
2364
2389
  condDeclaration(ctx) {
2365
2390
  const prevSibling = ctx.prevSibling;
@@ -2523,7 +2548,14 @@ class Interpreter {
2523
2548
  let key, eq;
2524
2549
  while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
2525
2550
  if (key == null) {
2526
- key = this.tokenizer.token.value;
2551
+ const keyValue = this.tokenizer.token.value;
2552
+ if (this.tokenizer.token.type & ChildrenSugarType || typeof keyValue === 'string' && keyValue.startsWith(this.tokenizer.HookId)) {
2553
+ key = 'children';
2554
+ eq = '=';
2555
+ continue;
2556
+ } else {
2557
+ key = this.tokenizer.token.value;
2558
+ }
2527
2559
  } else if (eq == null) {
2528
2560
  eq = '=';
2529
2561
  } else {