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.
@@ -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 {
@@ -293,6 +295,9 @@ class Tokenizer {
293
295
  this.needLoc = true;
294
296
  }
295
297
  switch (char) {
298
+ case '/':
299
+ this.comment();
300
+ break;
296
301
  case "'":
297
302
  case '"':
298
303
  this.str(char);
@@ -332,6 +337,21 @@ class Tokenizer {
332
337
  this.handledTokens.push(this.token);
333
338
  }
334
339
  }
340
+ getComment() {
341
+ let value = '/';
342
+ let nextC = this.code[this.i + 1];
343
+ if (nextC !== '/') {
344
+ throw new ParseSyntaxError(ParseErrorCode.MISSING_COMMENT_SECOND_SLASH, '注释开头必须是 //', this.emptyLoc());
345
+ }
346
+ while (this.code[this.i + 1] !== '\n') {
347
+ this.next();
348
+ value += this.code[this.i];
349
+ }
350
+ return value;
351
+ }
352
+ comment() {
353
+ this.getComment();
354
+ }
335
355
  condExp() {
336
356
  {
337
357
  this.preCol = this.column;
@@ -350,8 +370,8 @@ class Tokenizer {
350
370
  this.next();
351
371
  }
352
372
  value += this.code[this.i];
353
- const trimmed = value.trim();
354
- this.setToken(TokenType.Identifier, trimmed ? value : true);
373
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
374
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
355
375
  return this.token;
356
376
  } finally {
357
377
  this.next();
@@ -361,6 +381,9 @@ class Tokenizer {
361
381
  }
362
382
  }
363
383
  }
384
+ isEol(i) {
385
+ return this.code[i] === '\n' || this.code[i] === '/';
386
+ }
364
387
  jsExp() {
365
388
  {
366
389
  this.preCol = this.column;
@@ -399,6 +422,13 @@ class Tokenizer {
399
422
  }
400
423
  return this.code[i];
401
424
  }
425
+ peekCharIsEol() {
426
+ const char = this.peekChar();
427
+ return char === '\n' || char === '/';
428
+ }
429
+ charIsEol(char) {
430
+ return char === '\n' || char === '/';
431
+ }
402
432
  assignment() {
403
433
  this.setToken(TokenType.Assign, '=');
404
434
  }
@@ -518,6 +548,9 @@ class Tokenizer {
518
548
  case '\n':
519
549
  nextC = '\n';
520
550
  break;
551
+ case '/':
552
+ nextC = '/';
553
+ break;
521
554
  default:
522
555
  nextC = '';
523
556
  break;
@@ -526,6 +559,12 @@ class Tokenizer {
526
559
  isEmptyLine = true;
527
560
  break;
528
561
  }
562
+ if (nextC === '/') {
563
+ value += this.getComment();
564
+ this.next();
565
+ isEmptyLine = true;
566
+ break;
567
+ }
529
568
  if (!nextC) {
530
569
  break;
531
570
  }
@@ -555,6 +594,7 @@ class Tokenizer {
555
594
  isEmptyLine = _this$getDentValue2.isEmptyLine;
556
595
  if (isEmptyLine) {
557
596
  this.needIndent = true;
597
+ this.next();
558
598
  return;
559
599
  }
560
600
  this.needIndent = false;
@@ -964,6 +1004,7 @@ var NodeType = function (NodeType) {
964
1004
  NodeType["Element"] = "Element";
965
1005
  NodeType["Text"] = "Text";
966
1006
  NodeType["Interpolation"] = "Interpolation";
1007
+ NodeType["Comment"] = "Comment";
967
1008
  NodeType["Property"] = "Property";
968
1009
  NodeType["PropertyKey"] = "PropertyKey";
969
1010
  NodeType["StaticValue"] = "StaticValue";
@@ -1634,7 +1675,7 @@ class Interpreter {
1634
1675
  i: 0
1635
1676
  };
1636
1677
  if (keyExp) {
1637
- forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
1678
+ forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
1638
1679
  }
1639
1680
  window['for1'] = forNode;
1640
1681
  const data = this.getData();