bobe 0.0.21 → 0.0.23

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
@@ -2,7 +2,76 @@ import { getPulling, setPulling, Keys, $, effect, toRaw, scope, Store, deepSigna
2
2
  export * from 'aoye';
3
3
  import { BaseEvent, jsVarRegexp, Queue, isNum, matchIdStart2 } from 'bobe-shared';
4
4
 
5
- var TokenType = /* @__PURE__ */ ((TokenType2) => {
5
+ function _arrayLikeToArray(r, a) {
6
+ (null == a || a > r.length) && (a = r.length);
7
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
+ return n;
9
+ }
10
+ function _arrayWithHoles(r) {
11
+ if (Array.isArray(r)) return r;
12
+ }
13
+ function _iterableToArrayLimit(r, l) {
14
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
15
+ if (null != t) {
16
+ var e,
17
+ n,
18
+ i,
19
+ u,
20
+ a = [],
21
+ f = true,
22
+ o = false;
23
+ try {
24
+ if (i = (t = t.call(r)).next, 0 === l) {
25
+ if (Object(t) !== t) return;
26
+ f = !1;
27
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
28
+ } catch (r) {
29
+ o = true, n = r;
30
+ } finally {
31
+ try {
32
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
33
+ } finally {
34
+ if (o) throw n;
35
+ }
36
+ }
37
+ return a;
38
+ }
39
+ }
40
+ function _nonIterableRest() {
41
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
42
+ }
43
+ function _objectWithoutProperties(e, t) {
44
+ if (null == e) return {};
45
+ var o,
46
+ r,
47
+ i = _objectWithoutPropertiesLoose(e, t);
48
+ if (Object.getOwnPropertySymbols) {
49
+ var n = Object.getOwnPropertySymbols(e);
50
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
51
+ }
52
+ return i;
53
+ }
54
+ function _objectWithoutPropertiesLoose(r, e) {
55
+ if (null == r) return {};
56
+ var t = {};
57
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
58
+ if (-1 !== e.indexOf(n)) continue;
59
+ t[n] = r[n];
60
+ }
61
+ return t;
62
+ }
63
+ function _slicedToArray(r, e) {
64
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
65
+ }
66
+ function _unsupportedIterableToArray(r, a) {
67
+ if (r) {
68
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
69
+ var t = {}.toString.call(r).slice(8, -1);
70
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
71
+ }
72
+ }
73
+
74
+ var TokenType = /* @__PURE__ */(TokenType2 => {
6
75
  TokenType2[TokenType2["NewLine"] = 1] = "NewLine";
7
76
  TokenType2[TokenType2["Indent"] = 2] = "Indent";
8
77
  TokenType2[TokenType2["Dedent"] = 4] = "Dedent";
@@ -14,7 +83,7 @@ var TokenType = /* @__PURE__ */ ((TokenType2) => {
14
83
  TokenType2[TokenType2["Semicolon"] = 256] = "Semicolon";
15
84
  return TokenType2;
16
85
  })(TokenType || {});
17
- var FakeType = /* @__PURE__ */ ((FakeType2) => {
86
+ var FakeType = /* @__PURE__ */(FakeType2 => {
18
87
  FakeType2[FakeType2["If"] = 1] = "If";
19
88
  FakeType2[FakeType2["Fail"] = 2] = "Fail";
20
89
  FakeType2[FakeType2["Else"] = 4] = "Else";
@@ -27,7 +96,7 @@ var FakeType = /* @__PURE__ */ ((FakeType2) => {
27
96
  const CondBit = 1 /* If */ | 2 /* Fail */ | 4 /* Else */;
28
97
  const LogicalBit = 1 /* If */ | 2 /* Fail */ | 4 /* Else */ | 8 /* For */ | 64 /* ForItem */;
29
98
  const TokenizerSwitcherBit = 16 /* Component */ | 32 /* Fragment */;
30
- var NodeSort = /* @__PURE__ */ ((NodeSort2) => {
99
+ var NodeSort = /* @__PURE__ */(NodeSort2 => {
31
100
  NodeSort2[NodeSort2["Logic"] = 1] = "Logic";
32
101
  NodeSort2[NodeSort2["Real"] = 2] = "Real";
33
102
  NodeSort2[NodeSort2["Component"] = 4] = "Component";
@@ -73,7 +142,7 @@ class MultiTypeStack {
73
142
  const poppedNode = this.stack[this.length - 1];
74
143
  this.stack[--this.length] = null;
75
144
  if (!poppedNode) return void 0;
76
- let { types: bits } = poppedNode;
145
+ let bits = poppedNode.types;
77
146
  let bit;
78
147
  while (1) {
79
148
  bit = bits & ~bits + 1;
@@ -87,8 +156,7 @@ class MultiTypeStack {
87
156
  * 获取某个类别的当前“顶部”元素
88
157
  */
89
158
  peekByType(cat) {
90
- var _a;
91
- return (_a = this.typeTops[cat]) == null ? void 0 : _a.value;
159
+ return this.typeTops[cat]?.value;
92
160
  }
93
161
  peekType() {
94
162
  return this.stack.at(-1).types;
@@ -129,21 +197,7 @@ class MultiTypeStack {
129
197
  // }
130
198
  }
131
199
 
132
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
133
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
134
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
135
- var __objRest = (source, exclude) => {
136
- var target = {};
137
- for (var prop in source)
138
- if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
139
- target[prop] = source[prop];
140
- if (source != null && __getOwnPropSymbols$1)
141
- for (var prop of __getOwnPropSymbols$1(source)) {
142
- if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
143
- target[prop] = source[prop];
144
- }
145
- return target;
146
- };
200
+ const _excluded = ["dentStack", "isFirstToken"];
147
201
  new BaseEvent();
148
202
  class Interpreter {
149
203
  constructor(tokenizer) {
@@ -156,20 +210,22 @@ class Interpreter {
156
210
  return node && node.__logicType & LogicalBit;
157
211
  }
158
212
  program(root, componentNode, before, ctxProvider) {
159
- var _a, _b;
160
213
  this.rootComponent = componentNode;
161
214
  this.tokenizer.nextToken();
162
215
  const stack = new MultiTypeStack();
163
- stack.push({ node: root, prev: null }, NodeSort.Real);
164
- stack.push(
165
- { node: componentNode, prev: null },
166
- NodeSort.Component | NodeSort.CtxProvider | NodeSort.TokenizerSwitcher
167
- );
216
+ stack.push({
217
+ node: root,
218
+ prev: null
219
+ }, NodeSort.Real);
220
+ stack.push({
221
+ node: componentNode,
222
+ prev: null
223
+ }, NodeSort.Component | NodeSort.CtxProvider | NodeSort.TokenizerSwitcher);
168
224
  if (ctxProvider) {
169
- stack.push(
170
- { node: ctxProvider, prev: null },
171
- (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider
172
- );
225
+ stack.push({
226
+ node: ctxProvider,
227
+ prev: null
228
+ }, (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider);
173
229
  }
174
230
  const ctx = this.ctx = {
175
231
  realParent: root,
@@ -189,13 +245,10 @@ class Interpreter {
189
245
  if (token.type & TokenType.Indent) {
190
246
  this.tokenizer.nextToken();
191
247
  const isLogicNode = this.isLogicNode(ctx.current);
192
- stack.push(
193
- {
194
- node: ctx.current,
195
- prev: ctx.prevSibling
196
- },
197
- !ctx.current.__logicType ? NodeSort.Real : (ctx.current.__logicType & LogicalBit ? NodeSort.Logic : 0) | (ctx.current.__logicType & TokenizerSwitcherBit ? NodeSort.TokenizerSwitcher : 0) | (ctx.current.__logicType === FakeType.Component ? NodeSort.Component : 0) | NodeSort.CtxProvider
198
- );
248
+ stack.push({
249
+ node: ctx.current,
250
+ prev: ctx.prevSibling
251
+ }, !ctx.current.__logicType ? NodeSort.Real : (ctx.current.__logicType & LogicalBit ? NodeSort.Logic : 0) | (ctx.current.__logicType & TokenizerSwitcherBit ? NodeSort.TokenizerSwitcher : 0) | (ctx.current.__logicType === FakeType.Component ? NodeSort.Component : 0) | NodeSort.CtxProvider);
199
252
  if (ctx.current.__logicType) {
200
253
  if (isLogicNode) {
201
254
  setPulling(ctx.current.effect.ins);
@@ -217,13 +270,18 @@ class Interpreter {
217
270
  }
218
271
  if (this.tokenizer.token.type & TokenType.Dedent) {
219
272
  this.tokenizer.nextToken();
220
- const [{ node: parent, prev }, sort] = stack.pop();
273
+ const _stack$pop = stack.pop(),
274
+ _stack$pop2 = _slicedToArray(_stack$pop, 2),
275
+ _stack$pop2$ = _stack$pop2[0],
276
+ parent = _stack$pop2$.node,
277
+ prev = _stack$pop2$.prev,
278
+ sort = _stack$pop2[1];
221
279
  if (!parent.__logicType) {
222
280
  const prevSameType = stack.peekByType(NodeSort.Real);
223
- ctx.realParent = (prevSameType == null ? void 0 : prevSameType.node) || root;
281
+ ctx.realParent = prevSameType?.node || root;
224
282
  } else {
225
283
  if (sort & NodeSort.Logic) {
226
- const parentLogic = (_a = stack.peekByType(NodeSort.Logic)) == null ? void 0 : _a.node;
284
+ const parentLogic = stack.peekByType(NodeSort.Logic)?.node;
227
285
  if (parentLogic) {
228
286
  setPulling(parentLogic.effect.ins);
229
287
  } else {
@@ -231,12 +289,14 @@ class Interpreter {
231
289
  }
232
290
  }
233
291
  if (sort & NodeSort.TokenizerSwitcher) {
234
- const switcher = (_b = stack.peekByType(NodeSort.TokenizerSwitcher)) == null ? void 0 : _b.node;
292
+ const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
235
293
  this.tokenizer = switcher.tokenizer;
236
294
  }
237
295
  if (parent.__logicType === FakeType.ForItem) {
238
- const { forNode } = parent;
239
- const { i, arr, snapshot } = forNode;
296
+ const forNode = parent.forNode;
297
+ const i = forNode.i,
298
+ arr = forNode.arr,
299
+ snapshot = forNode.snapshot;
240
300
  if (i + 1 < arr.length) {
241
301
  this.tokenizer.resume(snapshot);
242
302
  this.tokenizer.nextToken();
@@ -260,7 +320,11 @@ class Interpreter {
260
320
  return componentNode;
261
321
  }
262
322
  insertAfterAnchor(name = "anchor") {
263
- const { realParent, prevSibling, stack, before } = this.ctx;
323
+ const _this$ctx = this.ctx,
324
+ realParent = _this$ctx.realParent,
325
+ prevSibling = _this$ctx.prevSibling,
326
+ stack = _this$ctx.stack,
327
+ before = _this$ctx.before;
264
328
  const afterAnchor = this.createAnchor(name);
265
329
  this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
266
330
  this.handleInsert(realParent, afterAnchor, prevSibling);
@@ -283,7 +347,7 @@ class Interpreter {
283
347
  } else {
284
348
  const childCmp = child;
285
349
  childCmp.realParent = parent;
286
- if (prev == null ? void 0 : prev.__logicType) {
350
+ if (prev?.__logicType) {
287
351
  childCmp.realBefore = prev.forNode ? prev.forNode.realAfter : prev.realAfter;
288
352
  } else {
289
353
  childCmp.realBefore = prev;
@@ -309,7 +373,10 @@ class Interpreter {
309
373
  * <declaration> ::= <tagName=token> <headerLine> <extensionLines>
310
374
  * */
311
375
  declaration(ctx) {
312
- const [hookType, value] = this.tokenizer._hook({});
376
+ const _this$tokenizer$_hook = this.tokenizer._hook({}),
377
+ _this$tokenizer$_hook2 = _slicedToArray(_this$tokenizer$_hook, 2),
378
+ hookType = _this$tokenizer$_hook2[0],
379
+ value = _this$tokenizer$_hook2[1];
313
380
  let _node;
314
381
  if (value === "if" || value === "else" || value === "fail") {
315
382
  return this.condDeclaration(ctx);
@@ -347,7 +414,6 @@ class Interpreter {
347
414
  return _node;
348
415
  }
349
416
  forDeclaration() {
350
- var _a;
351
417
  const arrExp = this.tokenizer.nextToken().value;
352
418
  this.tokenizer.nextToken();
353
419
  const itemToken = this.tokenizer.nextToken();
@@ -369,14 +435,14 @@ class Interpreter {
369
435
  }
370
436
  }
371
437
  }
372
- const owner = (_a = this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)) == null ? void 0 : _a.node;
438
+ const owner = this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
373
439
  const prevSibling = this.ctx.prevSibling;
374
440
  const forNode = {
375
441
  __logicType: FakeType.For,
376
442
  snapshot: this.tokenizer.snapshot(["dentStack", "isFirstToken"]),
377
443
  realParent: this.ctx.realParent,
378
444
  prevSibling,
379
- realBefore: (prevSibling == null ? void 0 : prevSibling.realAfter) || prevSibling,
445
+ realBefore: prevSibling?.realAfter || prevSibling,
380
446
  realAfter: null,
381
447
  arr: null,
382
448
  itemExp,
@@ -395,24 +461,24 @@ class Interpreter {
395
461
  const cells = data[Keys.Meta].cells;
396
462
  const hasArrExpKey = Reflect.has(data[Keys.Raw], arrExp);
397
463
  const arrSignal = hasArrExpKey ? (
398
- // 有 key 直接拿
399
- (data[arrExp], cells.get(arrExp))
400
- ) : (
401
- // 无key
402
- $(this.getFn(data, arrExp))
403
- );
464
+ // 有 key 直接拿
465
+ data[arrExp], cells.get(arrExp)) :
466
+ // 无key
467
+ $(this.getFn(data, arrExp));
404
468
  forNode.realAfter = this.insertAfterAnchor("for-after");
405
- const _b = forNode.snapshot, { dentStack, isFirstToken } = _b, snapshotForUpdate = __objRest(_b, ["dentStack", "isFirstToken"]);
469
+ const _forNode$snapshot = forNode.snapshot;
470
+ _forNode$snapshot.dentStack;
471
+ _forNode$snapshot.isFirstToken;
472
+ const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
406
473
  let isFirstRender = true;
407
474
  forNode.effect = effect(() => {
408
- var _a2;
409
475
  let arr = forNode.arr = arrSignal.v;
410
476
  arr[Keys.Iterator];
411
477
  arr = toRaw(arr);
412
478
  const children = forNode.children;
413
479
  if (isFirstRender) {
414
480
  const len = arr.length;
415
- for (let i = len; i--; ) {
481
+ for (let i = len; i--;) {
416
482
  const nextItem = children[i + 1];
417
483
  const item = this.createForItem(forNode, i, data);
418
484
  const anchor = this.insertAfterAnchor("for-item-after");
@@ -446,7 +512,7 @@ class Interpreter {
446
512
  }
447
513
  }
448
514
  if (oldLen < newLen) {
449
- const lastAfter = ((_a2 = children.at(-1)) == null ? void 0 : _a2.realAfter) || forNode.realBefore;
515
+ const lastAfter = children.at(-1)?.realAfter || forNode.realBefore;
450
516
  for (let i = newLen - 1; i >= oldLen; i--) {
451
517
  const item = this.createForItem(forNode, i, data);
452
518
  newChildren[i] = item;
@@ -470,7 +536,7 @@ class Interpreter {
470
536
  firstInsert.realBefore = lastAfter;
471
537
  }
472
538
  }
473
- for (let i = minLen; i--; ) {
539
+ for (let i = minLen; i--;) {
474
540
  const child = children[i];
475
541
  newChildren[i] = child;
476
542
  if (typeof itemExp === "string") {
@@ -488,19 +554,19 @@ class Interpreter {
488
554
  }
489
555
  createForItem(forNode, i, parentData) {
490
556
  let forItemNode;
491
- const effect2 = scope(() => {
492
- }, null);
493
- const { arr, itemExp, indexName, getKey } = forNode;
557
+ const effect2 = scope(() => {}, null);
558
+ const arr = forNode.arr,
559
+ itemExp = forNode.itemExp,
560
+ indexName = forNode.indexName,
561
+ getKey = forNode.getKey;
494
562
  let data;
495
563
  if (typeof itemExp === "string") {
496
- data = $(
497
- indexName ? {
498
- [itemExp]: arr[i],
499
- [indexName]: i
500
- } : {
501
- [itemExp]: arr[i]
502
- }
503
- );
564
+ data = $(indexName ? {
565
+ [itemExp]: arr[i],
566
+ [indexName]: i
567
+ } : {
568
+ [itemExp]: arr[i]
569
+ });
504
570
  } else {
505
571
  const rawData = itemExp(arr[i]);
506
572
  if (indexName) {
@@ -516,7 +582,7 @@ class Interpreter {
516
582
  realBefore: null,
517
583
  realAfter: null,
518
584
  forNode,
519
- key: getKey == null ? void 0 : getKey(data),
585
+ key: getKey?.(data),
520
586
  effect: null,
521
587
  data
522
588
  };
@@ -524,7 +590,8 @@ class Interpreter {
524
590
  return forItemNode;
525
591
  }
526
592
  getData() {
527
- const { node } = this.ctx.stack.peekByType(NodeSort.CtxProvider);
593
+ const _this$ctx$stack$peekB = this.ctx.stack.peekByType(NodeSort.CtxProvider),
594
+ node = _this$ctx$stack$peekB.node;
528
595
  return node.data || node.owner.data;
529
596
  }
530
597
  /**
@@ -585,7 +652,9 @@ class Interpreter {
585
652
  cells.set(key, computed);
586
653
  child[Keys.Raw][key] = void 0;
587
654
  } else {
588
- cells.set(key, { v: value });
655
+ cells.set(key, {
656
+ v: value
657
+ });
589
658
  child[Keys.Raw][key] = value;
590
659
  }
591
660
  }
@@ -598,18 +667,17 @@ class Interpreter {
598
667
  }
599
668
  // TODO: 优化代码逻辑,拆分 if elseif else
600
669
  condDeclaration(ctx) {
601
- var _a;
602
- const { prevSibling } = ctx;
670
+ const prevSibling = ctx.prevSibling;
603
671
  const keyWord = this.tokenizer.token;
604
672
  const expToken = this.tokenizer.condExp();
605
673
  const value = expToken.value;
606
674
  const isElse = keyWord.value === "else";
607
675
  const isIf = keyWord.value === "if";
608
- const preIsCond = (prevSibling == null ? void 0 : prevSibling.__logicType) & CondBit;
676
+ const preIsCond = prevSibling?.__logicType & CondBit;
609
677
  const data = this.getData();
610
678
  const noCond = value === true;
611
679
  const valueIsMapKey = !noCond && Reflect.has(data[Keys.Raw], value);
612
- const owner = (_a = ctx.stack.peekByType(NodeSort.TokenizerSwitcher)) == null ? void 0 : _a.node;
680
+ const owner = ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
613
681
  const ifNode = {
614
682
  __logicType: isElse ? FakeType.Else : isIf ? FakeType.If : FakeType.Fail,
615
683
  // 此时 token 是 exp, 下次解析 从 \n 开始
@@ -628,7 +696,7 @@ class Interpreter {
628
696
  case "if":
629
697
  if (valueIsMapKey) {
630
698
  runWithPulling(() => data[value], null);
631
- const { cells } = data[Keys.Meta];
699
+ const cells = data[Keys.Meta].cells;
632
700
  signal = cells.get(value);
633
701
  } else {
634
702
  const fn = this.getFn(data, value);
@@ -682,33 +750,34 @@ class Interpreter {
682
750
  }
683
751
  ifNode.condition = signal;
684
752
  ifNode.realAfter = this.insertAfterAnchor(`${keyWord.value}-after`);
685
- ifNode.effect = effect(
686
- ({ val }) => {
687
- if (val) {
688
- if (ifNode.isFirstRender) {
689
- this.tokenizer.nextToken();
690
- this.tokenizer.nextToken();
691
- } else {
692
- this.tokenizer = ifNode.owner.tokenizer;
693
- this.tokenizer.resume(ifNode.snapshot);
694
- this.tokenizer.useDedentAsEof = false;
695
- this.program(ifNode.realParent, ifNode.owner, ifNode.realBefore, ifNode);
696
- }
753
+ ifNode.effect = effect(({
754
+ val
755
+ }) => {
756
+ if (val) {
757
+ if (ifNode.isFirstRender) {
758
+ this.tokenizer.nextToken();
759
+ this.tokenizer.nextToken();
697
760
  } else {
698
- if (ifNode.isFirstRender) {
699
- this.tokenizer.skip();
700
- } else {
701
- this.removeLogicNode(ifNode);
702
- }
761
+ this.tokenizer = ifNode.owner.tokenizer;
762
+ this.tokenizer.resume(ifNode.snapshot);
763
+ this.tokenizer.useDedentAsEof = false;
764
+ this.program(ifNode.realParent, ifNode.owner, ifNode.realBefore, ifNode);
765
+ }
766
+ } else {
767
+ if (ifNode.isFirstRender) {
768
+ this.tokenizer.skip();
769
+ } else {
770
+ this.removeLogicNode(ifNode);
703
771
  }
704
- ifNode.isFirstRender = false;
705
- },
706
- [signal]
707
- );
772
+ }
773
+ ifNode.isFirstRender = false;
774
+ }, [signal]);
708
775
  return ifNode;
709
776
  }
710
777
  removeLogicNode(node) {
711
- const { realBefore, realAfter, realParent } = node;
778
+ const realBefore = node.realBefore,
779
+ realAfter = node.realAfter,
780
+ realParent = node.realParent;
712
781
  let point = realBefore ? this.nextSib(realBefore) : this.firstChild(realParent);
713
782
  while (point !== realAfter) {
714
783
  const next = this.nextSib(point);
@@ -761,7 +830,11 @@ class Interpreter {
761
830
  } else if (eq == null) {
762
831
  eq = "=";
763
832
  } else {
764
- const [hookType, value, hookI] = this.tokenizer._hook({});
833
+ const _this$tokenizer$_hook3 = this.tokenizer._hook({}),
834
+ _this$tokenizer$_hook4 = _slicedToArray(_this$tokenizer$_hook3, 3),
835
+ hookType = _this$tokenizer$_hook4[0],
836
+ value = _this$tokenizer$_hook4[1],
837
+ hookI = _this$tokenizer$_hook4[2];
765
838
  const rawVal = data[Keys.Raw][value];
766
839
  const isFn = typeof rawVal === "function";
767
840
  if (hookType === "dynamic") {
@@ -834,33 +907,16 @@ class Interpreter {
834
907
  }
835
908
  }
836
909
 
837
- var __defProp = Object.defineProperty;
838
- var __defProps = Object.defineProperties;
839
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
840
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
841
- var __hasOwnProp = Object.prototype.hasOwnProperty;
842
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
843
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
844
- var __spreadValues = (a, b) => {
845
- for (var prop in b || (b = {}))
846
- if (__hasOwnProp.call(b, prop))
847
- __defNormalProp(a, prop, b[prop]);
848
- if (__getOwnPropSymbols)
849
- for (var prop of __getOwnPropSymbols(b)) {
850
- if (__propIsEnum.call(b, prop))
851
- __defNormalProp(a, prop, b[prop]);
852
- }
853
- return a;
854
- };
855
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
856
- const _Tokenizer = class _Tokenizer {
910
+ class Tokenizer {
857
911
  constructor(hook, useDedentAsEof) {
858
912
  this.hook = hook;
859
913
  this.useDedentAsEof = useDedentAsEof;
860
914
  /** 缩进大小 默认 2 */
861
915
  this.TabSize = 2;
862
916
  /** 缩进字符 */
863
- this.Tab = Array.from({ length: this.TabSize }, () => " ").join("");
917
+ this.Tab = Array.from({
918
+ length: this.TabSize
919
+ }, () => " ").join("");
864
920
  /** 回车后需要判断缩进 */
865
921
  this.needIndent = false;
866
922
  /** 用于跳过第一个节点前的空白字符串,以及生成基础缩进 */
@@ -884,17 +940,18 @@ const _Tokenizer = class _Tokenizer {
884
940
  this.HookId = "_h_o_o_k_";
885
941
  /** 模板字符串动态节点索引 */
886
942
  this.hookI = 0;
887
- this._hook = (props) => {
943
+ this._hook = props => {
888
944
  const value = this.token.value;
889
945
  const isDynamicHook = this.token.type & TokenType.InsertionExp;
890
946
  const isStaticHook = typeof value === "string" && value.indexOf(this.HookId) === 0;
891
947
  const hookType = isDynamicHook ? "dynamic" : isStaticHook ? "static" : void 0;
892
948
  if (this.hook && isStaticHook) {
893
949
  const hookI = Number(value.slice(this.HookId.length));
894
- const res = this.hook(__spreadProps(__spreadValues({}, props), {
950
+ const res = this.hook({
951
+ ...props,
895
952
  HookId: this.HookId,
896
953
  i: hookI
897
- }));
954
+ });
898
955
  return [hookType, res, hookI];
899
956
  } else if (isDynamicHook) {
900
957
  return [hookType, value];
@@ -906,6 +963,13 @@ const _Tokenizer = class _Tokenizer {
906
963
  this.isFirstToken = true;
907
964
  }
908
965
  }
966
+ static {
967
+ /** Eof 标识符的值 */
968
+ this.EofId = `__EOF__${Date.now()}`;
969
+ }
970
+ static {
971
+ this.DedentId = `__DEDENT__${Date.now()}`;
972
+ }
909
973
  consume() {
910
974
  const token = this.token;
911
975
  this.nextToken();
@@ -953,7 +1017,9 @@ const _Tokenizer = class _Tokenizer {
953
1017
  continue;
954
1018
  }
955
1019
  needIndent = false;
956
- const { value, isEmptyLine } = this.getDentValue();
1020
+ const _this$getDentValue = this.getDentValue(),
1021
+ value = _this$getDentValue.value,
1022
+ isEmptyLine = _this$getDentValue.isEmptyLine;
957
1023
  const currLen = value.length;
958
1024
  if (isEmptyLine) continue;
959
1025
  if (currLen > logicDentLen) {
@@ -989,18 +1055,17 @@ const _Tokenizer = class _Tokenizer {
989
1055
  }
990
1056
  setCode(code) {
991
1057
  this.code = "\n" + code.trimEnd() + `
992
- ${_Tokenizer.EofId}`;
1058
+ ${Tokenizer.EofId}`;
993
1059
  }
994
1060
  tokenize() {
995
- var _a, _b;
996
1061
  do {
997
1062
  this.nextToken();
998
- console.log("token:", TokenType[(_a = this.token) == null ? void 0 : _a.type], JSON.stringify(((_b = this.token) == null ? void 0 : _b.value) || ""));
1063
+ console.log("token:", TokenType[this.token?.type], JSON.stringify(this.token?.value || ""));
999
1064
  } while (!this.isEof());
1000
1065
  }
1001
1066
  isEof() {
1002
1067
  if (!this.token) return false;
1003
- return this.token.type & TokenType.Identifier && this.token.value === _Tokenizer.EofId;
1068
+ return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
1004
1069
  }
1005
1070
  setToken(type, value) {
1006
1071
  this.token = {
@@ -1163,7 +1228,11 @@ ${_Tokenizer.EofId}`;
1163
1228
  return true;
1164
1229
  }
1165
1230
  brace() {
1166
- let inComment, inString, count = 0, value = "", backslashCount = 0;
1231
+ let inComment,
1232
+ inString,
1233
+ count = 0,
1234
+ value = "",
1235
+ backslashCount = 0;
1167
1236
  while (1) {
1168
1237
  const char = this.code[this.i];
1169
1238
  const nextChar = this.code[this.i + 1];
@@ -1254,7 +1323,9 @@ ${_Tokenizer.EofId}`;
1254
1323
  };
1255
1324
  }
1256
1325
  dent() {
1257
- const { value, isEmptyLine } = this.getDentValue();
1326
+ const _this$getDentValue2 = this.getDentValue(),
1327
+ value = _this$getDentValue2.value,
1328
+ isEmptyLine = _this$getDentValue2.isEmptyLine;
1258
1329
  if (isEmptyLine) {
1259
1330
  this.needIndent = true;
1260
1331
  return;
@@ -1273,7 +1344,7 @@ ${_Tokenizer.EofId}`;
1273
1344
  return indentHasLen;
1274
1345
  }
1275
1346
  if (currLen < prevLen) {
1276
- for (let i = this.dentStack.length; i--; ) {
1347
+ for (let i = this.dentStack.length; i--;) {
1277
1348
  const expLen = this.dentStack[i];
1278
1349
  if (currLen === expLen) break;
1279
1350
  if (currLen > expLen) {
@@ -1304,7 +1375,7 @@ ${_Tokenizer.EofId}`;
1304
1375
  if (this.useDedentAsEof) {
1305
1376
  this.setToken(TokenType.Dedent, "");
1306
1377
  } else {
1307
- this.setToken(TokenType.Identifier, _Tokenizer.EofId);
1378
+ this.setToken(TokenType.Identifier, Tokenizer.EofId);
1308
1379
  }
1309
1380
  } else {
1310
1381
  if (this.useDedentAsEof) {
@@ -1317,7 +1388,7 @@ ${_Tokenizer.EofId}`;
1317
1388
  this.waitingTokens.push({
1318
1389
  type: TokenType.Identifier,
1319
1390
  typeName: TokenType[TokenType.Identifier],
1320
- value: _Tokenizer.EofId
1391
+ value: Tokenizer.EofId
1321
1392
  });
1322
1393
  }
1323
1394
  }
@@ -1335,7 +1406,7 @@ ${_Tokenizer.EofId}`;
1335
1406
  value += nextC;
1336
1407
  this.i++;
1337
1408
  }
1338
- if (value === _Tokenizer.EofId && this.useDedentAsEof) {
1409
+ if (value === Tokenizer.EofId && this.useDedentAsEof) {
1339
1410
  this.setToken(TokenType.Dedent, "");
1340
1411
  return;
1341
1412
  }
@@ -1390,15 +1461,13 @@ ${_Tokenizer.EofId}`;
1390
1461
  this.setCode(code + fragments[fragments.length - 1]);
1391
1462
  }
1392
1463
  }
1393
- };
1394
- /** Eof 标识符的值 */
1395
- _Tokenizer.EofId = `__EOF__${Date.now()}`;
1396
- _Tokenizer.DedentId = `__DEDENT__${Date.now()}`;
1397
- let Tokenizer = _Tokenizer;
1464
+ }
1398
1465
 
1399
1466
  function bobe(fragments, ...values) {
1400
1467
  const ui = function ui2(isSub) {
1401
- const tokenizer = new Tokenizer(({ i }) => {
1468
+ const tokenizer = new Tokenizer(({
1469
+ i
1470
+ }) => {
1402
1471
  return values[i];
1403
1472
  }, isSub);
1404
1473
  tokenizer.init(Array.from(fragments));