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