bobe 0.0.39 → 0.0.41
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 +46 -5
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +46 -5
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +46 -5
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +46 -5
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.umd.js +46 -5
- 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,21 @@
|
|
|
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
|
+
}
|
|
310
330
|
condExp() {
|
|
311
331
|
let value = '';
|
|
312
332
|
this.token = null;
|
|
@@ -320,14 +340,17 @@
|
|
|
320
340
|
this.next();
|
|
321
341
|
}
|
|
322
342
|
value += this.code[this.i];
|
|
323
|
-
const trimmed = value.trim();
|
|
324
|
-
this.setToken(TokenType.Identifier, trimmed ?
|
|
343
|
+
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
344
|
+
this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
|
|
325
345
|
return this.token;
|
|
326
346
|
} finally {
|
|
327
347
|
this.next();
|
|
328
348
|
this.handledTokens.push(this.token);
|
|
329
349
|
}
|
|
330
350
|
}
|
|
351
|
+
isEol(i) {
|
|
352
|
+
return this.code[i] === '\n' || this.code[i] === '/';
|
|
353
|
+
}
|
|
331
354
|
jsExp() {
|
|
332
355
|
this.token = null;
|
|
333
356
|
let value = '';
|
|
@@ -358,6 +381,13 @@
|
|
|
358
381
|
}
|
|
359
382
|
return this.code[i];
|
|
360
383
|
}
|
|
384
|
+
peekCharIsEol() {
|
|
385
|
+
const char = this.peekChar();
|
|
386
|
+
return char === '\n' || char === '/';
|
|
387
|
+
}
|
|
388
|
+
charIsEol(char) {
|
|
389
|
+
return char === '\n' || char === '/';
|
|
390
|
+
}
|
|
361
391
|
assignment() {
|
|
362
392
|
this.setToken(TokenType.Assign, '=');
|
|
363
393
|
}
|
|
@@ -477,6 +507,9 @@
|
|
|
477
507
|
case '\n':
|
|
478
508
|
nextC = '\n';
|
|
479
509
|
break;
|
|
510
|
+
case '/':
|
|
511
|
+
nextC = '/';
|
|
512
|
+
break;
|
|
480
513
|
default:
|
|
481
514
|
nextC = '';
|
|
482
515
|
break;
|
|
@@ -485,6 +518,12 @@
|
|
|
485
518
|
isEmptyLine = true;
|
|
486
519
|
break;
|
|
487
520
|
}
|
|
521
|
+
if (nextC === '/') {
|
|
522
|
+
value += this.getComment();
|
|
523
|
+
this.next();
|
|
524
|
+
isEmptyLine = true;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
488
527
|
if (!nextC) {
|
|
489
528
|
break;
|
|
490
529
|
}
|
|
@@ -514,6 +553,7 @@
|
|
|
514
553
|
isEmptyLine = _this$getDentValue2.isEmptyLine;
|
|
515
554
|
if (isEmptyLine) {
|
|
516
555
|
this.needIndent = true;
|
|
556
|
+
this.next();
|
|
517
557
|
return;
|
|
518
558
|
}
|
|
519
559
|
this.needIndent = false;
|
|
@@ -923,6 +963,7 @@
|
|
|
923
963
|
NodeType["Element"] = "Element";
|
|
924
964
|
NodeType["Text"] = "Text";
|
|
925
965
|
NodeType["Interpolation"] = "Interpolation";
|
|
966
|
+
NodeType["Comment"] = "Comment";
|
|
926
967
|
NodeType["Property"] = "Property";
|
|
927
968
|
NodeType["PropertyKey"] = "PropertyKey";
|
|
928
969
|
NodeType["StaticValue"] = "StaticValue";
|
|
@@ -1593,7 +1634,7 @@
|
|
|
1593
1634
|
i: 0
|
|
1594
1635
|
};
|
|
1595
1636
|
if (keyExp) {
|
|
1596
|
-
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
|
|
1637
|
+
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
|
|
1597
1638
|
}
|
|
1598
1639
|
window['for1'] = forNode;
|
|
1599
1640
|
const data = this.getData();
|