bobe 0.0.31 → 0.0.33

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.
@@ -0,0 +1,2049 @@
1
+ 'use strict';
2
+
3
+ var bobeShared = require('bobe-shared');
4
+ var aoye = require('aoye');
5
+
6
+ let TokenType = function (TokenType) {
7
+ TokenType[TokenType["NewLine"] = 1] = "NewLine";
8
+ TokenType[TokenType["Indent"] = 2] = "Indent";
9
+ TokenType[TokenType["Dedent"] = 4] = "Dedent";
10
+ TokenType[TokenType["Identifier"] = 8] = "Identifier";
11
+ TokenType[TokenType["Assign"] = 16] = "Assign";
12
+ TokenType[TokenType["Pipe"] = 32] = "Pipe";
13
+ TokenType[TokenType["Eof"] = 64] = "Eof";
14
+ TokenType[TokenType["InsertionExp"] = 128] = "InsertionExp";
15
+ TokenType[TokenType["Semicolon"] = 256] = "Semicolon";
16
+ TokenType[TokenType["StaticInsExp"] = 512] = "StaticInsExp";
17
+ return TokenType;
18
+ }({});
19
+ let FakeType = function (FakeType) {
20
+ FakeType[FakeType["If"] = 1] = "If";
21
+ FakeType[FakeType["Fail"] = 2] = "Fail";
22
+ FakeType[FakeType["Else"] = 4] = "Else";
23
+ FakeType[FakeType["For"] = 8] = "For";
24
+ FakeType[FakeType["Component"] = 16] = "Component";
25
+ FakeType[FakeType["Fragment"] = 32] = "Fragment";
26
+ FakeType[FakeType["ForItem"] = 64] = "ForItem";
27
+ return FakeType;
28
+ }({});
29
+ const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
30
+ const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
31
+ FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment;
32
+ const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
33
+ let NodeSort = function (NodeSort) {
34
+ NodeSort[NodeSort["Logic"] = 1] = "Logic";
35
+ NodeSort[NodeSort["Real"] = 2] = "Real";
36
+ NodeSort[NodeSort["Component"] = 4] = "Component";
37
+ NodeSort[NodeSort["CtxProvider"] = 8] = "CtxProvider";
38
+ NodeSort[NodeSort["TokenizerSwitcher"] = 16] = "TokenizerSwitcher";
39
+ return NodeSort;
40
+ }({});
41
+ (function (TerpEvt) {
42
+ TerpEvt["AllAttrGot"] = "all-attr-got";
43
+ TerpEvt["HandledComponentNode"] = "handled-component-node";
44
+ return TerpEvt;
45
+ })({});
46
+
47
+ class Tokenizer {
48
+ TabSize = 2;
49
+ Tab = Array.from({
50
+ length: this.TabSize
51
+ }, () => ' ').join('');
52
+ static EofId = `__EOF__${Date.now()}`;
53
+ static DedentId = `__DEDENT__${Date.now()}`;
54
+ needIndent = false;
55
+ isFirstToken = true;
56
+ dentStack = [0];
57
+ i = 0;
58
+ line = 0;
59
+ column = 0;
60
+ preCol = 0;
61
+ preI = 0;
62
+ needLoc = false;
63
+ handledTokens = [];
64
+ waitingTokens = new bobeShared.Queue();
65
+ source = '';
66
+ constructor(hook, useDedentAsEof) {
67
+ this.hook = hook;
68
+ this.useDedentAsEof = useDedentAsEof;
69
+ if (useDedentAsEof) {
70
+ this.setToken(TokenType.Indent, '');
71
+ this.isFirstToken = true;
72
+ }
73
+ }
74
+ next() {
75
+ {
76
+ const char = this.code[this.i];
77
+ if (char === '\n') {
78
+ this.line++;
79
+ this.column = 0;
80
+ } else {
81
+ this.column++;
82
+ }
83
+ }
84
+ this.i++;
85
+ }
86
+ getCurrentPos() {
87
+ return {
88
+ offset: this.i,
89
+ line: this.line,
90
+ column: this.column
91
+ };
92
+ }
93
+ resume(_snapshot) {
94
+ this.token = undefined;
95
+ this.needIndent = false;
96
+ this.isFirstToken = true;
97
+ this.dentStack = [0];
98
+ Object.assign(this, _snapshot);
99
+ }
100
+ snapshot(keys) {
101
+ const snap = {
102
+ i: this.i,
103
+ waitingTokens: this.waitingTokens.clone()
104
+ };
105
+ if (keys) {
106
+ for (const k of keys) {
107
+ snap[k] = this[k];
108
+ if (k === 'dentStack') {
109
+ snap[k] = this[k].slice();
110
+ }
111
+ }
112
+ }
113
+ return snap;
114
+ }
115
+ skip() {
116
+ const logicDentLen = this.dentStack[this.dentStack.length - 1];
117
+ let needIndent = false;
118
+ let skipFragment = ``;
119
+ this.token = undefined;
120
+ while (1) {
121
+ const char = this.code[this.i];
122
+ if (char === '\n') {
123
+ needIndent = true;
124
+ skipFragment += char;
125
+ this.next();
126
+ continue;
127
+ }
128
+ if (!needIndent) {
129
+ skipFragment += char;
130
+ this.next();
131
+ continue;
132
+ }
133
+ needIndent = false;
134
+ const _this$getDentValue = this.getDentValue(),
135
+ value = _this$getDentValue.value,
136
+ isEmptyLine = _this$getDentValue.isEmptyLine;
137
+ const currLen = value.length;
138
+ if (isEmptyLine) continue;
139
+ if (currLen > logicDentLen) {
140
+ skipFragment += value;
141
+ } else {
142
+ for (let i = this.dentStack.length - 1; i >= 0; i--) {
143
+ const expLen = this.dentStack[i];
144
+ if (currLen === expLen) break;
145
+ if (currLen > expLen) {
146
+ throw SyntaxError(`缩进错误,缩进长度不匹配`);
147
+ }
148
+ if (this.shorterThanBaseDentEof()) {
149
+ break;
150
+ }
151
+ this.dentStack.pop();
152
+ if (!this.token) {
153
+ this.setToken(TokenType.Dedent, String(expLen));
154
+ } else {
155
+ this.waitingTokens.push({
156
+ type: TokenType.Dedent,
157
+ typeName: TokenType[TokenType.Dedent],
158
+ value: String(expLen),
159
+ loc: null
160
+ });
161
+ }
162
+ }
163
+ break;
164
+ }
165
+ }
166
+ if (!this.token) {
167
+ this.nextToken();
168
+ }
169
+ return skipFragment;
170
+ }
171
+ setCode(code) {
172
+ this.code = '\n' + code.trimEnd() + `\n${Tokenizer.EofId}`;
173
+ }
174
+ tokenize() {
175
+ do {
176
+ this.nextToken();
177
+ console.log('token:', TokenType[this.token?.type], JSON.stringify(this.token?.value || ''));
178
+ } while (!this.isEof());
179
+ }
180
+ isEof() {
181
+ if (!this.token) return false;
182
+ return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
183
+ }
184
+ setToken(type, value) {
185
+ this.token = {
186
+ type,
187
+ typeName: TokenType[type],
188
+ value,
189
+ loc: this.needLoc ? {
190
+ start: {
191
+ offset: this.preI,
192
+ line: this.line,
193
+ column: this.preCol
194
+ },
195
+ end: {
196
+ offset: this.i + 1,
197
+ line: this.line,
198
+ column: this.column + 1
199
+ },
200
+ source: this.code.slice(this.preI, this.i + 1)
201
+ } : null
202
+ };
203
+ this.isFirstToken = false;
204
+ }
205
+ nextToken() {
206
+ try {
207
+ if (this.isEof()) {
208
+ return this.token;
209
+ }
210
+ this.token = undefined;
211
+ if (this.waitingTokens.len) {
212
+ const item = this.waitingTokens.shift();
213
+ this.setToken(item.type, item.value);
214
+ return this.token;
215
+ }
216
+ outer: while (1) {
217
+ if (this.needIndent) {
218
+ this.dent();
219
+ } else {
220
+ const char = this.code[this.i];
221
+ switch (char) {
222
+ case '\t':
223
+ case ' ':
224
+ break;
225
+ case '\n':
226
+ this.newLine();
227
+ this.needIndent = true;
228
+ break;
229
+ case '=':
230
+ this.assignment();
231
+ break;
232
+ case '|':
233
+ this.pipe();
234
+ break;
235
+ case ';':
236
+ this.setToken(TokenType.Semicolon, ';');
237
+ break;
238
+ default:
239
+ if (true) {
240
+ this.preI = this.i;
241
+ this.preCol = this.column;
242
+ this.needLoc = true;
243
+ }
244
+ switch (char) {
245
+ case "'":
246
+ case '"':
247
+ this.str(char);
248
+ break;
249
+ case '{':
250
+ const braceToken = this.brace();
251
+ this.setToken(TokenType.InsertionExp, braceToken);
252
+ break;
253
+ case '$':
254
+ const handled = this.staticIns();
255
+ if (handled) break;
256
+ default:
257
+ if (bobeShared.isNum(char)) {
258
+ this.number(char);
259
+ break;
260
+ }
261
+ if (typeof char === 'string' && bobeShared.matchIdStart2(char, 0)) {
262
+ this.identifier(char);
263
+ }
264
+ break;
265
+ }
266
+ if (true) {
267
+ this.needLoc = false;
268
+ }
269
+ break;
270
+ }
271
+ this.next();
272
+ }
273
+ if (this.token) {
274
+ break;
275
+ }
276
+ }
277
+ return this.token;
278
+ } catch (error) {
279
+ console.error(error);
280
+ return this.token;
281
+ } finally {
282
+ this.handledTokens.push(this.token);
283
+ }
284
+ }
285
+ condExp() {
286
+ {
287
+ this.preCol = this.column;
288
+ this.preI = this.i;
289
+ this.needLoc = true;
290
+ }
291
+ let value = '';
292
+ this.token = null;
293
+ try {
294
+ if (this.code[this.i] === '\n') {
295
+ this.setToken(TokenType.Identifier, true);
296
+ return this.token;
297
+ }
298
+ while (this.code[this.i + 1] !== '\n') {
299
+ value += this.code[this.i];
300
+ this.next();
301
+ }
302
+ value += this.code[this.i];
303
+ const trimmed = value.trim();
304
+ this.setToken(TokenType.Identifier, trimmed ? value : true);
305
+ return this.token;
306
+ } finally {
307
+ this.next();
308
+ this.handledTokens.push(this.token);
309
+ {
310
+ this.needLoc = false;
311
+ }
312
+ }
313
+ }
314
+ jsExp() {
315
+ {
316
+ this.preCol = this.column;
317
+ this.preI = this.i;
318
+ this.needLoc = true;
319
+ }
320
+ this.token = null;
321
+ let value = '';
322
+ try {
323
+ const char = this.code[this.i];
324
+ if (char === ';' || char === '\n') {
325
+ this.setToken(TokenType.Identifier, value);
326
+ return this.token;
327
+ }
328
+ let nextC = this.code[this.i + 1];
329
+ while (nextC !== ';' && nextC !== '\n') {
330
+ value += this.code[this.i];
331
+ this.next();
332
+ nextC = this.code[this.i + 1];
333
+ }
334
+ value += this.code[this.i];
335
+ this.setToken(TokenType.Identifier, value);
336
+ return this.token;
337
+ } finally {
338
+ this.next();
339
+ this.handledTokens.push(this.token);
340
+ {
341
+ this.needLoc = false;
342
+ }
343
+ }
344
+ }
345
+ peekChar() {
346
+ let i = this.i;
347
+ while (this.code[i] === ' ' || this.code[i] === '\t') {
348
+ i++;
349
+ }
350
+ return this.code[i];
351
+ }
352
+ assignment() {
353
+ this.setToken(TokenType.Assign, '=');
354
+ }
355
+ pipe() {
356
+ this.setToken(TokenType.Pipe, '|');
357
+ }
358
+ staticIns() {
359
+ let nextC = this.code[this.i + 1];
360
+ if (nextC !== '{') {
361
+ return false;
362
+ }
363
+ this.next();
364
+ let value = '';
365
+ let innerBrace = 0;
366
+ while (1) {
367
+ nextC = this.code[this.i + 1];
368
+ value += nextC;
369
+ this.next();
370
+ if (nextC === '{') {
371
+ innerBrace++;
372
+ }
373
+ if (nextC === '}') {
374
+ if (!innerBrace) {
375
+ break;
376
+ }
377
+ innerBrace--;
378
+ }
379
+ }
380
+ this.setToken(TokenType.StaticInsExp, value.slice(0, -1));
381
+ return true;
382
+ }
383
+ brace() {
384
+ let inComment,
385
+ inString,
386
+ count = 0,
387
+ value = '',
388
+ backslashCount = 0;
389
+ while (1) {
390
+ const char = this.code[this.i];
391
+ const nextChar = this.code[this.i + 1];
392
+ if (inComment === 'single' && char === '\n') {
393
+ inComment = null;
394
+ } else if (inComment === 'multi' && char === '*' && nextChar === '/') {
395
+ inComment = null;
396
+ value += this.code[this.i];
397
+ this.next();
398
+ } else if (inString) {
399
+ if (char === inString && backslashCount % 2 === 0) {
400
+ inString = null;
401
+ }
402
+ backslashCount = char === '\\' ? backslashCount + 1 : 0;
403
+ } else {
404
+ if (char === '/' && nextChar === '/') {
405
+ inComment = 'single';
406
+ value += this.code[this.i];
407
+ this.next();
408
+ } else if (char === '/' && nextChar === '*') {
409
+ inComment = 'multi';
410
+ value += this.code[this.i];
411
+ this.next();
412
+ } else if (char === "'" || char === '"' || char === '`') {
413
+ inString = char;
414
+ } else if (char === '{') {
415
+ count++;
416
+ } else if (char === '}') {
417
+ count--;
418
+ }
419
+ }
420
+ if (count === 0 && inString == null && inComment == null) {
421
+ return value.slice(1);
422
+ }
423
+ value += this.code[this.i];
424
+ this.next();
425
+ }
426
+ }
427
+ newLine() {
428
+ let value = '\n';
429
+ let nextC;
430
+ while (1) {
431
+ nextC = this.code[this.i + 1];
432
+ if (nextC !== '\n') {
433
+ break;
434
+ }
435
+ value += nextC;
436
+ this.next();
437
+ }
438
+ if (this.isFirstToken) {
439
+ return;
440
+ }
441
+ this.setToken(TokenType.NewLine, value);
442
+ }
443
+ getDentValue() {
444
+ let value = '';
445
+ let nextC;
446
+ let isEmptyLine = false;
447
+ while (1) {
448
+ const nextChar = this.code[this.i];
449
+ switch (nextChar) {
450
+ case '\t':
451
+ nextC = this.Tab;
452
+ break;
453
+ case ' ':
454
+ nextC = ' ';
455
+ break;
456
+ case '\n':
457
+ nextC = '\n';
458
+ break;
459
+ default:
460
+ nextC = '';
461
+ break;
462
+ }
463
+ if (nextC === '\n') {
464
+ isEmptyLine = true;
465
+ break;
466
+ }
467
+ if (!nextC) {
468
+ break;
469
+ }
470
+ value += nextC;
471
+ this.next();
472
+ }
473
+ return {
474
+ value,
475
+ isEmptyLine
476
+ };
477
+ }
478
+ dent() {
479
+ const _this$getDentValue2 = this.getDentValue(),
480
+ value = _this$getDentValue2.value,
481
+ isEmptyLine = _this$getDentValue2.isEmptyLine;
482
+ if (isEmptyLine) {
483
+ this.needIndent = true;
484
+ return;
485
+ }
486
+ this.needIndent = false;
487
+ if (this.isFirstToken) {
488
+ this.dentStack[0] = value.length;
489
+ return;
490
+ }
491
+ let currLen = value.length;
492
+ const indentHasLen = currLen > 0;
493
+ const prevLen = this.dentStack[this.dentStack.length - 1];
494
+ if (currLen > prevLen) {
495
+ this.dentStack.push(currLen);
496
+ this.setToken(TokenType.Indent, currLen);
497
+ return indentHasLen;
498
+ }
499
+ if (currLen < prevLen) {
500
+ for (let i = this.dentStack.length; i--;) {
501
+ const expLen = this.dentStack[i];
502
+ if (currLen === expLen) break;
503
+ if (currLen > expLen) {
504
+ throw SyntaxError('缩进大小不统一');
505
+ }
506
+ if (this.shorterThanBaseDentEof()) {
507
+ return;
508
+ }
509
+ this.dentStack.pop();
510
+ if (!this.token) {
511
+ this.setToken(TokenType.Dedent, String(expLen));
512
+ } else {
513
+ this.waitingTokens.push({
514
+ type: TokenType.Dedent,
515
+ typeName: TokenType[TokenType.Dedent],
516
+ value: String(expLen),
517
+ loc: null
518
+ });
519
+ }
520
+ }
521
+ return indentHasLen;
522
+ }
523
+ return indentHasLen;
524
+ }
525
+ shorterThanBaseDentEof() {
526
+ const yes = this.dentStack.length === 1;
527
+ if (yes) {
528
+ if (!this.token) {
529
+ if (this.useDedentAsEof) {
530
+ this.setToken(TokenType.Dedent, '');
531
+ } else {
532
+ this.setToken(TokenType.Identifier, Tokenizer.EofId);
533
+ }
534
+ } else {
535
+ if (this.useDedentAsEof) {
536
+ this.waitingTokens.push({
537
+ type: TokenType.Dedent,
538
+ typeName: TokenType[TokenType.Dedent],
539
+ value: '',
540
+ loc: null
541
+ });
542
+ } else {
543
+ this.waitingTokens.push({
544
+ type: TokenType.Identifier,
545
+ typeName: TokenType[TokenType.Identifier],
546
+ value: Tokenizer.EofId,
547
+ loc: null
548
+ });
549
+ }
550
+ }
551
+ }
552
+ return yes;
553
+ }
554
+ identifier(char) {
555
+ let value = char;
556
+ let nextC;
557
+ while (1) {
558
+ nextC = this.code[this.i + 1];
559
+ if (typeof nextC !== 'string' || !bobeShared.matchIdStart2(nextC, 0)) {
560
+ break;
561
+ }
562
+ value += nextC;
563
+ this.next();
564
+ }
565
+ if (value === Tokenizer.EofId && this.useDedentAsEof) {
566
+ this.setToken(TokenType.Dedent, '');
567
+ return;
568
+ }
569
+ let realValue = value === 'null' ? null : value === 'undefined' ? undefined : value === 'false' ? false : value === 'true' ? true : value;
570
+ this.setToken(TokenType.Identifier, realValue);
571
+ }
572
+ str(char) {
573
+ let value = '';
574
+ let nextC;
575
+ let continuousBackslashCount = 0;
576
+ while (1) {
577
+ nextC = this.code[this.i + 1];
578
+ const memoCount = continuousBackslashCount;
579
+ if (nextC === '\\') {
580
+ continuousBackslashCount++;
581
+ } else {
582
+ continuousBackslashCount = 0;
583
+ }
584
+ this.next();
585
+ if (nextC === char && memoCount % 2 === 0) {
586
+ break;
587
+ }
588
+ value += nextC;
589
+ }
590
+ this.setToken(TokenType.Identifier, value);
591
+ }
592
+ number(char) {
593
+ let value = char;
594
+ let nextC;
595
+ while (1) {
596
+ nextC = this.code[this.i + 1];
597
+ if (!bobeShared.isNum(nextC)) {
598
+ break;
599
+ }
600
+ value += nextC;
601
+ this.next();
602
+ }
603
+ this.setToken(TokenType.Identifier, Number(value));
604
+ }
605
+ eof() {
606
+ this.setToken(TokenType.Eof, 'End Of File');
607
+ }
608
+ HookId = '_h_o_o_k_';
609
+ hookI = 0;
610
+ _hook = props => {
611
+ const value = this.token.value;
612
+ const isDynamicHook = this.token.type & TokenType.InsertionExp;
613
+ let isStaticHook;
614
+ {
615
+ isStaticHook = Boolean(this.token.type & TokenType.StaticInsExp);
616
+ }
617
+ const hookType = isDynamicHook ? 'dynamic' : isStaticHook ? 'static' : undefined;
618
+ if (this.hook && isStaticHook) {
619
+ const hookI = Number(value.slice(this.HookId.length));
620
+ const res = this.hook({
621
+ ...props,
622
+ HookId: this.HookId,
623
+ i: hookI
624
+ });
625
+ return [hookType, res, hookI];
626
+ } else if (isDynamicHook) {
627
+ return [hookType, value];
628
+ }
629
+ return [hookType, value];
630
+ };
631
+ init(fragments) {
632
+ if (typeof fragments === 'string') {
633
+ this.setCode(fragments);
634
+ } else {
635
+ let code = '';
636
+ for (let i = 0; i < fragments.length - 1; i++) {
637
+ const fragment = fragments[i];
638
+ code += fragment + `${this.HookId}${i}`;
639
+ }
640
+ this.setCode(code + fragments[fragments.length - 1]);
641
+ }
642
+ }
643
+ }
644
+
645
+ var NodeType = function (NodeType) {
646
+ NodeType["Element"] = "Element";
647
+ NodeType["Text"] = "Text";
648
+ NodeType["Interpolation"] = "Interpolation";
649
+ NodeType["Property"] = "Property";
650
+ NodeType["PropertyKey"] = "PropertyKey";
651
+ NodeType["StaticValue"] = "StaticValue";
652
+ NodeType["DynamicValue"] = "DynamicValue";
653
+ NodeType["Program"] = "Program";
654
+ NodeType["If"] = "If";
655
+ NodeType["Else"] = "Else";
656
+ NodeType["Fail"] = "Fail";
657
+ NodeType["For"] = "For";
658
+ NodeType["Component"] = "Component";
659
+ NodeType["Fragment"] = "Fragment";
660
+ return NodeType;
661
+ }(NodeType || {});
662
+
663
+ function _applyDecs2311(e, t, n, r, o, i) {
664
+ var a,
665
+ c,
666
+ u,
667
+ s,
668
+ f,
669
+ l,
670
+ p,
671
+ d = Symbol.metadata || Symbol.for("Symbol.metadata"),
672
+ m = Object.defineProperty,
673
+ h = Object.create,
674
+ y = [h(null), h(null)],
675
+ v = t.length;
676
+ function g(t, n, r) {
677
+ return function (o, i) {
678
+ n && (i = o, o = e);
679
+ for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
680
+ return r ? i : o;
681
+ };
682
+ }
683
+ function b(e, t, n, r) {
684
+ if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
685
+ return e;
686
+ }
687
+ function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
688
+ function d(e) {
689
+ if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
690
+ }
691
+ var h = [].concat(t[0]),
692
+ v = t[3],
693
+ w = !u,
694
+ D = 1 === o,
695
+ S = 3 === o,
696
+ j = 4 === o,
697
+ E = 2 === o;
698
+ function I(t, n, r) {
699
+ return function (o, i) {
700
+ return n && (i = o, o = e), r && r(o), P[t].call(o, i);
701
+ };
702
+ }
703
+ if (!w) {
704
+ var P = {},
705
+ k = [],
706
+ F = S ? "get" : j || D ? "set" : "value";
707
+ if (f ? (l || D ? P = {
708
+ get: _setFunctionName(function () {
709
+ return v(this);
710
+ }, r, "get"),
711
+ set: function (e) {
712
+ t[4](this, e);
713
+ }
714
+ } : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
715
+ if ((c = y[+s][r]) && 7 !== (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
716
+ y[+s][r] = o < 3 ? 1 : o;
717
+ }
718
+ }
719
+ for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
720
+ var T = b(h[O], "A decorator", "be", true),
721
+ z = n ? h[O - 1] : void 0,
722
+ A = {},
723
+ H = {
724
+ kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
725
+ name: r,
726
+ metadata: a,
727
+ addInitializer: function (e, t) {
728
+ if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
729
+ b(t, "An initializer", "be", true), i.push(t);
730
+ }.bind(null, A)
731
+ };
732
+ if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);else if (H.static = s, H.private = f, c = H.access = {
733
+ has: f ? p.bind() : function (e) {
734
+ return r in e;
735
+ }
736
+ }, j || (c.get = f ? E ? function (e) {
737
+ return d(e), P.value;
738
+ } : I("get", 0, d) : function (e) {
739
+ return e[r];
740
+ }), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
741
+ e[r] = t;
742
+ }), N = T.call(z, D ? {
743
+ get: P.get,
744
+ set: P.set
745
+ } : P[F], H), A.v = 1, D) {
746
+ if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
747
+ } else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
748
+ }
749
+ return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
750
+ }
751
+ function w(e) {
752
+ return m(e, d, {
753
+ configurable: true,
754
+ enumerable: true,
755
+ value: a
756
+ });
757
+ }
758
+ return a = h(null == a ? null : a), f = [], l = function (e) {
759
+ e && f.push(g(e));
760
+ }, p = function (t, r) {
761
+ for (var i = 0; i < n.length; i++) {
762
+ var a = n[i],
763
+ c = a[1],
764
+ l = 7 & c;
765
+ if ((8 & c) == t && !l == r) {
766
+ var p = a[2],
767
+ d = !!a[3],
768
+ m = 16 & c;
769
+ applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
770
+ return _checkInRHS(t) === e;
771
+ } : o);
772
+ }
773
+ }
774
+ }, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
775
+ e: c,
776
+ get c() {
777
+ var n = [];
778
+ return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
779
+ }
780
+ };
781
+ }
782
+ function _arrayLikeToArray(r, a) {
783
+ (null == a || a > r.length) && (a = r.length);
784
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
785
+ return n;
786
+ }
787
+ function _arrayWithHoles(r) {
788
+ if (Array.isArray(r)) return r;
789
+ }
790
+ function _checkInRHS(e) {
791
+ if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
792
+ return e;
793
+ }
794
+ function _iterableToArrayLimit(r, l) {
795
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
796
+ if (null != t) {
797
+ var e,
798
+ n,
799
+ i,
800
+ u,
801
+ a = [],
802
+ f = true,
803
+ o = false;
804
+ try {
805
+ if (i = (t = t.call(r)).next, 0 === l) {
806
+ if (Object(t) !== t) return;
807
+ f = !1;
808
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
809
+ } catch (r) {
810
+ o = true, n = r;
811
+ } finally {
812
+ try {
813
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
814
+ } finally {
815
+ if (o) throw n;
816
+ }
817
+ }
818
+ return a;
819
+ }
820
+ }
821
+ function _nonIterableRest() {
822
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
823
+ }
824
+ function _objectWithoutProperties(e, t) {
825
+ if (null == e) return {};
826
+ var o,
827
+ r,
828
+ i = _objectWithoutPropertiesLoose(e, t);
829
+ if (Object.getOwnPropertySymbols) {
830
+ var n = Object.getOwnPropertySymbols(e);
831
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
832
+ }
833
+ return i;
834
+ }
835
+ function _objectWithoutPropertiesLoose(r, e) {
836
+ if (null == r) return {};
837
+ var t = {};
838
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
839
+ if (-1 !== e.indexOf(n)) continue;
840
+ t[n] = r[n];
841
+ }
842
+ return t;
843
+ }
844
+ function _setFunctionName(e, t, n) {
845
+ "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
846
+ try {
847
+ Object.defineProperty(e, "name", {
848
+ configurable: !0,
849
+ value: n ? n + " " + t : t
850
+ });
851
+ } catch (e) {}
852
+ return e;
853
+ }
854
+ function _slicedToArray(r, e) {
855
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
856
+ }
857
+ function _toPrimitive(t, r) {
858
+ if ("object" != typeof t || !t) return t;
859
+ var e = t[Symbol.toPrimitive];
860
+ if (void 0 !== e) {
861
+ var i = e.call(t, r);
862
+ if ("object" != typeof i) return i;
863
+ throw new TypeError("@@toPrimitive must return a primitive value.");
864
+ }
865
+ return ("string" === r ? String : Number)(t);
866
+ }
867
+ function _toPropertyKey(t) {
868
+ var i = _toPrimitive(t, "string");
869
+ return "symbol" == typeof i ? i : i + "";
870
+ }
871
+ function _unsupportedIterableToArray(r, a) {
872
+ if (r) {
873
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
874
+ var t = {}.toString.call(r).slice(8, -1);
875
+ 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;
876
+ }
877
+ }
878
+
879
+ let _initProto;
880
+ class Compiler {
881
+ static {
882
+ var _applyDecs$e = _slicedToArray(_applyDecs2311(this, [], [[NodeHook, 2, "parseProgram"], [[NodeHook, NodeLoc], 2, "parseComponentNode"], [[NodeHook, NodeLoc], 2, "parseElementNode"], [[NodeHook, NodeLoc], 2, "parseConditionalNode"], [[NodeHook, NodeLoc], 2, "parseLoopNode"], [NodeHook, 2, "parseProperty"], [[NodeHook, TokenLoc], 2, "parsePropertyKey"], [[NodeHook, TokenLoc], 2, "parsePropertyValue"]]).e, 1);
883
+ _initProto = _applyDecs$e[0];
884
+ }
885
+ constructor(tokenizer, hooks = {}) {
886
+ this.tokenizer = tokenizer;
887
+ this.hooks = hooks;
888
+ _initProto(this);
889
+ }
890
+ parseProgram() {
891
+ this.tokenizer.nextToken();
892
+ const body = [];
893
+ while (!this.tokenizer.isEof()) {
894
+ const node = this.templateNode();
895
+ if (node) {
896
+ body.push(node);
897
+ }
898
+ }
899
+ return {
900
+ type: NodeType.Program,
901
+ body,
902
+ loc: {
903
+ start: {
904
+ offset: 0,
905
+ line: 1,
906
+ column: 0
907
+ },
908
+ end: {
909
+ offset: this.tokenizer.preI,
910
+ line: this.tokenizer.line,
911
+ column: this.tokenizer.column
912
+ },
913
+ source: this.tokenizer.code
914
+ }
915
+ };
916
+ }
917
+ handleChildren() {
918
+ const children = [];
919
+ if (this.tokenizer.token.type & TokenType.Indent) {
920
+ this.tokenizer.nextToken();
921
+ while (!(this.tokenizer.token.type & TokenType.Dedent) && !this.tokenizer.isEof()) {
922
+ const child = this.templateNode();
923
+ if (child) {
924
+ children.push(child);
925
+ }
926
+ }
927
+ if (this.tokenizer.token.type & TokenType.Dedent) {
928
+ this.tokenizer.nextToken();
929
+ }
930
+ }
931
+ return children;
932
+ }
933
+ templateNode() {
934
+ this.tokenizer.token;
935
+ const _this$tokenizer$_hook = this.tokenizer._hook({}),
936
+ _this$tokenizer$_hook2 = _slicedToArray(_this$tokenizer$_hook, 2),
937
+ hookType = _this$tokenizer$_hook2[0],
938
+ value = _this$tokenizer$_hook2[1];
939
+ if (value === 'if' || value === 'else' || value === 'fail') {
940
+ return this.parseConditionalNode();
941
+ }
942
+ if (value === 'for') {
943
+ return this.parseLoopNode();
944
+ }
945
+ if (hookType) {
946
+ return this.parseComponentNode();
947
+ }
948
+ return this.parseElementNode();
949
+ }
950
+ parseComponentNode(node) {
951
+ const tagToken = this.tokenizer.token;
952
+ const tagName = tagToken.value;
953
+ this.tokenizer.nextToken();
954
+ const props = this.headerLineAndExtensions();
955
+ node.type = NodeType.Component;
956
+ node.componentName = tagName;
957
+ node.props = props;
958
+ this.hooks.parseComponentNode?.propsAdded?.call(this, node);
959
+ const children = this.handleChildren();
960
+ node.children = children;
961
+ return node;
962
+ }
963
+ parseElementNode(node) {
964
+ const tagToken = this.tokenizer.token;
965
+ const tagName = tagToken.value;
966
+ this.tokenizer.nextToken();
967
+ const props = this.headerLineAndExtensions();
968
+ node.type = NodeType.Element;
969
+ node.tagName = tagName;
970
+ node.props = props;
971
+ this.hooks.parseElementNode?.propsAdded?.call(this, node);
972
+ const children = this.handleChildren();
973
+ node.children = children;
974
+ return node;
975
+ }
976
+ parseConditionalNode(node) {
977
+ const keyword = this.tokenizer.token.value;
978
+ const conditionToken = this.tokenizer.condExp();
979
+ const condition = conditionToken.value;
980
+ this.tokenizer.nextToken();
981
+ this.tokenizer.nextToken();
982
+ node.type = keyword === 'if' ? NodeType.If : keyword === 'else' ? NodeType.Else : NodeType.Fail;
983
+ node.condition = condition;
984
+ this.hooks.parseConditionalNode?.propsAdded?.call(this, node);
985
+ const children = this.handleChildren();
986
+ node.children = children;
987
+ return node;
988
+ }
989
+ parseLoopNode(node) {
990
+ const collection = this.tokenizer.nextToken().value;
991
+ this.tokenizer.nextToken();
992
+ const itemToken = this.tokenizer.nextToken();
993
+ const isDestruct = itemToken.type === TokenType.InsertionExp;
994
+ let item = isDestruct ? `{${itemToken.value}}` : itemToken.value;
995
+ let char = this.tokenizer.peekChar(),
996
+ key,
997
+ index;
998
+ if (char === ';') {
999
+ this.tokenizer.nextToken();
1000
+ if (this.tokenizer.peekChar() !== '\n') key = this.tokenizer.jsExp().value;
1001
+ } else if (char === '\n') ; else {
1002
+ index = this.tokenizer.nextToken().value;
1003
+ if (this.tokenizer.peekChar() === ';') {
1004
+ this.tokenizer.nextToken();
1005
+ if (this.tokenizer.peekChar() !== '\n') key = this.tokenizer.jsExp().value;
1006
+ }
1007
+ }
1008
+ this.tokenizer.nextToken();
1009
+ this.tokenizer.nextToken();
1010
+ node.type = NodeType.For;
1011
+ node.collection = collection;
1012
+ node.item = item;
1013
+ node.index = index;
1014
+ node.key = key;
1015
+ this.hooks.parseLoopNode?.propsAdded?.call(this, node);
1016
+ const children = this.handleChildren();
1017
+ node.children = children;
1018
+ return node;
1019
+ }
1020
+ headerLineAndExtensions() {
1021
+ const props = [];
1022
+ props.push(...this.attributeList());
1023
+ if (this.tokenizer.token.type & TokenType.NewLine) {
1024
+ this.tokenizer.nextToken();
1025
+ }
1026
+ while (this.tokenizer.token.type & TokenType.Pipe) {
1027
+ this.tokenizer.nextToken();
1028
+ props.push(...this.attributeList());
1029
+ if (this.tokenizer.token.type & TokenType.NewLine) {
1030
+ this.tokenizer.nextToken();
1031
+ }
1032
+ }
1033
+ return props;
1034
+ }
1035
+ attributeList() {
1036
+ const props = [];
1037
+ while (!(this.tokenizer.token.type & TokenType.NewLine) && !(this.tokenizer.token.type & TokenType.Pipe) && !this.tokenizer.isEof()) {
1038
+ props.push(this.parseProperty());
1039
+ }
1040
+ return props;
1041
+ }
1042
+ parseProperty(node) {
1043
+ node.type = NodeType.Property;
1044
+ node.key = this.parsePropertyKey();
1045
+ const token = this.tokenizer.nextToken();
1046
+ if (token.value === '=') {
1047
+ this.tokenizer.nextToken();
1048
+ node.value = this.parsePropertyValue();
1049
+ this.tokenizer.nextToken();
1050
+ }
1051
+ node.loc.start = node.key.loc.start;
1052
+ node.loc.end = node.value ? node.value.loc.end : node.key.loc.end;
1053
+ node.loc.source = this.tokenizer.code.slice(node.loc.start.offset, node.loc.end.offset);
1054
+ return node;
1055
+ }
1056
+ parsePropertyKey(node) {
1057
+ node.type = NodeType.PropertyKey;
1058
+ node.key = this.tokenizer.token.value;
1059
+ return node;
1060
+ }
1061
+ parsePropertyValue(node) {
1062
+ const _this$tokenizer$_hook3 = this.tokenizer._hook({}),
1063
+ _this$tokenizer$_hook4 = _slicedToArray(_this$tokenizer$_hook3, 2),
1064
+ hookType = _this$tokenizer$_hook4[0],
1065
+ value = _this$tokenizer$_hook4[1];
1066
+ node.type = hookType === 'dynamic' ? NodeType.DynamicValue : NodeType.StaticValue;
1067
+ node.value = value;
1068
+ return node;
1069
+ }
1070
+ }
1071
+ function NodeLoc(target, context) {
1072
+ return function (_node) {
1073
+ _node.loc.start = this.tokenizer.token.loc.start;
1074
+ const result = target.call(this, _node);
1075
+ _node.loc.end = this.tokenizer.token.loc ? this.tokenizer.token.loc.start : this.tokenizer.getCurrentPos();
1076
+ _node.loc.source = this.tokenizer.code.slice(_node.loc.start.offset, _node.loc.end.offset);
1077
+ return result;
1078
+ };
1079
+ }
1080
+ function TokenLoc(target, context) {
1081
+ return function (_node) {
1082
+ const result = target.call(this, _node);
1083
+ _node.loc = this.tokenizer.token.loc;
1084
+ return result;
1085
+ };
1086
+ }
1087
+ function NodeHook(target, context) {
1088
+ return function (_node) {
1089
+ const hook = this.hooks[context.name];
1090
+ const node = {
1091
+ loc: {}
1092
+ };
1093
+ hook?.enter?.call(this, node);
1094
+ const result = target.call(this, node);
1095
+ hook?.leave?.call(this, node);
1096
+ return result;
1097
+ };
1098
+ }
1099
+
1100
+ class MultiTypeStack {
1101
+ typeTops = {};
1102
+ length = 0;
1103
+ stack = [];
1104
+ push(value, bits) {
1105
+ const newNode = {
1106
+ value,
1107
+ types: bits,
1108
+ prevByType: {}
1109
+ };
1110
+ let bit;
1111
+ while (1) {
1112
+ bit = bits & ~bits + 1;
1113
+ if (!bit) break;
1114
+ bits &= ~bit;
1115
+ newNode.prevByType[bit] = this.typeTops[bit] || undefined;
1116
+ this.typeTops[bit] = newNode;
1117
+ }
1118
+ this.stack[this.length++] = newNode;
1119
+ }
1120
+ pop() {
1121
+ const poppedNode = this.stack[this.length - 1];
1122
+ this.stack[--this.length] = null;
1123
+ if (!poppedNode) return undefined;
1124
+ let bits = poppedNode.types;
1125
+ let bit;
1126
+ while (1) {
1127
+ bit = bits & ~bits + 1;
1128
+ if (!bit) break;
1129
+ bits &= ~bit;
1130
+ this.typeTops[bit] = poppedNode.prevByType[bit];
1131
+ }
1132
+ return [poppedNode.value, poppedNode.types];
1133
+ }
1134
+ peekByType(cat) {
1135
+ return this.typeTops[cat]?.value;
1136
+ }
1137
+ peekType() {
1138
+ return this.stack.at(-1).types;
1139
+ }
1140
+ peek() {
1141
+ return this.stack.at(-1).value;
1142
+ }
1143
+ }
1144
+
1145
+ function macInc(arr) {
1146
+ const len = arr.length;
1147
+ let candyLast = [],
1148
+ i = 0;
1149
+ while (i < len) {
1150
+ const it = arr[i];
1151
+ if (it !== -1) {
1152
+ candyLast = [i];
1153
+ break;
1154
+ }
1155
+ i++;
1156
+ }
1157
+ if (i + 1 >= len) return candyLast;
1158
+ const toPrev = new Int32Array(len);
1159
+ while (i < len) {
1160
+ const target = arr[i];
1161
+ if (target === -1) continue;
1162
+ let start = -1,
1163
+ end = candyLast.length;
1164
+ while (start + 1 < end) {
1165
+ const mid = start + end >> 1;
1166
+ if (arr[candyLast[mid]] < target) {
1167
+ start = mid;
1168
+ } else {
1169
+ end = mid;
1170
+ }
1171
+ }
1172
+ candyLast[end] = i;
1173
+ toPrev[i] = candyLast[start];
1174
+ i++;
1175
+ }
1176
+ let length = candyLast.length;
1177
+ for (let j = length - 1; j > 0; j--) {
1178
+ const prev = toPrev[candyLast[j]];
1179
+ candyLast[j - 1] = prev;
1180
+ }
1181
+ return candyLast;
1182
+ }
1183
+
1184
+ const KEY_INDEX = '__BOBE_KEY_INDEX';
1185
+
1186
+ const _excluded = ["dentStack", "isFirstToken"];
1187
+ class Interpreter {
1188
+ constructor(tokenizer) {
1189
+ this.tokenizer = tokenizer;
1190
+ }
1191
+ isLogicNode(node) {
1192
+ return node && node.__logicType & LogicalBit;
1193
+ }
1194
+ rootComponent = null;
1195
+ program(root, componentNode, before, ctxProvider) {
1196
+ this.rootComponent = componentNode;
1197
+ this.tokenizer.nextToken();
1198
+ const stack = new MultiTypeStack();
1199
+ stack.push({
1200
+ node: root,
1201
+ prev: null
1202
+ }, NodeSort.Real);
1203
+ stack.push({
1204
+ node: componentNode,
1205
+ prev: null
1206
+ }, NodeSort.Component | NodeSort.CtxProvider | NodeSort.TokenizerSwitcher);
1207
+ if (ctxProvider) {
1208
+ stack.push({
1209
+ node: ctxProvider,
1210
+ prev: null
1211
+ }, (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider);
1212
+ }
1213
+ const rootLen = stack.length;
1214
+ const ctx = this.ctx = {
1215
+ realParent: root,
1216
+ prevSibling: before,
1217
+ current: null,
1218
+ stack,
1219
+ before
1220
+ };
1221
+ const rootPulling = aoye.getPulling();
1222
+ while (1) {
1223
+ if (this.tokenizer.isEof()) {
1224
+ if (!ctx.prevSibling) ctx.prevSibling = before;
1225
+ this.handleInsert(root, ctx.current, ctx.prevSibling, componentNode);
1226
+ break;
1227
+ }
1228
+ const token = this.tokenizer.token;
1229
+ if (token.type & TokenType.Indent) {
1230
+ this.tokenizer.nextToken();
1231
+ const isLogicNode = this.isLogicNode(ctx.current);
1232
+ stack.push({
1233
+ node: ctx.current,
1234
+ prev: ctx.prevSibling
1235
+ }, !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);
1236
+ if (ctx.current.__logicType) {
1237
+ if (isLogicNode) {
1238
+ aoye.setPulling(ctx.current.effect);
1239
+ if (ctx.current.__logicType & FakeType.ForItem) {
1240
+ ctx.prevSibling = ctx.current.realBefore;
1241
+ }
1242
+ }
1243
+ } else {
1244
+ if (ctx.current) {
1245
+ ctx.realParent = ctx.current;
1246
+ }
1247
+ ctx.prevSibling = null;
1248
+ }
1249
+ ctx.current = this.declaration(ctx);
1250
+ continue;
1251
+ }
1252
+ if (ctx.current) {
1253
+ if (stack.length === rootLen && !ctx.prevSibling) {
1254
+ ctx.prevSibling = before;
1255
+ }
1256
+ this.handleInsert(ctx.realParent, ctx.current, ctx.prevSibling);
1257
+ }
1258
+ if (this.tokenizer.token.type & TokenType.Dedent) {
1259
+ this.tokenizer.nextToken();
1260
+ const _stack$pop = stack.pop(),
1261
+ _stack$pop2 = _slicedToArray(_stack$pop, 2),
1262
+ _stack$pop2$ = _stack$pop2[0],
1263
+ parent = _stack$pop2$.node,
1264
+ prev = _stack$pop2$.prev,
1265
+ sort = _stack$pop2[1];
1266
+ if (!parent.__logicType) {
1267
+ const prevSameType = stack.peekByType(NodeSort.Real);
1268
+ ctx.realParent = prevSameType?.node || root;
1269
+ } else {
1270
+ if (sort & NodeSort.Logic) {
1271
+ const parentLogic = stack.peekByType(NodeSort.Logic)?.node;
1272
+ if (parentLogic) {
1273
+ aoye.setPulling(parentLogic.effect);
1274
+ } else {
1275
+ aoye.setPulling(rootPulling);
1276
+ }
1277
+ }
1278
+ if (sort & NodeSort.TokenizerSwitcher) {
1279
+ const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1280
+ this.tokenizer = switcher.tokenizer;
1281
+ }
1282
+ if (parent.__logicType === FakeType.ForItem) {
1283
+ const _ref = parent,
1284
+ forNode = _ref.forNode;
1285
+ const i = forNode.i,
1286
+ arr = forNode.arr,
1287
+ snapshot = forNode.snapshot;
1288
+ if (i + 1 < arr.length) {
1289
+ this.tokenizer.resume(snapshot);
1290
+ this.tokenizer.nextToken();
1291
+ this.tokenizer.nextToken();
1292
+ ctx.current = forNode.children[++forNode.i];
1293
+ ctx.prevSibling = ctx.current.realBefore;
1294
+ continue;
1295
+ }
1296
+ ctx.prevSibling = forNode.prevSibling;
1297
+ ctx.current = forNode;
1298
+ continue;
1299
+ }
1300
+ }
1301
+ ctx.prevSibling = prev;
1302
+ ctx.current = parent;
1303
+ } else {
1304
+ ctx.prevSibling = ctx.current || ctx.prevSibling;
1305
+ ctx.current = this.declaration(ctx);
1306
+ }
1307
+ }
1308
+ return componentNode;
1309
+ }
1310
+ insertAfterAnchor(name = 'anchor') {
1311
+ const _this$ctx = this.ctx,
1312
+ realParent = _this$ctx.realParent,
1313
+ prevSibling = _this$ctx.prevSibling,
1314
+ stack = _this$ctx.stack,
1315
+ before = _this$ctx.before;
1316
+ const afterAnchor = this.createAnchor(name);
1317
+ this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
1318
+ this.handleInsert(realParent, afterAnchor, prevSibling);
1319
+ return afterAnchor;
1320
+ }
1321
+ handleInsert(parent, child, prev, parentComponent) {
1322
+ if (!child.__logicType) {
1323
+ if (!prev || !prev.__logicType) {
1324
+ this.insertAfter(parent, child, prev);
1325
+ } else {
1326
+ const before = prev.realAfter;
1327
+ this.insertAfter(parent, child, before);
1328
+ }
1329
+ } else {
1330
+ const childCmp = child;
1331
+ childCmp.realParent = parent;
1332
+ if (prev?.__logicType) {
1333
+ childCmp.realBefore = prev.forNode ? prev.forNode.realAfter : prev.realAfter;
1334
+ } else {
1335
+ childCmp.realBefore = prev;
1336
+ }
1337
+ }
1338
+ }
1339
+ getPrevRealSibling(prevSibling) {
1340
+ if (!prevSibling || !prevSibling.__logicType) {
1341
+ return prevSibling;
1342
+ }
1343
+ let point = prevSibling;
1344
+ while (point != null) {
1345
+ if (point.lastChild) {
1346
+ return point.lastChild.value;
1347
+ }
1348
+ point = point.anchor;
1349
+ }
1350
+ }
1351
+ declaration(ctx) {
1352
+ const _this$tokenizer$_hook = this.tokenizer._hook({}),
1353
+ _this$tokenizer$_hook2 = _slicedToArray(_this$tokenizer$_hook, 2),
1354
+ hookType = _this$tokenizer$_hook2[0],
1355
+ value = _this$tokenizer$_hook2[1];
1356
+ let _node;
1357
+ if (value === 'if' || value === 'else' || value === 'fail') {
1358
+ return this.condDeclaration(ctx);
1359
+ } else if (value === 'for') {
1360
+ return this.forDeclaration();
1361
+ } else if (hookType) {
1362
+ const data = this.getData();
1363
+ if (hookType === 'static') {
1364
+ if (typeof value === 'function') {
1365
+ _node = this.componentOrFragmentDeclaration(value, ctx);
1366
+ } else {
1367
+ throw new SyntaxError(`declaration 不支持 ${value} 类型的静态插值`);
1368
+ }
1369
+ } else {
1370
+ const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
1371
+ const val = data[aoye.Keys.Raw][value];
1372
+ if (typeof val === 'function') {
1373
+ _node = this.componentOrFragmentDeclaration(val, ctx);
1374
+ } else {
1375
+ const str = valueIsMapKey ? value : this.getFn(data, value);
1376
+ _node = this.createNode('text');
1377
+ this.onePropParsed(data, _node, 'text', str, valueIsMapKey, false);
1378
+ }
1379
+ }
1380
+ } else {
1381
+ _node = this.createNode(value);
1382
+ }
1383
+ this.tokenizer.nextToken();
1384
+ this.headerLine(_node);
1385
+ this.extensionLines(_node);
1386
+ if (_node.__logicType & TokenizerSwitcherBit) {
1387
+ this.onePropParsed = this.oneRealPropParsed;
1388
+ this.tokenizer = _node.tokenizer;
1389
+ }
1390
+ return _node;
1391
+ }
1392
+ forDeclaration() {
1393
+ const arrExp = this.tokenizer.nextToken().value;
1394
+ this.tokenizer.nextToken();
1395
+ const itemToken = this.tokenizer.nextToken();
1396
+ const isDestruct = itemToken.type === TokenType.InsertionExp;
1397
+ let itemExp = itemToken.value,
1398
+ vars;
1399
+ if (isDestruct) {
1400
+ itemExp = '{' + itemExp + '}';
1401
+ vars = itemExp.match(bobeShared.jsVarRegexp);
1402
+ const varStr = vars.join(',');
1403
+ itemExp = new Function(itemExp, `return {${varStr}};`);
1404
+ }
1405
+ let indexName,
1406
+ keyExp,
1407
+ char = this.tokenizer.peekChar();
1408
+ if (char === ';') {
1409
+ this.tokenizer.nextToken();
1410
+ if (this.tokenizer.peekChar() !== '\n') keyExp = this.tokenizer.jsExp().value;
1411
+ } else if (char === '\n') ; else {
1412
+ indexName = this.tokenizer.nextToken().value;
1413
+ if (this.tokenizer.peekChar() === ';') {
1414
+ this.tokenizer.nextToken();
1415
+ if (this.tokenizer.peekChar() !== '\n') keyExp = this.tokenizer.jsExp().value;
1416
+ }
1417
+ }
1418
+ const owner = this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1419
+ const prevSibling = this.ctx.prevSibling;
1420
+ const forNode = {
1421
+ __logicType: FakeType.For,
1422
+ snapshot: this.tokenizer.snapshot(['dentStack', 'isFirstToken']),
1423
+ realParent: this.ctx.realParent,
1424
+ prevSibling,
1425
+ realBefore: prevSibling?.realAfter || prevSibling,
1426
+ realAfter: null,
1427
+ arr: null,
1428
+ arrSignal: null,
1429
+ itemExp,
1430
+ indexName,
1431
+ getKey: null,
1432
+ children: [],
1433
+ effect: null,
1434
+ owner,
1435
+ vars,
1436
+ i: 0
1437
+ };
1438
+ if (keyExp) {
1439
+ forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
1440
+ }
1441
+ window['for1'] = forNode;
1442
+ const data = this.getData();
1443
+ const cells = data[aoye.Keys.Meta].cells;
1444
+ const hasArrExpKey = Reflect.has(data[aoye.Keys.Raw], arrExp);
1445
+ const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new aoye.Computed(this.getFn(data, arrExp));
1446
+ forNode.arrSignal = arrSignal;
1447
+ forNode.realAfter = this.insertAfterAnchor('for-after');
1448
+ const _forNode$snapshot = forNode.snapshot;
1449
+ _forNode$snapshot.dentStack;
1450
+ _forNode$snapshot.isFirstToken;
1451
+ const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
1452
+ let isFirstRender = true;
1453
+ forNode.effect = new aoye.Effect(() => {
1454
+ let arr = arrSignal.get();
1455
+ arr[aoye.Keys.Iterator];
1456
+ const prevCtx = aoye.getPulling();
1457
+ aoye.setPulling(null);
1458
+ forNode.arr = arr = aoye.toRaw(arr);
1459
+ const children = forNode.children;
1460
+ if (isFirstRender) {
1461
+ const len = arr.length;
1462
+ for (let i = len; i--;) {
1463
+ const item = this.createForItem(forNode, i, data);
1464
+ item.realAfter = this.insertAfterAnchor('for-item-after');
1465
+ item.realBefore = this.insertAfterAnchor('for-item-before');
1466
+ item.realParent = forNode.realParent;
1467
+ children[i] = item;
1468
+ }
1469
+ const firstInsert = children[0];
1470
+ if (firstInsert) {
1471
+ this.tokenizer.nextToken();
1472
+ this.tokenizer.nextToken();
1473
+ } else {
1474
+ this.tokenizer.skip();
1475
+ }
1476
+ } else {
1477
+ const oldLen = children.length;
1478
+ const newLen = arr.length;
1479
+ const minLen = Math.min(oldLen, newLen);
1480
+ const newChildren = [];
1481
+ if (!forNode.getKey) {
1482
+ if (newLen < oldLen) {
1483
+ for (let i = oldLen - 1; i >= newLen; i--) {
1484
+ this.removeForItem(children, i);
1485
+ }
1486
+ }
1487
+ if (oldLen < newLen) {
1488
+ const lastAfter = children.at(-1)?.realAfter || forNode.realBefore;
1489
+ for (let i = newLen - 1; i >= oldLen; i--) {
1490
+ this.insertForItem(forNode, i, data, newChildren, lastAfter, snapshotForUpdate);
1491
+ }
1492
+ }
1493
+ for (let i = minLen; i--;) {
1494
+ const child = children[i];
1495
+ newChildren[i] = child;
1496
+ this.reuseForItem(child, arr[i], itemExp, i, indexName);
1497
+ }
1498
+ } else {
1499
+ let s = 0,
1500
+ e1 = oldLen - 1,
1501
+ e2 = newLen - 1;
1502
+ while (s <= e1 && s <= e2) {
1503
+ const child = children[s];
1504
+ const old = child.key;
1505
+ const itemData = this.getItemData(forNode, s, data);
1506
+ const key = forNode.getKey(itemData);
1507
+ if (old === key) {
1508
+ newChildren[s] = child;
1509
+ this.reuseForItem(child, arr[s], itemExp, s, indexName);
1510
+ s++;
1511
+ } else {
1512
+ break;
1513
+ }
1514
+ }
1515
+ while (s <= e1 && s <= e2) {
1516
+ const child = children[e1];
1517
+ const old = child.key;
1518
+ const itemData = this.getItemData(forNode, e2, data);
1519
+ const key = forNode.getKey(itemData);
1520
+ if (old === key) {
1521
+ newChildren[e2] = child;
1522
+ this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
1523
+ e1--;
1524
+ e2--;
1525
+ } else {
1526
+ break;
1527
+ }
1528
+ }
1529
+ if (s > e1) {
1530
+ if (s <= e2) {
1531
+ const firstBefore = s > 0 ? children[s - 1]?.realAfter || forNode.realBefore : forNode.realBefore;
1532
+ for (let i = e2; i >= s; i--) {
1533
+ this.insertForItem(forNode, i, data, newChildren, firstBefore, snapshotForUpdate);
1534
+ }
1535
+ }
1536
+ } else if (s > e2) {
1537
+ if (s <= e1) {
1538
+ for (let i = e1; i >= s; i--) {
1539
+ this.removeForItem(children, i);
1540
+ }
1541
+ }
1542
+ } else {
1543
+ let s1 = s,
1544
+ s2 = s;
1545
+ const mixLen = e2 - s2 + 1;
1546
+ const key2new = new Map();
1547
+ for (let i = s2; i <= e2; i++) {
1548
+ const itemData = this.getItemData(forNode, i, data);
1549
+ const key = forNode.getKey(itemData);
1550
+ key2new.set(key, i);
1551
+ }
1552
+ let maxIncNewI = -1;
1553
+ let hasMove = false;
1554
+ const new2oldI = new Array(mixLen).fill(-1);
1555
+ for (let i = s1; i <= e1; i++) {
1556
+ const key = children[i].key;
1557
+ const newI = key2new.get(key);
1558
+ if (newI == null) {
1559
+ this.removeForItem(children, i);
1560
+ continue;
1561
+ }
1562
+ const child = children[i];
1563
+ newChildren[newI] = child;
1564
+ this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
1565
+ new2oldI[newI - s2] = i;
1566
+ key2new.delete(key);
1567
+ if (newI < maxIncNewI) {
1568
+ hasMove = true;
1569
+ } else {
1570
+ maxIncNewI = newI;
1571
+ }
1572
+ }
1573
+ if (!hasMove) {
1574
+ key2new.forEach((i, key) => {
1575
+ const before = i === 0 ? forNode.realBefore : newChildren[i - 1].realAfter;
1576
+ this.insertForItem(forNode, i, data, newChildren, before, snapshotForUpdate);
1577
+ });
1578
+ } else {
1579
+ const incI = macInc(new2oldI),
1580
+ incLen = incI.length;
1581
+ let p1, p2;
1582
+ for (p1 = s2, p2 = 0; p1 <= e2; p1++) {
1583
+ const oldI = new2oldI[p1];
1584
+ if (oldI === -1) {
1585
+ const before = p1 === 0 ? forNode.realBefore : newChildren[p1 - 1].realAfter;
1586
+ this.insertForItem(forNode, p1, data, newChildren, before, snapshotForUpdate);
1587
+ continue;
1588
+ }
1589
+ const staticIdx = incI[p2] + s2;
1590
+ if (p1 === staticIdx) {
1591
+ p2 <= incLen && p2++;
1592
+ continue;
1593
+ }
1594
+ let before = p1 === 0 ? forNode.realBefore : newChildren[p1 - 1].realAfter;
1595
+ const child = newChildren[p1];
1596
+ const realBefore = child.realBefore,
1597
+ realAfter = child.realAfter,
1598
+ realParent = child.realParent;
1599
+ let point = realBefore,
1600
+ next;
1601
+ do {
1602
+ next = this.nextSib(point);
1603
+ this.insertAfter(realParent, point, before);
1604
+ before = point;
1605
+ if (point === realAfter) break;
1606
+ point = next;
1607
+ } while (true);
1608
+ }
1609
+ }
1610
+ }
1611
+ }
1612
+ forNode.children = newChildren;
1613
+ }
1614
+ isFirstRender = false;
1615
+ aoye.setPulling(prevCtx);
1616
+ return isDestroy => {
1617
+ if (isDestroy) {
1618
+ for (let i = 0; i < forNode.children.length; i++) {
1619
+ const item = forNode.children[i];
1620
+ item.effect.dispose();
1621
+ }
1622
+ }
1623
+ };
1624
+ });
1625
+ return forNode.children[0] || forNode;
1626
+ }
1627
+ insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
1628
+ const item = this.createForItem(forNode, i, parentData);
1629
+ newChildren[i] = item;
1630
+ let realAfter = this.createAnchor('for-item-after');
1631
+ this.handleInsert(forNode.realParent, realAfter, before);
1632
+ let realBefore = this.createAnchor('for-item-before');
1633
+ this.handleInsert(forNode.realParent, realBefore, before);
1634
+ item.realBefore = realBefore;
1635
+ item.realAfter = realAfter;
1636
+ this.tokenizer = forNode.owner.tokenizer;
1637
+ this.tokenizer.resume(snapshotForUpdate);
1638
+ this.tokenizer.useDedentAsEof = false;
1639
+ aoye.runWithPulling(() => {
1640
+ this.program(forNode.realParent, forNode.owner, realBefore, item);
1641
+ }, item.effect);
1642
+ }
1643
+ removeForItem(children, i) {
1644
+ const child = children[i];
1645
+ this.removeLogicNode(child);
1646
+ this.remove(child.realBefore);
1647
+ this.remove(child.realAfter);
1648
+ child.effect.dispose();
1649
+ }
1650
+ reuseForItem(child, data, itemExp, i, indexName) {
1651
+ if (typeof itemExp === 'string') {
1652
+ child.data[itemExp] = data;
1653
+ if (indexName) {
1654
+ child.data[indexName] = i;
1655
+ }
1656
+ } else {
1657
+ indexName = indexName || KEY_INDEX;
1658
+ child.data[indexName] = i;
1659
+ }
1660
+ }
1661
+ forItemId = 0;
1662
+ createForItem(forNode, i, parentData) {
1663
+ let forItemNode;
1664
+ let data;
1665
+ const scope = new aoye.Scope(() => {});
1666
+ scope.scope = null;
1667
+ aoye.runWithPulling(() => {
1668
+ scope.get();
1669
+ }, null);
1670
+ data = this.getItemData(forNode, i, parentData);
1671
+ forItemNode = {
1672
+ id: this.forItemId++,
1673
+ __logicType: FakeType.ForItem,
1674
+ realParent: null,
1675
+ realBefore: null,
1676
+ realAfter: null,
1677
+ forNode,
1678
+ key: forNode.getKey?.(data),
1679
+ effect: null,
1680
+ data
1681
+ };
1682
+ forItemNode.effect = scope;
1683
+ return forItemNode;
1684
+ }
1685
+ getItemData(forNode, i, parentData) {
1686
+ const arr = forNode.arr,
1687
+ itemExp = forNode.itemExp,
1688
+ vars = forNode.vars,
1689
+ arrSignal = forNode.arrSignal,
1690
+ getKey = forNode.getKey;
1691
+ let indexName = forNode.indexName;
1692
+ let data;
1693
+ if (typeof itemExp === 'string') {
1694
+ data = aoye.deepSignal(indexName ? {
1695
+ [itemExp]: arr[i],
1696
+ [indexName]: i
1697
+ } : {
1698
+ [itemExp]: arr[i]
1699
+ }, aoye.getPulling());
1700
+ } else {
1701
+ indexName = indexName ?? KEY_INDEX;
1702
+ const rawData = {
1703
+ [indexName]: i
1704
+ };
1705
+ data = aoye.deepSignal(rawData, aoye.getPulling());
1706
+ const computedData = new aoye.Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
1707
+ const cells = data[aoye.Keys.Meta].cells;
1708
+ for (let i = 0; i < vars.length; i++) {
1709
+ const name = vars[i];
1710
+ rawData[name] = undefined;
1711
+ cells.set(name, new aoye.Computed(() => computedData.get()[name]));
1712
+ }
1713
+ }
1714
+ Object.setPrototypeOf(data, parentData);
1715
+ return data;
1716
+ }
1717
+ getData() {
1718
+ const _this$ctx$stack$peekB = this.ctx.stack.peekByType(NodeSort.CtxProvider),
1719
+ node = _this$ctx$stack$peekB.node;
1720
+ return node.data;
1721
+ }
1722
+ onePropParsed(data, node, key, value, valueIsMapKey, isFn, hookI) {
1723
+ if (isFn) {
1724
+ this.setProp(node, key, value, hookI);
1725
+ } else if (typeof value === 'function') {
1726
+ new aoye.Effect(() => {
1727
+ const res = value();
1728
+ this.setProp(node, key, res, hookI);
1729
+ });
1730
+ } else if (valueIsMapKey) {
1731
+ new aoye.Effect(() => {
1732
+ const res = data[value];
1733
+ this.setProp(node, key, res, hookI);
1734
+ });
1735
+ } else {
1736
+ this.setProp(node, key, value, hookI);
1737
+ }
1738
+ }
1739
+ oneRealPropParsed = this.onePropParsed.bind(this);
1740
+ componentOrFragmentDeclaration(ComponentOrRender, ctx) {
1741
+ let Component, render, child;
1742
+ const isCC = ComponentOrRender.prototype instanceof aoye.Store;
1743
+ if (isCC) {
1744
+ Component = ComponentOrRender;
1745
+ child = Component.new();
1746
+ } else {
1747
+ render = ComponentOrRender;
1748
+ const boundStore = render.boundStore;
1749
+ child = aoye.deepSignal({}, aoye.getPulling(), true);
1750
+ Object.setPrototypeOf(child, boundStore);
1751
+ }
1752
+ const node = {
1753
+ __logicType: isCC ? FakeType.Component : FakeType.Fragment,
1754
+ realParent: ctx.realParent,
1755
+ realBefore: null,
1756
+ realAfter: null,
1757
+ data: child,
1758
+ tokenizer: render ? render(true) : child['ui'](true)
1759
+ };
1760
+ this.onePropParsed = (data, _, key, value, valueIsMapKey, isFn, hookI) => {
1761
+ if (isFn) {
1762
+ child[aoye.Keys.Raw][key] = value;
1763
+ } else if (valueIsMapKey) {
1764
+ aoye.shareSignal(data, value, child, key);
1765
+ } else {
1766
+ const meta = child[aoye.Keys.Meta];
1767
+ const cells = meta.cells;
1768
+ if (typeof value === 'function') {
1769
+ const computed = new aoye.Computed(value);
1770
+ cells.set(key, computed);
1771
+ child[aoye.Keys.Raw][key] = undefined;
1772
+ } else {
1773
+ cells.set(key, {
1774
+ get: () => value
1775
+ });
1776
+ child[aoye.Keys.Raw][key] = value;
1777
+ }
1778
+ }
1779
+ };
1780
+ node.realAfter = this.insertAfterAnchor('component-after');
1781
+ return node;
1782
+ }
1783
+ getFn(data, expression) {
1784
+ return new Function('data', `let v;with(data){v=${expression}};return v;`).bind(undefined, data);
1785
+ }
1786
+ condDeclaration(ctx) {
1787
+ const prevSibling = ctx.prevSibling;
1788
+ const keyWord = this.tokenizer.token;
1789
+ const expToken = this.tokenizer.condExp();
1790
+ const value = expToken.value;
1791
+ const isElse = keyWord.value === 'else';
1792
+ const isIf = keyWord.value === 'if';
1793
+ const preIsCond = prevSibling?.__logicType & CondBit;
1794
+ const data = this.getData();
1795
+ const noCond = value === true;
1796
+ const valueIsMapKey = !noCond && Reflect.has(data[aoye.Keys.Raw], value);
1797
+ const owner = ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1798
+ const ifNode = {
1799
+ __logicType: isElse ? FakeType.Else : isIf ? FakeType.If : FakeType.Fail,
1800
+ snapshot: this.tokenizer.snapshot(),
1801
+ realParent: null,
1802
+ realBefore: null,
1803
+ realAfter: null,
1804
+ condition: null,
1805
+ preCond: preIsCond ? prevSibling : null,
1806
+ isFirstRender: true,
1807
+ effect: null,
1808
+ owner,
1809
+ data
1810
+ };
1811
+ let signal;
1812
+ switch (keyWord.value) {
1813
+ case 'if':
1814
+ if (valueIsMapKey) {
1815
+ aoye.runWithPulling(() => data[value], null);
1816
+ const cells = data[aoye.Keys.Meta].cells;
1817
+ signal = cells.get(value);
1818
+ } else {
1819
+ const fn = this.getFn(data, value);
1820
+ signal = new aoye.Computed(fn);
1821
+ }
1822
+ break;
1823
+ case 'else':
1824
+ if (noCond) {
1825
+ signal = new aoye.Computed(() => {
1826
+ let point = ifNode.preCond;
1827
+ while (point) {
1828
+ if (point.condition.get()) {
1829
+ return false;
1830
+ }
1831
+ if (point.__logicType === FakeType.If) {
1832
+ break;
1833
+ }
1834
+ point = point.preCond;
1835
+ }
1836
+ return true;
1837
+ });
1838
+ } else {
1839
+ const fn = valueIsMapKey ? null : this.getFn(data, value);
1840
+ signal = new aoye.Computed(() => {
1841
+ let point = ifNode.preCond;
1842
+ while (point) {
1843
+ if (point.condition.get()) {
1844
+ return false;
1845
+ }
1846
+ if (point.__logicType === FakeType.If) {
1847
+ break;
1848
+ }
1849
+ point = point.preCond;
1850
+ }
1851
+ return valueIsMapKey ? data[value] : fn();
1852
+ });
1853
+ }
1854
+ break;
1855
+ case 'fail':
1856
+ signal = new aoye.Computed(() => {
1857
+ let point = ifNode.preCond;
1858
+ while (point) {
1859
+ if (point.condition.get()) {
1860
+ return false;
1861
+ }
1862
+ point = point.preCond;
1863
+ }
1864
+ return true;
1865
+ });
1866
+ break;
1867
+ }
1868
+ ifNode.condition = signal;
1869
+ ifNode.realAfter = this.insertAfterAnchor(`${keyWord.value}-after`);
1870
+ const ef = aoye.effect(({
1871
+ val
1872
+ }) => {
1873
+ if (val) {
1874
+ if (ifNode.isFirstRender) {
1875
+ this.tokenizer.nextToken();
1876
+ this.tokenizer.nextToken();
1877
+ } else {
1878
+ this.tokenizer = ifNode.owner.tokenizer;
1879
+ this.tokenizer.resume(ifNode.snapshot);
1880
+ this.tokenizer.useDedentAsEof = false;
1881
+ this.program(ifNode.realParent, ifNode.owner, ifNode.realBefore, ifNode);
1882
+ }
1883
+ } else {
1884
+ if (ifNode.isFirstRender) {
1885
+ this.tokenizer.skip();
1886
+ } else {
1887
+ this.removeLogicNode(ifNode);
1888
+ }
1889
+ }
1890
+ ifNode.isFirstRender = false;
1891
+ }, [signal]);
1892
+ ifNode.effect = ef;
1893
+ return ifNode;
1894
+ }
1895
+ removeLogicNode(node) {
1896
+ const realBefore = node.realBefore,
1897
+ realAfter = node.realAfter,
1898
+ realParent = node.realParent;
1899
+ let point = realBefore ? this.nextSib(realBefore) : this.firstChild(realParent);
1900
+ while (point !== realAfter) {
1901
+ const next = this.nextSib(point);
1902
+ this.remove(point, realParent, realBefore);
1903
+ point = next;
1904
+ }
1905
+ }
1906
+ extensionLines(_node) {
1907
+ while (1) {
1908
+ if ((this.tokenizer.token.type & TokenType.Pipe) === 0) {
1909
+ return;
1910
+ }
1911
+ this.tokenizer.nextToken();
1912
+ this.attributeList(_node);
1913
+ if ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
1914
+ return;
1915
+ }
1916
+ this.tokenizer.nextToken();
1917
+ }
1918
+ }
1919
+ headerLine(_node) {
1920
+ this.attributeList(_node);
1921
+ this.tokenizer.nextToken();
1922
+ }
1923
+ attributeList(_node) {
1924
+ let key, eq;
1925
+ const data = this.getData();
1926
+ while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
1927
+ if (key == null) {
1928
+ key = this.tokenizer.token.value;
1929
+ } else if (eq == null) {
1930
+ eq = '=';
1931
+ } else {
1932
+ const _this$tokenizer$_hook3 = this.tokenizer._hook({}),
1933
+ _this$tokenizer$_hook4 = _slicedToArray(_this$tokenizer$_hook3, 3),
1934
+ hookType = _this$tokenizer$_hook4[0],
1935
+ value = _this$tokenizer$_hook4[1],
1936
+ hookI = _this$tokenizer$_hook4[2];
1937
+ const rawVal = data[aoye.Keys.Raw][value];
1938
+ const isFn = typeof rawVal === 'function';
1939
+ if (hookType === 'dynamic') {
1940
+ const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
1941
+ const fn = isFn ? rawVal : valueIsMapKey ? value : this.getFn(data, value);
1942
+ this.onePropParsed(data, _node, key, fn, valueIsMapKey, isFn, hookI);
1943
+ } else if (hookType === 'static') {
1944
+ this.onePropParsed(data, _node, key, value, false, isFn, hookI);
1945
+ } else {
1946
+ this.onePropParsed(data, _node, key, value, false, isFn, hookI);
1947
+ }
1948
+ key = null;
1949
+ eq = null;
1950
+ }
1951
+ this.tokenizer.nextToken();
1952
+ }
1953
+ }
1954
+ config(opt) {
1955
+ Object.assign(this, opt);
1956
+ this.opt = opt;
1957
+ }
1958
+ createNode(name) {
1959
+ return {
1960
+ name,
1961
+ props: {},
1962
+ nextSibling: null
1963
+ };
1964
+ }
1965
+ nextSib(node) {
1966
+ return node.nextSibling;
1967
+ }
1968
+ firstChild(node) {
1969
+ return node.firstChild;
1970
+ }
1971
+ createAnchor(name) {
1972
+ return {
1973
+ name,
1974
+ nextSibling: null
1975
+ };
1976
+ }
1977
+ insertAfter(parent, node, prev) {
1978
+ return this.defaultInsert(parent, node, prev);
1979
+ }
1980
+ defaultInsert(parent, node, prev) {
1981
+ if (prev) {
1982
+ const next = prev.nextSibling;
1983
+ prev.nextSibling = node;
1984
+ node.nextSibling = next;
1985
+ } else {
1986
+ const next = parent.firstChild;
1987
+ parent.firstChild = node;
1988
+ node.nextSibling = next;
1989
+ }
1990
+ }
1991
+ remove(node, parent, prev) {
1992
+ return this.defaultRemove(node, parent, prev);
1993
+ }
1994
+ defaultRemove(node, parent, prevSibling) {
1995
+ const next = node.nextSibling;
1996
+ if (prevSibling) {
1997
+ prevSibling.nextSibling = next;
1998
+ }
1999
+ if (parent.firstChild === node) {
2000
+ parent.firstChild = next;
2001
+ }
2002
+ }
2003
+ setProp(node, key, value, hookI) {
2004
+ node.props[key] = value;
2005
+ }
2006
+ }
2007
+
2008
+ function bobe(fragments, ...values) {
2009
+ const ui = function ui(isSub) {
2010
+ const tokenizer = new Tokenizer(({
2011
+ i
2012
+ }) => {
2013
+ return values[i];
2014
+ }, isSub);
2015
+ tokenizer.init(Array.from(fragments));
2016
+ return tokenizer;
2017
+ };
2018
+ ui.boundStore = aoye.Store.Current;
2019
+ return ui;
2020
+ }
2021
+ function customRender(option) {
2022
+ return function render(Ctor, root) {
2023
+ const store = Ctor.new();
2024
+ const tokenizer = store['ui'](false);
2025
+ const terp = new Interpreter(tokenizer);
2026
+ terp.config(option);
2027
+ const componentNode = {
2028
+ __logicType: FakeType.Component,
2029
+ realParent: root,
2030
+ data: store,
2031
+ tokenizer
2032
+ };
2033
+ terp.program(root, componentNode);
2034
+ return [componentNode, store];
2035
+ };
2036
+ }
2037
+
2038
+ exports.Compiler = Compiler;
2039
+ exports.NodeType = NodeType;
2040
+ exports.Tokenizer = Tokenizer;
2041
+ exports.bobe = bobe;
2042
+ exports.customRender = customRender;
2043
+ Object.keys(aoye).forEach(function (k) {
2044
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2045
+ enumerable: true,
2046
+ get: function () { return aoye[k]; }
2047
+ });
2048
+ });
2049
+ //# sourceMappingURL=bobe.compiler.cjs.js.map