bobe 0.0.47 → 0.0.49
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 +191 -78
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +199 -100
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +197 -97
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +189 -75
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +51 -22
- package/dist/index.umd.js +191 -78
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Queue, isNum, matchIdStart2, matchId, escapeMap, jsVarRegexp, date32 } from 'bobe-shared';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { Signal, Computed, Keys, getPulling, setPulling, deepSignal, toRaw, ScheduleType, runWithPulling, Scope, Store, noopEffect, NoopEffect, Effect, effect as effect$1, shareSignal } from 'aoye';
|
|
3
|
+
export { Store } from 'aoye';
|
|
4
4
|
|
|
5
5
|
let TokenType = function (TokenType) {
|
|
6
6
|
TokenType[TokenType["NewLine"] = 1] = "NewLine";
|
|
@@ -80,6 +80,7 @@ class ParseSyntaxError extends SyntaxError {
|
|
|
80
80
|
this.loc = loc;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
const isDep = target => target && (target instanceof Signal || target instanceof Computed || typeof target === 'function' || typeof target === 'string');
|
|
83
84
|
|
|
84
85
|
class Tokenizer {
|
|
85
86
|
TabSize = 2;
|
|
@@ -104,10 +105,13 @@ class Tokenizer {
|
|
|
104
105
|
this.hook = hook;
|
|
105
106
|
this.useDedentAsEof = useDedentAsEof;
|
|
106
107
|
if (useDedentAsEof) {
|
|
107
|
-
this.
|
|
108
|
-
this.isFirstToken = true;
|
|
108
|
+
this.initIndentWhenUseDedentAsEof();
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
initIndentWhenUseDedentAsEof() {
|
|
112
|
+
this.setToken(TokenType.Indent, '');
|
|
113
|
+
this.isFirstToken = true;
|
|
114
|
+
}
|
|
111
115
|
next() {
|
|
112
116
|
{
|
|
113
117
|
const char = this.code[this.i];
|
|
@@ -146,16 +150,23 @@ class Tokenizer {
|
|
|
146
150
|
throwUnclosed(code, message, startOffset, startLine, startCol) {
|
|
147
151
|
throw new ParseSyntaxError(code, message, this.unclosedLoc(startOffset, startLine, startCol));
|
|
148
152
|
}
|
|
149
|
-
resume(
|
|
153
|
+
resume({
|
|
154
|
+
dentStack,
|
|
155
|
+
waitingTokens,
|
|
156
|
+
..._snapshot
|
|
157
|
+
}) {
|
|
150
158
|
this.token = undefined;
|
|
151
159
|
this.needIndent = false;
|
|
152
160
|
this.isFirstToken = true;
|
|
153
|
-
this.dentStack = [0];
|
|
161
|
+
this.dentStack = dentStack ? dentStack.slice() : [0];
|
|
162
|
+
if (waitingTokens) {
|
|
163
|
+
this.waitingTokens = waitingTokens.clone();
|
|
164
|
+
}
|
|
154
165
|
Object.assign(this, _snapshot);
|
|
155
166
|
}
|
|
156
|
-
snapshot(keys) {
|
|
167
|
+
snapshot(keys, dtI = 0) {
|
|
157
168
|
const snap = {
|
|
158
|
-
i: this.i,
|
|
169
|
+
i: this.i + dtI,
|
|
159
170
|
waitingTokens: this.waitingTokens.clone()
|
|
160
171
|
};
|
|
161
172
|
if (keys) {
|
|
@@ -168,8 +179,10 @@ class Tokenizer {
|
|
|
168
179
|
}
|
|
169
180
|
return snap;
|
|
170
181
|
}
|
|
171
|
-
skip() {
|
|
172
|
-
|
|
182
|
+
skip(targetDentLen) {
|
|
183
|
+
if (targetDentLen == undefined) {
|
|
184
|
+
targetDentLen = this.dentStack[this.dentStack.length - 1];
|
|
185
|
+
}
|
|
173
186
|
let needIndent = false;
|
|
174
187
|
let skipFragment = ``;
|
|
175
188
|
this.token = undefined;
|
|
@@ -192,7 +205,7 @@ class Tokenizer {
|
|
|
192
205
|
isEmptyLine = _this$getDentValue.isEmptyLine;
|
|
193
206
|
const currLen = value.length;
|
|
194
207
|
if (isEmptyLine) continue;
|
|
195
|
-
if (currLen >
|
|
208
|
+
if (currLen > targetDentLen) {
|
|
196
209
|
skipFragment += value;
|
|
197
210
|
} else {
|
|
198
211
|
for (let i = this.dentStack.length - 1; i >= 0; i--) {
|
|
@@ -205,6 +218,9 @@ class Tokenizer {
|
|
|
205
218
|
break;
|
|
206
219
|
}
|
|
207
220
|
this.dentStack.pop();
|
|
221
|
+
if (expLen > targetDentLen) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
208
224
|
if (!this.token) {
|
|
209
225
|
this.setToken(TokenType.Dedent, String(expLen));
|
|
210
226
|
} else {
|
|
@@ -271,33 +287,31 @@ class Tokenizer {
|
|
|
271
287
|
}
|
|
272
288
|
outer: while (1) {
|
|
273
289
|
if (this.needIndent) {
|
|
290
|
+
this.locStart();
|
|
274
291
|
this.dent();
|
|
292
|
+
this.locEnd();
|
|
275
293
|
} else {
|
|
276
294
|
const char = this.code[this.i];
|
|
277
295
|
switch (char) {
|
|
278
296
|
case '\t':
|
|
279
297
|
case ' ':
|
|
280
298
|
break;
|
|
281
|
-
case '\n':
|
|
282
|
-
this.newLine();
|
|
283
|
-
this.needIndent = true;
|
|
284
|
-
break;
|
|
285
|
-
case '=':
|
|
286
|
-
this.assignment();
|
|
287
|
-
break;
|
|
288
|
-
case '|':
|
|
289
|
-
this.pipe();
|
|
290
|
-
break;
|
|
291
|
-
case ';':
|
|
292
|
-
this.setToken(TokenType.Semicolon, ';');
|
|
293
|
-
break;
|
|
294
299
|
default:
|
|
295
|
-
|
|
296
|
-
this.preI = this.i;
|
|
297
|
-
this.preCol = this.column;
|
|
298
|
-
this.needLoc = true;
|
|
299
|
-
}
|
|
300
|
+
this.locStart();
|
|
300
301
|
switch (char) {
|
|
302
|
+
case '\n':
|
|
303
|
+
this.newLine();
|
|
304
|
+
this.needIndent = true;
|
|
305
|
+
break;
|
|
306
|
+
case '=':
|
|
307
|
+
this.assignment();
|
|
308
|
+
break;
|
|
309
|
+
case '|':
|
|
310
|
+
this.pipe();
|
|
311
|
+
break;
|
|
312
|
+
case ';':
|
|
313
|
+
this.setToken(TokenType.Semicolon, ';');
|
|
314
|
+
break;
|
|
301
315
|
case '/':
|
|
302
316
|
this.comment();
|
|
303
317
|
break;
|
|
@@ -322,9 +336,7 @@ class Tokenizer {
|
|
|
322
336
|
}
|
|
323
337
|
break;
|
|
324
338
|
}
|
|
325
|
-
|
|
326
|
-
this.needLoc = false;
|
|
327
|
-
}
|
|
339
|
+
this.locEnd();
|
|
328
340
|
break;
|
|
329
341
|
}
|
|
330
342
|
this.next();
|
|
@@ -340,6 +352,18 @@ class Tokenizer {
|
|
|
340
352
|
this.handledTokens.push(this.token);
|
|
341
353
|
}
|
|
342
354
|
}
|
|
355
|
+
locStart() {
|
|
356
|
+
{
|
|
357
|
+
this.preCol = this.column;
|
|
358
|
+
this.preI = this.i;
|
|
359
|
+
this.needLoc = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
locEnd() {
|
|
363
|
+
{
|
|
364
|
+
this.needLoc = false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
343
367
|
getComment() {
|
|
344
368
|
let value = '/';
|
|
345
369
|
let nextC = this.code[this.i + 1];
|
|
@@ -356,11 +380,7 @@ class Tokenizer {
|
|
|
356
380
|
this.getComment();
|
|
357
381
|
}
|
|
358
382
|
condExp() {
|
|
359
|
-
|
|
360
|
-
this.preCol = this.column;
|
|
361
|
-
this.preI = this.i;
|
|
362
|
-
this.needLoc = true;
|
|
363
|
-
}
|
|
383
|
+
this.locStart();
|
|
364
384
|
let value = '';
|
|
365
385
|
this.token = null;
|
|
366
386
|
let char = this.code[this.i];
|
|
@@ -375,20 +395,14 @@ class Tokenizer {
|
|
|
375
395
|
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
376
396
|
this.setToken(TokenType.Identifier, trimmed ? trimmed : true, 0);
|
|
377
397
|
this.handledTokens.push(this.token);
|
|
378
|
-
|
|
379
|
-
this.needLoc = false;
|
|
380
|
-
}
|
|
398
|
+
this.locEnd();
|
|
381
399
|
return this.token;
|
|
382
400
|
}
|
|
383
401
|
isEol(i) {
|
|
384
402
|
return this.code[i] === '\n' || this.code[i] === '/';
|
|
385
403
|
}
|
|
386
404
|
jsExp() {
|
|
387
|
-
|
|
388
|
-
this.preCol = this.column;
|
|
389
|
-
this.preI = this.i;
|
|
390
|
-
this.needLoc = true;
|
|
391
|
-
}
|
|
405
|
+
this.locStart();
|
|
392
406
|
this.token = null;
|
|
393
407
|
let value = '';
|
|
394
408
|
let char = this.code[this.i];
|
|
@@ -402,9 +416,7 @@ class Tokenizer {
|
|
|
402
416
|
}
|
|
403
417
|
this.setToken(TokenType.Identifier, value, 0);
|
|
404
418
|
this.handledTokens.push(this.token);
|
|
405
|
-
|
|
406
|
-
this.needLoc = false;
|
|
407
|
-
}
|
|
419
|
+
this.locEnd();
|
|
408
420
|
return this.token;
|
|
409
421
|
}
|
|
410
422
|
peekChar() {
|
|
@@ -592,7 +604,7 @@ class Tokenizer {
|
|
|
592
604
|
const prevLen = this.dentStack[this.dentStack.length - 1];
|
|
593
605
|
if (currLen > prevLen) {
|
|
594
606
|
this.dentStack.push(currLen);
|
|
595
|
-
this.setToken(TokenType.Indent, currLen);
|
|
607
|
+
this.setToken(TokenType.Indent, currLen, 0);
|
|
596
608
|
return indentHasLen;
|
|
597
609
|
}
|
|
598
610
|
if (currLen < prevLen) {
|
|
@@ -607,7 +619,7 @@ class Tokenizer {
|
|
|
607
619
|
}
|
|
608
620
|
this.dentStack.pop();
|
|
609
621
|
if (!this.token) {
|
|
610
|
-
this.setToken(TokenType.Dedent, String(expLen));
|
|
622
|
+
this.setToken(TokenType.Dedent, String(expLen), 0);
|
|
611
623
|
} else {
|
|
612
624
|
this.waitingTokens.push({
|
|
613
625
|
type: TokenType.Dedent,
|
|
@@ -1014,7 +1026,7 @@ var NodeType = function (NodeType) {
|
|
|
1014
1026
|
let _initProto;
|
|
1015
1027
|
class Compiler {
|
|
1016
1028
|
static {
|
|
1017
|
-
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, "parseJsExp"], [[NodeHook, TokenLoc], 2, "parsePropertyValue"], [[NodeHook, TokenLoc], 2, "parseName"]]).e, 1);
|
|
1029
|
+
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, "parseJsExp"], [[NodeHook, TokenLoc], 2, "parsePropertyValue"], [[NodeHook, NodeLoc], 2, "parsePropertyInlineFragment"], [[NodeHook, TokenLoc], 2, "parseName"]]).e, 1);
|
|
1018
1030
|
_initProto = _applyDecs$e[0];
|
|
1019
1031
|
}
|
|
1020
1032
|
errors = (_initProto(this), []);
|
|
@@ -1116,9 +1128,9 @@ class Compiler {
|
|
|
1116
1128
|
parseComponentNode(node) {
|
|
1117
1129
|
const name = this.parseName();
|
|
1118
1130
|
this.tokenizer.nextToken();
|
|
1119
|
-
const props = this.headerLineAndExtensions();
|
|
1120
1131
|
node.type = NodeType.Component;
|
|
1121
1132
|
node.componentName = name;
|
|
1133
|
+
const props = this.headerLineAndExtensions();
|
|
1122
1134
|
node.props = props;
|
|
1123
1135
|
this.hooks.parseComponentNode?.propsAdded?.call(this, node);
|
|
1124
1136
|
const children = this.handleChildren();
|
|
@@ -1136,9 +1148,9 @@ class Compiler {
|
|
|
1136
1148
|
}
|
|
1137
1149
|
const tagName = tagToken.value;
|
|
1138
1150
|
this.tokenizer.nextToken();
|
|
1139
|
-
const props = this.headerLineAndExtensions();
|
|
1140
1151
|
node.type = NodeType.Element;
|
|
1141
1152
|
node.tagName = tagName;
|
|
1153
|
+
const props = this.headerLineAndExtensions();
|
|
1142
1154
|
node.props = props;
|
|
1143
1155
|
this.hooks.parseElementNode?.propsAdded?.call(this, node);
|
|
1144
1156
|
const children = this.handleChildren();
|
|
@@ -1212,17 +1224,17 @@ class Compiler {
|
|
|
1212
1224
|
}
|
|
1213
1225
|
headerLineAndExtensions() {
|
|
1214
1226
|
const props = [];
|
|
1215
|
-
|
|
1216
|
-
if (this.tokenizer.token.type & TokenType.NewLine) {
|
|
1217
|
-
this.tokenizer.nextToken();
|
|
1218
|
-
}
|
|
1219
|
-
while (this.tokenizer.token.type & TokenType.Pipe) {
|
|
1220
|
-
this.tokenizer.nextToken();
|
|
1227
|
+
do {
|
|
1221
1228
|
props.push(...this.attributeList());
|
|
1222
1229
|
if (this.tokenizer.token.type & TokenType.NewLine) {
|
|
1223
1230
|
this.tokenizer.nextToken();
|
|
1224
1231
|
}
|
|
1225
|
-
|
|
1232
|
+
if ((this.tokenizer.token.type & TokenType.Pipe) === 0) {
|
|
1233
|
+
break;
|
|
1234
|
+
} else {
|
|
1235
|
+
this.tokenizer.nextToken();
|
|
1236
|
+
}
|
|
1237
|
+
} while (true);
|
|
1226
1238
|
return props;
|
|
1227
1239
|
}
|
|
1228
1240
|
attributeList() {
|
|
@@ -1246,25 +1258,35 @@ class Compiler {
|
|
|
1246
1258
|
const token = this.tokenizer.nextToken();
|
|
1247
1259
|
if (token.value !== '=') {
|
|
1248
1260
|
this.addError(ParseErrorCode.MISSING_ASSIGN, `属性 "${node.key.key}" 缺少 "=" 赋值符号`, node.key.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1249
|
-
|
|
1250
|
-
node.loc.end = node.key.loc.end;
|
|
1251
|
-
node.loc.source = this.tokenizer.code.slice(node.loc.start.offset, node.loc.end.offset);
|
|
1261
|
+
this.handleOnlyKeyLoc(node);
|
|
1252
1262
|
return node;
|
|
1253
1263
|
}
|
|
1254
1264
|
const valueToken = this.tokenizer.nextToken();
|
|
1265
|
+
if (valueToken.type & TokenType.NewLine) {
|
|
1266
|
+
this.tokenizer.nextToken();
|
|
1267
|
+
node.value = this.parsePropertyInlineFragment();
|
|
1268
|
+
this.handleKeyValueLoc(node);
|
|
1269
|
+
return node;
|
|
1270
|
+
}
|
|
1255
1271
|
if ((valueToken.type & ValueTokenType) === 0) {
|
|
1256
1272
|
this.addError(ParseErrorCode.MISSING_PROP_ASSIGNMENT, `属性值不合法, "${valueToken.value}" 不合法`, valueToken.loc ?? this.tokenizer.emptyLoc(), node);
|
|
1257
|
-
|
|
1258
|
-
node.loc.end = node.key.loc.end;
|
|
1259
|
-
node.loc.source = this.tokenizer.code.slice(node.loc.start.offset, node.loc.end.offset);
|
|
1273
|
+
this.handleOnlyKeyLoc(node);
|
|
1260
1274
|
return node;
|
|
1261
1275
|
}
|
|
1262
1276
|
node.value = this.parsePropertyValue();
|
|
1263
1277
|
this.tokenizer.nextToken();
|
|
1278
|
+
this.handleKeyValueLoc(node);
|
|
1279
|
+
return node;
|
|
1280
|
+
}
|
|
1281
|
+
handleOnlyKeyLoc(node) {
|
|
1282
|
+
node.loc.start = node.key.loc.start;
|
|
1283
|
+
node.loc.end = node.key.loc.end;
|
|
1284
|
+
node.loc.source = this.tokenizer.code.slice(node.loc.start.offset, node.loc.end.offset);
|
|
1285
|
+
}
|
|
1286
|
+
handleKeyValueLoc(node) {
|
|
1264
1287
|
node.loc.start = node.key.loc.start;
|
|
1265
1288
|
node.loc.end = node.value.loc.end;
|
|
1266
1289
|
node.loc.source = this.tokenizer.code.slice(node.loc.start.offset, node.loc.end.offset);
|
|
1267
|
-
return node;
|
|
1268
1290
|
}
|
|
1269
1291
|
parsePropertyKey(node) {
|
|
1270
1292
|
node.type = NodeType.PropertyKey;
|
|
@@ -1289,6 +1311,12 @@ class Compiler {
|
|
|
1289
1311
|
node.value = value;
|
|
1290
1312
|
return node;
|
|
1291
1313
|
}
|
|
1314
|
+
parsePropertyInlineFragment(node) {
|
|
1315
|
+
const list = this.handleChildren();
|
|
1316
|
+
node.type = NodeType.StaticValue;
|
|
1317
|
+
node.value = list;
|
|
1318
|
+
return node;
|
|
1319
|
+
}
|
|
1292
1320
|
parseName(node) {
|
|
1293
1321
|
const _this$tokenizer$_hook7 = this.tokenizer._hook({}),
|
|
1294
1322
|
_this$tokenizer$_hook8 = _slicedToArray(_this$tokenizer$_hook7, 2),
|
|
@@ -1512,6 +1540,9 @@ class Interpreter {
|
|
|
1512
1540
|
}
|
|
1513
1541
|
if (sort & NodeSort.TokenizerSwitcher) {
|
|
1514
1542
|
const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
|
|
1543
|
+
if (parent.resumeSnapshot) {
|
|
1544
|
+
this.tokenizer.resume(parent.resumeSnapshot);
|
|
1545
|
+
}
|
|
1515
1546
|
this.tokenizer = switcher.tokenizer;
|
|
1516
1547
|
}
|
|
1517
1548
|
if (parent.__logicType === FakeType.ForItem) {
|
|
@@ -1606,7 +1637,7 @@ class Interpreter {
|
|
|
1606
1637
|
} else {
|
|
1607
1638
|
const valueIsMapKey = Reflect.has(data[Keys.Raw], value);
|
|
1608
1639
|
const val = data[Keys.Raw][value];
|
|
1609
|
-
if (typeof val === 'function') {
|
|
1640
|
+
if (typeof val === 'function' || val instanceof InlineFragment) {
|
|
1610
1641
|
_node = this.componentOrFragmentDeclaration(val, ctx);
|
|
1611
1642
|
} else {
|
|
1612
1643
|
const str = valueIsMapKey ? value : this.getFn(data, value);
|
|
@@ -1618,11 +1649,15 @@ class Interpreter {
|
|
|
1618
1649
|
_node = this.createNode(value);
|
|
1619
1650
|
}
|
|
1620
1651
|
this.tokenizer.nextToken();
|
|
1621
|
-
this.
|
|
1622
|
-
this.extensionLines(_node);
|
|
1652
|
+
this.headerLineAndExtensions(_node);
|
|
1623
1653
|
this.onePropParsed = this.oneRealPropParsed;
|
|
1624
1654
|
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
1625
1655
|
this.tokenizer = _node.tokenizer;
|
|
1656
|
+
if (_node.fragmentSnapshot) {
|
|
1657
|
+
this.tokenizer.resume(_node.fragmentSnapshot);
|
|
1658
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1659
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1660
|
+
}
|
|
1626
1661
|
}
|
|
1627
1662
|
return _node;
|
|
1628
1663
|
}
|
|
@@ -1704,7 +1739,7 @@ class Interpreter {
|
|
|
1704
1739
|
_forNode$snapshot.isFirstToken;
|
|
1705
1740
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1706
1741
|
let isFirstRender = true;
|
|
1707
|
-
forNode.effect = new Effect(() => {
|
|
1742
|
+
forNode.effect = new this.Effect(() => {
|
|
1708
1743
|
let arr = arrSignal.get();
|
|
1709
1744
|
arr[Keys.Iterator];
|
|
1710
1745
|
const prevCtx = getPulling();
|
|
@@ -1875,7 +1910,7 @@ class Interpreter {
|
|
|
1875
1910
|
}
|
|
1876
1911
|
}
|
|
1877
1912
|
};
|
|
1878
|
-
});
|
|
1913
|
+
}, ScheduleType.Render);
|
|
1879
1914
|
return forNode.children[0] || forNode;
|
|
1880
1915
|
}
|
|
1881
1916
|
insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
|
|
@@ -1981,33 +2016,42 @@ class Interpreter {
|
|
|
1981
2016
|
return this.setProp(node, key, value, hookI);
|
|
1982
2017
|
}).get();
|
|
1983
2018
|
} else if (typeof value === 'function') {
|
|
1984
|
-
new Effect(() => {
|
|
2019
|
+
new this.Effect(() => {
|
|
1985
2020
|
const res = value(data);
|
|
1986
2021
|
const dispose = this.setProp(node, key, res, hookI);
|
|
1987
2022
|
return dispose;
|
|
1988
|
-
});
|
|
2023
|
+
}, ScheduleType.Render);
|
|
1989
2024
|
} else if (valueIsMapKey) {
|
|
1990
|
-
new Effect(() => {
|
|
2025
|
+
new this.Effect(() => {
|
|
1991
2026
|
const res = data[value];
|
|
1992
2027
|
const dispose = this.setProp(node, key, res, hookI);
|
|
1993
2028
|
return dispose;
|
|
1994
|
-
});
|
|
2029
|
+
}, ScheduleType.Render);
|
|
1995
2030
|
} else {
|
|
1996
2031
|
this.setProp(node, key, value, hookI);
|
|
1997
2032
|
}
|
|
1998
2033
|
}
|
|
1999
2034
|
oneRealPropParsed = this.onePropParsed.bind(this);
|
|
2000
2035
|
componentOrFragmentDeclaration(ComponentOrRender, ctx) {
|
|
2001
|
-
let Component,
|
|
2036
|
+
let Component, tokenizer, child, fragmentSnapshot, resumeSnapshot;
|
|
2002
2037
|
const isCC = ComponentOrRender.prototype instanceof Store;
|
|
2003
2038
|
if (isCC) {
|
|
2004
2039
|
Component = ComponentOrRender;
|
|
2005
2040
|
child = Component.new();
|
|
2041
|
+
tokenizer = child.ui(true);
|
|
2042
|
+
} else if (ComponentOrRender instanceof InlineFragment) {
|
|
2043
|
+
const conf = ComponentOrRender;
|
|
2044
|
+
child = deepSignal({}, getPulling(), true);
|
|
2045
|
+
Object.setPrototypeOf(child, conf.data);
|
|
2046
|
+
tokenizer = conf.tokenizer;
|
|
2047
|
+
fragmentSnapshot = conf.snapshot;
|
|
2048
|
+
resumeSnapshot = tokenizer.snapshot(['token', 'needIndent', 'isFirstToken', 'dentStack', 'isFirstToken', 'useDedentAsEof']);
|
|
2006
2049
|
} else {
|
|
2007
|
-
render = ComponentOrRender;
|
|
2050
|
+
const render = ComponentOrRender;
|
|
2008
2051
|
const boundStore = render.boundStore;
|
|
2009
2052
|
child = deepSignal({}, getPulling(), true);
|
|
2010
2053
|
Object.setPrototypeOf(child, boundStore);
|
|
2054
|
+
tokenizer = render(true);
|
|
2011
2055
|
}
|
|
2012
2056
|
const node = {
|
|
2013
2057
|
__logicType: isCC ? FakeType.Component : FakeType.Fragment,
|
|
@@ -2015,7 +2059,9 @@ class Interpreter {
|
|
|
2015
2059
|
realBefore: null,
|
|
2016
2060
|
realAfter: null,
|
|
2017
2061
|
data: child,
|
|
2018
|
-
tokenizer
|
|
2062
|
+
tokenizer,
|
|
2063
|
+
fragmentSnapshot,
|
|
2064
|
+
resumeSnapshot
|
|
2019
2065
|
};
|
|
2020
2066
|
this.onePropParsed = createStoreOnePropParsed(child);
|
|
2021
2067
|
node.realAfter = this.insertAfterAnchor('component-after');
|
|
@@ -2114,7 +2160,7 @@ class Interpreter {
|
|
|
2114
2160
|
}
|
|
2115
2161
|
ifNode.condition = signal;
|
|
2116
2162
|
ifNode.realAfter = this.insertAfterAnchor(`${keyWord.value}-after`);
|
|
2117
|
-
const ef = effect(({
|
|
2163
|
+
const ef = this.effect(({
|
|
2118
2164
|
val
|
|
2119
2165
|
}) => {
|
|
2120
2166
|
if (val) {
|
|
@@ -2135,7 +2181,9 @@ class Interpreter {
|
|
|
2135
2181
|
}
|
|
2136
2182
|
}
|
|
2137
2183
|
ifNode.isFirstRender = false;
|
|
2138
|
-
}, [signal]
|
|
2184
|
+
}, [signal], {
|
|
2185
|
+
type: 'render'
|
|
2186
|
+
});
|
|
2139
2187
|
ifNode.effect = ef;
|
|
2140
2188
|
return ifNode;
|
|
2141
2189
|
}
|
|
@@ -2150,26 +2198,38 @@ class Interpreter {
|
|
|
2150
2198
|
point = next;
|
|
2151
2199
|
}
|
|
2152
2200
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2201
|
+
headerLineAndExtensions(_node) {
|
|
2202
|
+
const tokenizer = this.tokenizer;
|
|
2203
|
+
do {
|
|
2204
|
+
const isComponent = _node.__logicType & TokenizerSwitcherBit;
|
|
2205
|
+
let snapshot, dentLen;
|
|
2206
|
+
const data = this.getData();
|
|
2207
|
+
const unHandledKey = this.attributeList(_node, data);
|
|
2208
|
+
if (isComponent) {
|
|
2209
|
+
snapshot = tokenizer.snapshot(undefined, -1);
|
|
2210
|
+
dentLen = tokenizer.dentStack[tokenizer.dentStack.length - 1];
|
|
2157
2211
|
}
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2212
|
+
tokenizer.nextToken();
|
|
2213
|
+
if ((tokenizer.token.type & TokenType.Pipe) === 0) {
|
|
2214
|
+
if (isComponent && tokenizer.token.type & TokenType.Indent) {
|
|
2215
|
+
this.inlineFragment(_node, snapshot, data, unHandledKey);
|
|
2216
|
+
tokenizer.skip(dentLen);
|
|
2217
|
+
if ((tokenizer.token.type & TokenType.Pipe) === 0) {
|
|
2218
|
+
break;
|
|
2219
|
+
}
|
|
2220
|
+
} else {
|
|
2221
|
+
break;
|
|
2222
|
+
}
|
|
2162
2223
|
}
|
|
2163
|
-
|
|
2164
|
-
}
|
|
2224
|
+
tokenizer.nextToken();
|
|
2225
|
+
} while (true);
|
|
2165
2226
|
}
|
|
2166
|
-
|
|
2167
|
-
this.
|
|
2168
|
-
this.
|
|
2227
|
+
inlineFragment(_node, snapshot, data, key = 'children') {
|
|
2228
|
+
const value = new InlineFragment(snapshot, data, key, this.tokenizer);
|
|
2229
|
+
this.onePropParsed(data, _node, key, value, false, true);
|
|
2169
2230
|
}
|
|
2170
|
-
attributeList(_node) {
|
|
2231
|
+
attributeList(_node, data) {
|
|
2171
2232
|
let key, eq;
|
|
2172
|
-
const data = this.getData();
|
|
2173
2233
|
while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
|
|
2174
2234
|
if (key == null) {
|
|
2175
2235
|
key = this.tokenizer.token.value;
|
|
@@ -2217,10 +2277,15 @@ class Interpreter {
|
|
|
2217
2277
|
}
|
|
2218
2278
|
this.tokenizer.nextToken();
|
|
2219
2279
|
}
|
|
2280
|
+
return key;
|
|
2220
2281
|
}
|
|
2221
2282
|
config(opt) {
|
|
2222
2283
|
Object.assign(this, opt);
|
|
2223
2284
|
this.opt = opt;
|
|
2285
|
+
if (opt.noopEffect) {
|
|
2286
|
+
this.effect = noopEffect;
|
|
2287
|
+
this.Effect = NoopEffect;
|
|
2288
|
+
}
|
|
2224
2289
|
}
|
|
2225
2290
|
createNode(name) {
|
|
2226
2291
|
return {
|
|
@@ -2270,6 +2335,8 @@ class Interpreter {
|
|
|
2270
2335
|
setProp(node, key, value, hookI) {
|
|
2271
2336
|
node.props[key] = value;
|
|
2272
2337
|
}
|
|
2338
|
+
Effect = Effect;
|
|
2339
|
+
effect = effect$1;
|
|
2273
2340
|
}
|
|
2274
2341
|
function createStoreOnePropParsed(child) {
|
|
2275
2342
|
const onePropParsed = (data, _, key, value, valueIsMapKey, isFn, hookI) => {
|
|
@@ -2294,6 +2361,15 @@ function createStoreOnePropParsed(child) {
|
|
|
2294
2361
|
};
|
|
2295
2362
|
return onePropParsed;
|
|
2296
2363
|
}
|
|
2364
|
+
class InlineFragment {
|
|
2365
|
+
[Keys.ProxyFreeObject] = true;
|
|
2366
|
+
constructor(snapshot, data, key, tokenizer) {
|
|
2367
|
+
this.snapshot = snapshot;
|
|
2368
|
+
this.data = data;
|
|
2369
|
+
this.key = key;
|
|
2370
|
+
this.tokenizer = tokenizer;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2297
2373
|
|
|
2298
2374
|
function bobe(fragments, ...values) {
|
|
2299
2375
|
const ui = function ui(isSub) {
|
|
@@ -2340,5 +2416,29 @@ const context = name => {
|
|
|
2340
2416
|
return context;
|
|
2341
2417
|
};
|
|
2342
2418
|
|
|
2343
|
-
|
|
2419
|
+
const depTokenizer = new Tokenizer(() => '', false);
|
|
2420
|
+
const effect = (callback, depOrOpt, opt) => {
|
|
2421
|
+
const isArray = Array.isArray(depOrOpt);
|
|
2422
|
+
const isSingleDep = isDep(depOrOpt);
|
|
2423
|
+
const deps = isArray ? depOrOpt : isSingleDep ? [depOrOpt] : [];
|
|
2424
|
+
const option = isArray || isSingleDep ? opt : depOrOpt;
|
|
2425
|
+
const newDeps = [];
|
|
2426
|
+
for (let i = 0; i < deps.length; i++) {
|
|
2427
|
+
const dep = deps[i];
|
|
2428
|
+
if (typeof dep === 'string') {
|
|
2429
|
+
depTokenizer.code = dep.trim() + '\n';
|
|
2430
|
+
let exp;
|
|
2431
|
+
while (depTokenizer.i < depTokenizer.code.length) {
|
|
2432
|
+
exp = depTokenizer.jsExp().value;
|
|
2433
|
+
depTokenizer.nextToken();
|
|
2434
|
+
newDeps.push(new Function('data', `let v;with(data){v=${exp};}return v;`).bind(undefined, Store.Current));
|
|
2435
|
+
}
|
|
2436
|
+
} else {
|
|
2437
|
+
newDeps.push(dep);
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
return effect$1(callback, newDeps, option);
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
export { Compiler, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
2344
2444
|
//# sourceMappingURL=bobe.compiler.esm.js.map
|