bobe 0.0.38 → 0.0.40
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 +48 -6
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +48 -6
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +49 -7
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +49 -7
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.umd.js +48 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -138,7 +138,8 @@ declare enum TokenType {
|
|
|
138
138
|
Number = 2048,
|
|
139
139
|
Boolean = 4096,
|
|
140
140
|
Null = 8192,
|
|
141
|
-
Undefined = 16384
|
|
141
|
+
Undefined = 16384,
|
|
142
|
+
Comment = 32768
|
|
142
143
|
}
|
|
143
144
|
declare enum FakeType {
|
|
144
145
|
If = 1,
|
|
@@ -194,8 +195,9 @@ declare enum ParseErrorCode {
|
|
|
194
195
|
MISSING_FOR_COLLECTION = 9012,
|
|
195
196
|
MISSING_FOR_SEMICOLON = 9013,
|
|
196
197
|
MISSING_FOR_ITEM = 9014,
|
|
197
|
-
|
|
198
|
-
|
|
198
|
+
MISSING_COMMENT_SECOND_SLASH = 9015,
|
|
199
|
+
MISSING_PROP_ASSIGNMENT = 9016,
|
|
200
|
+
PIPE_IN_WRONG_CONTEXT = 9017
|
|
199
201
|
}
|
|
200
202
|
type ParseError = {
|
|
201
203
|
code: ParseErrorCode;
|
|
@@ -316,7 +318,14 @@ declare class Tokenizer {
|
|
|
316
318
|
isEof(): boolean;
|
|
317
319
|
private setToken;
|
|
318
320
|
nextToken(): Token;
|
|
321
|
+
getComment(): string;
|
|
322
|
+
/**
|
|
323
|
+
* 处理处于行末尾的 comment 例如:
|
|
324
|
+
* div // 这里是注释
|
|
325
|
+
*/
|
|
326
|
+
comment(): void;
|
|
319
327
|
condExp(): Token;
|
|
328
|
+
isEol(i: number): boolean;
|
|
320
329
|
/**
|
|
321
330
|
* 解析到 for 时使用这个方法获取 for 后方的子表达式
|
|
322
331
|
* 表达式通过 “;” 分割
|
|
@@ -326,6 +335,8 @@ declare class Tokenizer {
|
|
|
326
335
|
*/
|
|
327
336
|
jsExp(): Token;
|
|
328
337
|
peekChar(): string;
|
|
338
|
+
peekCharIsEol(): boolean;
|
|
339
|
+
charIsEol(char: string): char is "/" | "\n";
|
|
329
340
|
private assignment;
|
|
330
341
|
private pipe;
|
|
331
342
|
private staticIns;
|
|
@@ -351,6 +362,7 @@ declare enum NodeType {
|
|
|
351
362
|
Element = "Element",// 真实DOM节点
|
|
352
363
|
Text = "Text",// 文本节点
|
|
353
364
|
Interpolation = "Interpolation",// 插值节点
|
|
365
|
+
Comment = "Comment",// 注释节点
|
|
354
366
|
Property = "Property",// 属性节点
|
|
355
367
|
PropertyKey = "PropertyKey",// 属性节点
|
|
356
368
|
StaticValue = "StaticValue",// 静态值
|
|
@@ -373,13 +385,17 @@ interface Program extends BaseNode {
|
|
|
373
385
|
type: NodeType.Program;
|
|
374
386
|
body: TemplateNode[];
|
|
375
387
|
}
|
|
376
|
-
type TemplateNode = ElementNode | TextNode | InterpolationNode | ConditionalNode | LoopNode | ComponentNode | FragmentNode;
|
|
388
|
+
type TemplateNode = ElementNode | TextNode | InterpolationNode | ConditionalNode | LoopNode | ComponentNode | FragmentNode | CommentNode;
|
|
377
389
|
interface ElementNode extends BaseNode {
|
|
378
390
|
type: NodeType.Element;
|
|
379
391
|
tagName: string;
|
|
380
392
|
props: Property[];
|
|
381
393
|
children: TemplateNode[];
|
|
382
394
|
}
|
|
395
|
+
interface CommentNode extends BaseNode {
|
|
396
|
+
type: NodeType.Comment;
|
|
397
|
+
value: string;
|
|
398
|
+
}
|
|
383
399
|
interface TextNode extends BaseNode {
|
|
384
400
|
type: NodeType.Text;
|
|
385
401
|
value: string;
|
|
@@ -504,4 +520,4 @@ declare function bobe(fragments: TemplateStringsArray, ...values: any[]): BobeUI
|
|
|
504
520
|
declare function customRender(option: CustomRenderConf): <T>(Ctor: typeof Store, root: any) => (ComponentNode$1 | Store)[];
|
|
505
521
|
|
|
506
522
|
export { Compiler, NodeType, ParseErrorCode, ParseSyntaxError, Tokenizer, bobe, customRender };
|
|
507
|
-
export type { ASTNodeType, BaseNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, InterpolationNode, LoopNode, ParseError, Program, Property, PropertyKeyNode, PropertyValue, SourceLocation, StaticValue, TemplateNode, TextNode };
|
|
523
|
+
export type { ASTNodeType, BaseNode, CommentNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, InterpolationNode, LoopNode, ParseError, Program, Property, PropertyKeyNode, PropertyValue, SourceLocation, StaticValue, TemplateNode, TextNode };
|
package/dist/index.umd.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
TokenType[TokenType["Boolean"] = 4096] = "Boolean";
|
|
21
21
|
TokenType[TokenType["Null"] = 8192] = "Null";
|
|
22
22
|
TokenType[TokenType["Undefined"] = 16384] = "Undefined";
|
|
23
|
+
TokenType[TokenType["Comment"] = 32768] = "Comment";
|
|
23
24
|
return TokenType;
|
|
24
25
|
}({});
|
|
25
26
|
const BaseTokenType = TokenType.String | TokenType.Number | TokenType.Boolean | TokenType.Null | TokenType.Undefined;
|
|
@@ -66,8 +67,9 @@
|
|
|
66
67
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_COLLECTION"] = 9012] = "MISSING_FOR_COLLECTION";
|
|
67
68
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_SEMICOLON"] = 9013] = "MISSING_FOR_SEMICOLON";
|
|
68
69
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_ITEM"] = 9014] = "MISSING_FOR_ITEM";
|
|
69
|
-
ParseErrorCode[ParseErrorCode["
|
|
70
|
-
ParseErrorCode[ParseErrorCode["
|
|
70
|
+
ParseErrorCode[ParseErrorCode["MISSING_COMMENT_SECOND_SLASH"] = 9015] = "MISSING_COMMENT_SECOND_SLASH";
|
|
71
|
+
ParseErrorCode[ParseErrorCode["MISSING_PROP_ASSIGNMENT"] = 9016] = "MISSING_PROP_ASSIGNMENT";
|
|
72
|
+
ParseErrorCode[ParseErrorCode["PIPE_IN_WRONG_CONTEXT"] = 9017] = "PIPE_IN_WRONG_CONTEXT";
|
|
71
73
|
return ParseErrorCode;
|
|
72
74
|
}({});
|
|
73
75
|
class ParseSyntaxError extends SyntaxError {
|
|
@@ -270,6 +272,9 @@
|
|
|
270
272
|
default:
|
|
271
273
|
if (false) ;
|
|
272
274
|
switch (char) {
|
|
275
|
+
case '/':
|
|
276
|
+
this.comment();
|
|
277
|
+
break;
|
|
273
278
|
case "'":
|
|
274
279
|
case '"':
|
|
275
280
|
this.str(char);
|
|
@@ -307,6 +312,22 @@
|
|
|
307
312
|
this.handledTokens.push(this.token);
|
|
308
313
|
}
|
|
309
314
|
}
|
|
315
|
+
getComment() {
|
|
316
|
+
let value = '/';
|
|
317
|
+
let nextC = this.code[this.i + 1];
|
|
318
|
+
if (nextC !== '/') {
|
|
319
|
+
throw new ParseSyntaxError(ParseErrorCode.MISSING_COMMENT_SECOND_SLASH, '注释开头必须是 //', this.emptyLoc());
|
|
320
|
+
}
|
|
321
|
+
while (this.code[this.i + 1] !== '\n') {
|
|
322
|
+
this.next();
|
|
323
|
+
value += this.code[this.i];
|
|
324
|
+
}
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
comment() {
|
|
328
|
+
this.getComment();
|
|
329
|
+
this.next();
|
|
330
|
+
}
|
|
310
331
|
condExp() {
|
|
311
332
|
let value = '';
|
|
312
333
|
this.token = null;
|
|
@@ -320,14 +341,17 @@
|
|
|
320
341
|
this.next();
|
|
321
342
|
}
|
|
322
343
|
value += this.code[this.i];
|
|
323
|
-
const trimmed = value.trim();
|
|
324
|
-
this.setToken(TokenType.Identifier, trimmed ?
|
|
344
|
+
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
345
|
+
this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
|
|
325
346
|
return this.token;
|
|
326
347
|
} finally {
|
|
327
348
|
this.next();
|
|
328
349
|
this.handledTokens.push(this.token);
|
|
329
350
|
}
|
|
330
351
|
}
|
|
352
|
+
isEol(i) {
|
|
353
|
+
return this.code[i] === '\n' || this.code[i] === '/';
|
|
354
|
+
}
|
|
331
355
|
jsExp() {
|
|
332
356
|
this.token = null;
|
|
333
357
|
let value = '';
|
|
@@ -358,6 +382,13 @@
|
|
|
358
382
|
}
|
|
359
383
|
return this.code[i];
|
|
360
384
|
}
|
|
385
|
+
peekCharIsEol() {
|
|
386
|
+
const char = this.peekChar();
|
|
387
|
+
return char === '\n' || char === '/';
|
|
388
|
+
}
|
|
389
|
+
charIsEol(char) {
|
|
390
|
+
return char === '\n' || char === '/';
|
|
391
|
+
}
|
|
361
392
|
assignment() {
|
|
362
393
|
this.setToken(TokenType.Assign, '=');
|
|
363
394
|
}
|
|
@@ -477,6 +508,9 @@
|
|
|
477
508
|
case '\n':
|
|
478
509
|
nextC = '\n';
|
|
479
510
|
break;
|
|
511
|
+
case '/':
|
|
512
|
+
nextC = '/';
|
|
513
|
+
break;
|
|
480
514
|
default:
|
|
481
515
|
nextC = '';
|
|
482
516
|
break;
|
|
@@ -485,6 +519,12 @@
|
|
|
485
519
|
isEmptyLine = true;
|
|
486
520
|
break;
|
|
487
521
|
}
|
|
522
|
+
if (nextC === '/') {
|
|
523
|
+
value += this.getComment();
|
|
524
|
+
this.next();
|
|
525
|
+
isEmptyLine = true;
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
488
528
|
if (!nextC) {
|
|
489
529
|
break;
|
|
490
530
|
}
|
|
@@ -514,6 +554,7 @@
|
|
|
514
554
|
isEmptyLine = _this$getDentValue2.isEmptyLine;
|
|
515
555
|
if (isEmptyLine) {
|
|
516
556
|
this.needIndent = true;
|
|
557
|
+
this.next();
|
|
517
558
|
return;
|
|
518
559
|
}
|
|
519
560
|
this.needIndent = false;
|
|
@@ -589,7 +630,7 @@
|
|
|
589
630
|
let nextC;
|
|
590
631
|
while (1) {
|
|
591
632
|
nextC = this.code[this.i + 1];
|
|
592
|
-
if (typeof nextC !== 'string' || !bobeShared.
|
|
633
|
+
if (typeof nextC !== 'string' || !bobeShared.matchId(nextC, 0)) {
|
|
593
634
|
break;
|
|
594
635
|
}
|
|
595
636
|
value += nextC;
|
|
@@ -923,6 +964,7 @@
|
|
|
923
964
|
NodeType["Element"] = "Element";
|
|
924
965
|
NodeType["Text"] = "Text";
|
|
925
966
|
NodeType["Interpolation"] = "Interpolation";
|
|
967
|
+
NodeType["Comment"] = "Comment";
|
|
926
968
|
NodeType["Property"] = "Property";
|
|
927
969
|
NodeType["PropertyKey"] = "PropertyKey";
|
|
928
970
|
NodeType["StaticValue"] = "StaticValue";
|
|
@@ -1593,7 +1635,7 @@
|
|
|
1593
1635
|
i: 0
|
|
1594
1636
|
};
|
|
1595
1637
|
if (keyExp) {
|
|
1596
|
-
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
|
|
1638
|
+
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
|
|
1597
1639
|
}
|
|
1598
1640
|
window['for1'] = forNode;
|
|
1599
1641
|
const data = this.getData();
|