bobe 0.0.41 → 0.0.43
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 +72 -53
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +79 -62
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +80 -63
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +73 -54
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.umd.js +72 -53
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ declare class Interpreter {
|
|
|
49
49
|
oneRealPropParsed: Interpreter['onePropParsed'];
|
|
50
50
|
componentOrFragmentDeclaration(ComponentOrRender: BobeUI | typeof Store, ctx: ProgramCtx): ComponentNode$1;
|
|
51
51
|
getFn(data: any, expression: string | number): any;
|
|
52
|
+
getAssignFn(data: any, expression: string | number): any;
|
|
52
53
|
condDeclaration(ctx: ProgramCtx): IfNode;
|
|
53
54
|
removeLogicNode(node: LogicNode): void;
|
|
54
55
|
/**
|
|
@@ -89,7 +90,7 @@ declare class Interpreter {
|
|
|
89
90
|
defaultInsert(parent: any, node: any, prev: any): void;
|
|
90
91
|
remove(node: any, parent?: any, prev?: any): void;
|
|
91
92
|
defaultRemove(node: any, parent: any, prevSibling: any): void;
|
|
92
|
-
setProp(node: any, key: string, value: any, hookI?: number): void;
|
|
93
|
+
setProp(node: any, key: string, value: any, hookI?: number): void | undefined | (() => void);
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
interface StackNode<T> {
|
|
@@ -347,6 +348,7 @@ declare class Tokenizer {
|
|
|
347
348
|
private dent;
|
|
348
349
|
private shorterThanBaseDentEof;
|
|
349
350
|
private identifier;
|
|
351
|
+
private getStr;
|
|
350
352
|
private str;
|
|
351
353
|
private number;
|
|
352
354
|
private eof;
|
package/dist/index.umd.js
CHANGED
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
if (!this.token) return false;
|
|
228
228
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
229
229
|
}
|
|
230
|
-
setToken(type, value) {
|
|
230
|
+
setToken(type, value, dt = 1) {
|
|
231
231
|
this.token = {
|
|
232
232
|
type,
|
|
233
233
|
typeName: TokenType[type],
|
|
@@ -330,23 +330,19 @@
|
|
|
330
330
|
condExp() {
|
|
331
331
|
let value = '';
|
|
332
332
|
this.token = null;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
while (this.code[this.i + 1] !== '\n') {
|
|
339
|
-
value += this.code[this.i];
|
|
340
|
-
this.next();
|
|
333
|
+
let char = this.code[this.i];
|
|
334
|
+
while (char !== '\n') {
|
|
335
|
+
if (char === '"' || char === "'") {
|
|
336
|
+
value += char + this.getStr(char);
|
|
341
337
|
}
|
|
342
338
|
value += this.code[this.i];
|
|
343
|
-
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
344
|
-
this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
|
|
345
|
-
return this.token;
|
|
346
|
-
} finally {
|
|
347
339
|
this.next();
|
|
348
|
-
this.
|
|
340
|
+
char = this.code[this.i];
|
|
349
341
|
}
|
|
342
|
+
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
343
|
+
this.setToken(TokenType.Identifier, trimmed ? trimmed : true, 0);
|
|
344
|
+
this.handledTokens.push(this.token);
|
|
345
|
+
return this.token;
|
|
350
346
|
}
|
|
351
347
|
isEol(i) {
|
|
352
348
|
return this.code[i] === '\n' || this.code[i] === '/';
|
|
@@ -354,25 +350,18 @@
|
|
|
354
350
|
jsExp() {
|
|
355
351
|
this.token = null;
|
|
356
352
|
let value = '';
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (char === '
|
|
360
|
-
this.
|
|
361
|
-
return this.token;
|
|
362
|
-
}
|
|
363
|
-
let nextC = this.code[this.i + 1];
|
|
364
|
-
while (nextC !== ';' && nextC !== '\n') {
|
|
365
|
-
value += this.code[this.i];
|
|
366
|
-
this.next();
|
|
367
|
-
nextC = this.code[this.i + 1];
|
|
353
|
+
let char = this.code[this.i];
|
|
354
|
+
while (char !== ';' && char !== '\n') {
|
|
355
|
+
if (char === '"' || char === "'") {
|
|
356
|
+
value += char + this.getStr(char);
|
|
368
357
|
}
|
|
369
358
|
value += this.code[this.i];
|
|
370
|
-
this.setToken(TokenType.Identifier, value);
|
|
371
|
-
return this.token;
|
|
372
|
-
} finally {
|
|
373
359
|
this.next();
|
|
374
|
-
this.
|
|
360
|
+
char = this.code[this.i];
|
|
375
361
|
}
|
|
362
|
+
this.setToken(TokenType.Identifier, value, 0);
|
|
363
|
+
this.handledTokens.push(this.token);
|
|
364
|
+
return this.token;
|
|
376
365
|
}
|
|
377
366
|
peekChar() {
|
|
378
367
|
let i = this.i;
|
|
@@ -430,10 +419,8 @@
|
|
|
430
419
|
startLine = this.line,
|
|
431
420
|
startCol = this.preCol;
|
|
432
421
|
let inComment,
|
|
433
|
-
inString,
|
|
434
422
|
count = 0,
|
|
435
|
-
value = ''
|
|
436
|
-
backslashCount = 0;
|
|
423
|
+
value = '';
|
|
437
424
|
while (1) {
|
|
438
425
|
const char = this.code[this.i];
|
|
439
426
|
if (char === undefined) {
|
|
@@ -446,11 +433,6 @@
|
|
|
446
433
|
inComment = null;
|
|
447
434
|
value += this.code[this.i];
|
|
448
435
|
this.next();
|
|
449
|
-
} else if (inString) {
|
|
450
|
-
if (char === inString && backslashCount % 2 === 0) {
|
|
451
|
-
inString = null;
|
|
452
|
-
}
|
|
453
|
-
backslashCount = char === '\\' ? backslashCount + 1 : 0;
|
|
454
436
|
} else {
|
|
455
437
|
if (char === '/' && nextChar === '/') {
|
|
456
438
|
inComment = 'single';
|
|
@@ -460,15 +442,15 @@
|
|
|
460
442
|
inComment = 'multi';
|
|
461
443
|
value += this.code[this.i];
|
|
462
444
|
this.next();
|
|
463
|
-
} else if (char === "'" || char === '"'
|
|
464
|
-
|
|
445
|
+
} else if (char === "'" || char === '"') {
|
|
446
|
+
value += char + this.getStr(char);
|
|
465
447
|
} else if (char === '{') {
|
|
466
448
|
count++;
|
|
467
449
|
} else if (char === '}') {
|
|
468
450
|
count--;
|
|
469
451
|
}
|
|
470
452
|
}
|
|
471
|
-
if (count === 0 &&
|
|
453
|
+
if (count === 0 && inComment == null) {
|
|
472
454
|
return value.slice(1);
|
|
473
455
|
}
|
|
474
456
|
value += this.code[this.i];
|
|
@@ -664,7 +646,7 @@
|
|
|
664
646
|
}
|
|
665
647
|
this.setToken(tokenType, realValue);
|
|
666
648
|
}
|
|
667
|
-
|
|
649
|
+
getStr(head, parseEscape = true) {
|
|
668
650
|
const startOffset = this.preI,
|
|
669
651
|
startLine = this.line,
|
|
670
652
|
startCol = this.preCol;
|
|
@@ -683,11 +665,20 @@
|
|
|
683
665
|
continuousBackslashCount = 0;
|
|
684
666
|
}
|
|
685
667
|
this.next();
|
|
686
|
-
if (nextC ===
|
|
668
|
+
if (nextC === head && memoCount % 2 === 0) {
|
|
687
669
|
break;
|
|
688
670
|
}
|
|
689
|
-
|
|
671
|
+
const mapped = bobeShared.escapeMap[nextC];
|
|
672
|
+
if (parseEscape && mapped) {
|
|
673
|
+
value += mapped;
|
|
674
|
+
} else {
|
|
675
|
+
value += nextC;
|
|
676
|
+
}
|
|
690
677
|
}
|
|
678
|
+
return value;
|
|
679
|
+
}
|
|
680
|
+
str(char) {
|
|
681
|
+
const value = this.getStr(char, false);
|
|
691
682
|
this.setToken(TokenType.String, value);
|
|
692
683
|
}
|
|
693
684
|
number(char) {
|
|
@@ -1127,7 +1118,7 @@
|
|
|
1127
1118
|
}
|
|
1128
1119
|
parseLoopNode(node) {
|
|
1129
1120
|
const forLoc = this.tokenizer.token.loc ?? this.tokenizer.emptyLoc();
|
|
1130
|
-
this.tokenizer.
|
|
1121
|
+
this.tokenizer.jsExp();
|
|
1131
1122
|
const collection = this.parseJsExp();
|
|
1132
1123
|
if (!collection.value && collection.value !== 0) {
|
|
1133
1124
|
this.addError(ParseErrorCode.MISSING_FOR_COLLECTION, '"for" 缺少集合表达式', forLoc, node);
|
|
@@ -1588,7 +1579,7 @@
|
|
|
1588
1579
|
return _node;
|
|
1589
1580
|
}
|
|
1590
1581
|
forDeclaration() {
|
|
1591
|
-
const arrExp = this.tokenizer.
|
|
1582
|
+
const arrExp = this.tokenizer.jsExp().value;
|
|
1592
1583
|
this.tokenizer.nextToken();
|
|
1593
1584
|
const itemToken = this.tokenizer.nextToken();
|
|
1594
1585
|
const isDestruct = itemToken.type === TokenType.InsertionExp;
|
|
@@ -1919,16 +1910,20 @@
|
|
|
1919
1910
|
}
|
|
1920
1911
|
onePropParsed(data, node, key, value, valueIsMapKey, isFn, hookI) {
|
|
1921
1912
|
if (isFn) {
|
|
1922
|
-
|
|
1913
|
+
new aoye.Scope(() => {
|
|
1914
|
+
return this.setProp(node, key, value, hookI);
|
|
1915
|
+
}).get();
|
|
1923
1916
|
} else if (typeof value === 'function') {
|
|
1924
1917
|
new aoye.Effect(() => {
|
|
1925
|
-
const res = value();
|
|
1926
|
-
this.setProp(node, key, res, hookI);
|
|
1918
|
+
const res = value(data);
|
|
1919
|
+
const dispose = this.setProp(node, key, res, hookI);
|
|
1920
|
+
return dispose;
|
|
1927
1921
|
});
|
|
1928
1922
|
} else if (valueIsMapKey) {
|
|
1929
1923
|
new aoye.Effect(() => {
|
|
1930
1924
|
const res = data[value];
|
|
1931
|
-
this.setProp(node, key, res, hookI);
|
|
1925
|
+
const dispose = this.setProp(node, key, res, hookI);
|
|
1926
|
+
return dispose;
|
|
1932
1927
|
});
|
|
1933
1928
|
} else {
|
|
1934
1929
|
this.setProp(node, key, value, hookI);
|
|
@@ -1953,7 +1948,7 @@
|
|
|
1953
1948
|
realBefore: null,
|
|
1954
1949
|
realAfter: null,
|
|
1955
1950
|
data: child,
|
|
1956
|
-
tokenizer: render ? render(true) : child
|
|
1951
|
+
tokenizer: render ? render(true) : child.ui(true)
|
|
1957
1952
|
};
|
|
1958
1953
|
this.onePropParsed = (data, _, key, value, valueIsMapKey, isFn, hookI) => {
|
|
1959
1954
|
if (isFn) {
|
|
@@ -1964,7 +1959,7 @@
|
|
|
1964
1959
|
const meta = child[aoye.Keys.Meta];
|
|
1965
1960
|
const cells = meta.cells;
|
|
1966
1961
|
if (typeof value === 'function') {
|
|
1967
|
-
const computed = new aoye.Computed(value);
|
|
1962
|
+
const computed = new aoye.Computed(() => value(data));
|
|
1968
1963
|
cells.set(key, computed);
|
|
1969
1964
|
child[aoye.Keys.Raw][key] = undefined;
|
|
1970
1965
|
} else {
|
|
@@ -1981,6 +1976,10 @@
|
|
|
1981
1976
|
getFn(data, expression) {
|
|
1982
1977
|
return new Function('data', `let v;with(data){v=${expression}};return v;`).bind(undefined, data);
|
|
1983
1978
|
}
|
|
1979
|
+
getAssignFn(data, expression) {
|
|
1980
|
+
const valueId = `value_bobe_${bobeShared.date32()}`;
|
|
1981
|
+
return new Function('data', valueId, `with(data){${expression}=${valueId}};`).bind(undefined, data);
|
|
1982
|
+
}
|
|
1984
1983
|
condDeclaration(ctx) {
|
|
1985
1984
|
const prevSibling = ctx.prevSibling;
|
|
1986
1985
|
const keyWord = this.tokenizer.token;
|
|
@@ -2134,7 +2133,27 @@
|
|
|
2134
2133
|
hookI = _this$tokenizer$_hook4[2];
|
|
2135
2134
|
const rawVal = data[aoye.Keys.Raw][value];
|
|
2136
2135
|
const isFn = typeof rawVal === 'function';
|
|
2137
|
-
if (
|
|
2136
|
+
if (key === 'ref') {
|
|
2137
|
+
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2138
|
+
let refValue = _node;
|
|
2139
|
+
if (_node.__logicType === FakeType.Component) {
|
|
2140
|
+
refValue = _node.data;
|
|
2141
|
+
} else {
|
|
2142
|
+
refValue[aoye.Keys.ProxyFreeObject] = true;
|
|
2143
|
+
}
|
|
2144
|
+
if (valueIsMapKey) {
|
|
2145
|
+
data[value] = refValue;
|
|
2146
|
+
new aoye.Scope(() => () => {
|
|
2147
|
+
data[value] = null;
|
|
2148
|
+
}).get();
|
|
2149
|
+
} else {
|
|
2150
|
+
const fn = this.getAssignFn(data, value);
|
|
2151
|
+
fn(refValue);
|
|
2152
|
+
new aoye.Scope(() => () => {
|
|
2153
|
+
fn(null);
|
|
2154
|
+
}).get();
|
|
2155
|
+
}
|
|
2156
|
+
} else if (hookType === 'dynamic') {
|
|
2138
2157
|
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2139
2158
|
const fn = isFn ? rawVal : valueIsMapKey ? value : this.getFn(data, value);
|
|
2140
2159
|
this.onePropParsed(data, _node, key, fn, valueIsMapKey, isFn, hookI);
|
|
@@ -2219,7 +2238,7 @@
|
|
|
2219
2238
|
function customRender(option) {
|
|
2220
2239
|
return function render(Ctor, root) {
|
|
2221
2240
|
const store = Ctor.new();
|
|
2222
|
-
const tokenizer = store
|
|
2241
|
+
const tokenizer = store.ui(false);
|
|
2223
2242
|
const terp = new Interpreter(tokenizer);
|
|
2224
2243
|
terp.config(option);
|
|
2225
2244
|
const componentNode = {
|