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