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.
@@ -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,21 @@ 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
+ }
336
356
  condExp() {
337
357
  {
338
358
  this.preCol = this.column;
@@ -351,8 +371,8 @@ class Tokenizer {
351
371
  this.next();
352
372
  }
353
373
  value += this.code[this.i];
354
- const trimmed = value.trim();
355
- this.setToken(TokenType.Identifier, trimmed ? value : true);
374
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
375
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
356
376
  return this.token;
357
377
  } finally {
358
378
  this.next();
@@ -362,6 +382,9 @@ class Tokenizer {
362
382
  }
363
383
  }
364
384
  }
385
+ isEol(i) {
386
+ return this.code[i] === '\n' || this.code[i] === '/';
387
+ }
365
388
  jsExp() {
366
389
  {
367
390
  this.preCol = this.column;
@@ -400,6 +423,13 @@ class Tokenizer {
400
423
  }
401
424
  return this.code[i];
402
425
  }
426
+ peekCharIsEol() {
427
+ const char = this.peekChar();
428
+ return char === '\n' || char === '/';
429
+ }
430
+ charIsEol(char) {
431
+ return char === '\n' || char === '/';
432
+ }
403
433
  assignment() {
404
434
  this.setToken(TokenType.Assign, '=');
405
435
  }
@@ -519,6 +549,9 @@ class Tokenizer {
519
549
  case '\n':
520
550
  nextC = '\n';
521
551
  break;
552
+ case '/':
553
+ nextC = '/';
554
+ break;
522
555
  default:
523
556
  nextC = '';
524
557
  break;
@@ -527,6 +560,12 @@ class Tokenizer {
527
560
  isEmptyLine = true;
528
561
  break;
529
562
  }
563
+ if (nextC === '/') {
564
+ value += this.getComment();
565
+ this.next();
566
+ isEmptyLine = true;
567
+ break;
568
+ }
530
569
  if (!nextC) {
531
570
  break;
532
571
  }
@@ -556,6 +595,7 @@ class Tokenizer {
556
595
  isEmptyLine = _this$getDentValue2.isEmptyLine;
557
596
  if (isEmptyLine) {
558
597
  this.needIndent = true;
598
+ this.next();
559
599
  return;
560
600
  }
561
601
  this.needIndent = false;
@@ -965,6 +1005,7 @@ var NodeType = function (NodeType) {
965
1005
  NodeType["Element"] = "Element";
966
1006
  NodeType["Text"] = "Text";
967
1007
  NodeType["Interpolation"] = "Interpolation";
1008
+ NodeType["Comment"] = "Comment";
968
1009
  NodeType["Property"] = "Property";
969
1010
  NodeType["PropertyKey"] = "PropertyKey";
970
1011
  NodeType["StaticValue"] = "StaticValue";
@@ -1635,7 +1676,7 @@ class Interpreter {
1635
1676
  i: 0
1636
1677
  };
1637
1678
  if (keyExp) {
1638
- forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
1679
+ forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
1639
1680
  }
1640
1681
  window['for1'] = forNode;
1641
1682
  const data = this.getData();