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