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.
@@ -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["MISSING_PROP_ASSIGNMENT"] = 9015] = "MISSING_PROP_ASSIGNMENT";
69
- ParseErrorCode[ParseErrorCode["PIPE_IN_WRONG_CONTEXT"] = 9016] = "PIPE_IN_WRONG_CONTEXT";
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 {
@@ -294,6 +296,9 @@ class Tokenizer {
294
296
  this.needLoc = true;
295
297
  }
296
298
  switch (char) {
299
+ case '/':
300
+ this.comment();
301
+ break;
297
302
  case "'":
298
303
  case '"':
299
304
  this.str(char);
@@ -333,6 +338,22 @@ class Tokenizer {
333
338
  this.handledTokens.push(this.token);
334
339
  }
335
340
  }
341
+ getComment() {
342
+ let value = '/';
343
+ let nextC = this.code[this.i + 1];
344
+ if (nextC !== '/') {
345
+ throw new ParseSyntaxError(ParseErrorCode.MISSING_COMMENT_SECOND_SLASH, '注释开头必须是 //', this.emptyLoc());
346
+ }
347
+ while (this.code[this.i + 1] !== '\n') {
348
+ this.next();
349
+ value += this.code[this.i];
350
+ }
351
+ return value;
352
+ }
353
+ comment() {
354
+ this.getComment();
355
+ this.next();
356
+ }
336
357
  condExp() {
337
358
  {
338
359
  this.preCol = this.column;
@@ -351,8 +372,8 @@ class Tokenizer {
351
372
  this.next();
352
373
  }
353
374
  value += this.code[this.i];
354
- const trimmed = value.trim();
355
- this.setToken(TokenType.Identifier, trimmed ? value : true);
375
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
376
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
356
377
  return this.token;
357
378
  } finally {
358
379
  this.next();
@@ -362,6 +383,9 @@ class Tokenizer {
362
383
  }
363
384
  }
364
385
  }
386
+ isEol(i) {
387
+ return this.code[i] === '\n' || this.code[i] === '/';
388
+ }
365
389
  jsExp() {
366
390
  {
367
391
  this.preCol = this.column;
@@ -400,6 +424,13 @@ class Tokenizer {
400
424
  }
401
425
  return this.code[i];
402
426
  }
427
+ peekCharIsEol() {
428
+ const char = this.peekChar();
429
+ return char === '\n' || char === '/';
430
+ }
431
+ charIsEol(char) {
432
+ return char === '\n' || char === '/';
433
+ }
403
434
  assignment() {
404
435
  this.setToken(TokenType.Assign, '=');
405
436
  }
@@ -519,6 +550,9 @@ class Tokenizer {
519
550
  case '\n':
520
551
  nextC = '\n';
521
552
  break;
553
+ case '/':
554
+ nextC = '/';
555
+ break;
522
556
  default:
523
557
  nextC = '';
524
558
  break;
@@ -527,6 +561,12 @@ class Tokenizer {
527
561
  isEmptyLine = true;
528
562
  break;
529
563
  }
564
+ if (nextC === '/') {
565
+ value += this.getComment();
566
+ this.next();
567
+ isEmptyLine = true;
568
+ break;
569
+ }
530
570
  if (!nextC) {
531
571
  break;
532
572
  }
@@ -556,6 +596,7 @@ class Tokenizer {
556
596
  isEmptyLine = _this$getDentValue2.isEmptyLine;
557
597
  if (isEmptyLine) {
558
598
  this.needIndent = true;
599
+ this.next();
559
600
  return;
560
601
  }
561
602
  this.needIndent = false;
@@ -631,7 +672,7 @@ class Tokenizer {
631
672
  let nextC;
632
673
  while (1) {
633
674
  nextC = this.code[this.i + 1];
634
- if (typeof nextC !== 'string' || !bobeShared.matchIdStart2(nextC, 0)) {
675
+ if (typeof nextC !== 'string' || !bobeShared.matchId(nextC, 0)) {
635
676
  break;
636
677
  }
637
678
  value += nextC;
@@ -965,6 +1006,7 @@ var NodeType = function (NodeType) {
965
1006
  NodeType["Element"] = "Element";
966
1007
  NodeType["Text"] = "Text";
967
1008
  NodeType["Interpolation"] = "Interpolation";
1009
+ NodeType["Comment"] = "Comment";
968
1010
  NodeType["Property"] = "Property";
969
1011
  NodeType["PropertyKey"] = "PropertyKey";
970
1012
  NodeType["StaticValue"] = "StaticValue";
@@ -1635,7 +1677,7 @@ class Interpreter {
1635
1677
  i: 0
1636
1678
  };
1637
1679
  if (keyExp) {
1638
- forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
1680
+ forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
1639
1681
  }
1640
1682
  window['for1'] = forNode;
1641
1683
  const data = this.getData();