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/bobe.cjs.js
CHANGED
|
@@ -19,6 +19,7 @@ let TokenType = function (TokenType) {
|
|
|
19
19
|
TokenType[TokenType["Boolean"] = 4096] = "Boolean";
|
|
20
20
|
TokenType[TokenType["Null"] = 8192] = "Null";
|
|
21
21
|
TokenType[TokenType["Undefined"] = 16384] = "Undefined";
|
|
22
|
+
TokenType[TokenType["Comment"] = 32768] = "Comment";
|
|
22
23
|
return TokenType;
|
|
23
24
|
}({});
|
|
24
25
|
const BaseTokenType = TokenType.String | TokenType.Number | TokenType.Boolean | TokenType.Null | TokenType.Undefined;
|
|
@@ -65,8 +66,9 @@ let ParseErrorCode = function (ParseErrorCode) {
|
|
|
65
66
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_COLLECTION"] = 9012] = "MISSING_FOR_COLLECTION";
|
|
66
67
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_SEMICOLON"] = 9013] = "MISSING_FOR_SEMICOLON";
|
|
67
68
|
ParseErrorCode[ParseErrorCode["MISSING_FOR_ITEM"] = 9014] = "MISSING_FOR_ITEM";
|
|
68
|
-
ParseErrorCode[ParseErrorCode["
|
|
69
|
-
ParseErrorCode[ParseErrorCode["
|
|
69
|
+
ParseErrorCode[ParseErrorCode["MISSING_COMMENT_SECOND_SLASH"] = 9015] = "MISSING_COMMENT_SECOND_SLASH";
|
|
70
|
+
ParseErrorCode[ParseErrorCode["MISSING_PROP_ASSIGNMENT"] = 9016] = "MISSING_PROP_ASSIGNMENT";
|
|
71
|
+
ParseErrorCode[ParseErrorCode["PIPE_IN_WRONG_CONTEXT"] = 9017] = "PIPE_IN_WRONG_CONTEXT";
|
|
70
72
|
return ParseErrorCode;
|
|
71
73
|
}({});
|
|
72
74
|
class ParseSyntaxError extends SyntaxError {
|
|
@@ -269,6 +271,9 @@ class Tokenizer {
|
|
|
269
271
|
default:
|
|
270
272
|
if (false) ;
|
|
271
273
|
switch (char) {
|
|
274
|
+
case '/':
|
|
275
|
+
this.comment();
|
|
276
|
+
break;
|
|
272
277
|
case "'":
|
|
273
278
|
case '"':
|
|
274
279
|
this.str(char);
|
|
@@ -306,6 +311,21 @@ class Tokenizer {
|
|
|
306
311
|
this.handledTokens.push(this.token);
|
|
307
312
|
}
|
|
308
313
|
}
|
|
314
|
+
getComment() {
|
|
315
|
+
let value = '/';
|
|
316
|
+
let nextC = this.code[this.i + 1];
|
|
317
|
+
if (nextC !== '/') {
|
|
318
|
+
throw new ParseSyntaxError(ParseErrorCode.MISSING_COMMENT_SECOND_SLASH, '注释开头必须是 //', this.emptyLoc());
|
|
319
|
+
}
|
|
320
|
+
while (this.code[this.i + 1] !== '\n') {
|
|
321
|
+
this.next();
|
|
322
|
+
value += this.code[this.i];
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
comment() {
|
|
327
|
+
this.getComment();
|
|
328
|
+
}
|
|
309
329
|
condExp() {
|
|
310
330
|
let value = '';
|
|
311
331
|
this.token = null;
|
|
@@ -319,14 +339,17 @@ class Tokenizer {
|
|
|
319
339
|
this.next();
|
|
320
340
|
}
|
|
321
341
|
value += this.code[this.i];
|
|
322
|
-
const trimmed = value.trim();
|
|
323
|
-
this.setToken(TokenType.Identifier, trimmed ?
|
|
342
|
+
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
343
|
+
this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
|
|
324
344
|
return this.token;
|
|
325
345
|
} finally {
|
|
326
346
|
this.next();
|
|
327
347
|
this.handledTokens.push(this.token);
|
|
328
348
|
}
|
|
329
349
|
}
|
|
350
|
+
isEol(i) {
|
|
351
|
+
return this.code[i] === '\n' || this.code[i] === '/';
|
|
352
|
+
}
|
|
330
353
|
jsExp() {
|
|
331
354
|
this.token = null;
|
|
332
355
|
let value = '';
|
|
@@ -357,6 +380,13 @@ class Tokenizer {
|
|
|
357
380
|
}
|
|
358
381
|
return this.code[i];
|
|
359
382
|
}
|
|
383
|
+
peekCharIsEol() {
|
|
384
|
+
const char = this.peekChar();
|
|
385
|
+
return char === '\n' || char === '/';
|
|
386
|
+
}
|
|
387
|
+
charIsEol(char) {
|
|
388
|
+
return char === '\n' || char === '/';
|
|
389
|
+
}
|
|
360
390
|
assignment() {
|
|
361
391
|
this.setToken(TokenType.Assign, '=');
|
|
362
392
|
}
|
|
@@ -476,6 +506,9 @@ class Tokenizer {
|
|
|
476
506
|
case '\n':
|
|
477
507
|
nextC = '\n';
|
|
478
508
|
break;
|
|
509
|
+
case '/':
|
|
510
|
+
nextC = '/';
|
|
511
|
+
break;
|
|
479
512
|
default:
|
|
480
513
|
nextC = '';
|
|
481
514
|
break;
|
|
@@ -484,6 +517,12 @@ class Tokenizer {
|
|
|
484
517
|
isEmptyLine = true;
|
|
485
518
|
break;
|
|
486
519
|
}
|
|
520
|
+
if (nextC === '/') {
|
|
521
|
+
value += this.getComment();
|
|
522
|
+
this.next();
|
|
523
|
+
isEmptyLine = true;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
487
526
|
if (!nextC) {
|
|
488
527
|
break;
|
|
489
528
|
}
|
|
@@ -513,6 +552,7 @@ class Tokenizer {
|
|
|
513
552
|
isEmptyLine = _this$getDentValue2.isEmptyLine;
|
|
514
553
|
if (isEmptyLine) {
|
|
515
554
|
this.needIndent = true;
|
|
555
|
+
this.next();
|
|
516
556
|
return;
|
|
517
557
|
}
|
|
518
558
|
this.needIndent = false;
|
|
@@ -922,6 +962,7 @@ var NodeType = function (NodeType) {
|
|
|
922
962
|
NodeType["Element"] = "Element";
|
|
923
963
|
NodeType["Text"] = "Text";
|
|
924
964
|
NodeType["Interpolation"] = "Interpolation";
|
|
965
|
+
NodeType["Comment"] = "Comment";
|
|
925
966
|
NodeType["Property"] = "Property";
|
|
926
967
|
NodeType["PropertyKey"] = "PropertyKey";
|
|
927
968
|
NodeType["StaticValue"] = "StaticValue";
|
|
@@ -1592,7 +1633,7 @@ class Interpreter {
|
|
|
1592
1633
|
i: 0
|
|
1593
1634
|
};
|
|
1594
1635
|
if (keyExp) {
|
|
1595
|
-
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
|
|
1636
|
+
forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
|
|
1596
1637
|
}
|
|
1597
1638
|
window['for1'] = forNode;
|
|
1598
1639
|
const data = this.getData();
|