bobe 0.0.39 → 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.
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["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 {
@@ -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,22 @@ 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
+ this.next();
329
+ }
309
330
  condExp() {
310
331
  let value = '';
311
332
  this.token = null;
@@ -319,14 +340,17 @@ class Tokenizer {
319
340
  this.next();
320
341
  }
321
342
  value += this.code[this.i];
322
- const trimmed = value.trim();
323
- this.setToken(TokenType.Identifier, trimmed ? value : true);
343
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
344
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
324
345
  return this.token;
325
346
  } finally {
326
347
  this.next();
327
348
  this.handledTokens.push(this.token);
328
349
  }
329
350
  }
351
+ isEol(i) {
352
+ return this.code[i] === '\n' || this.code[i] === '/';
353
+ }
330
354
  jsExp() {
331
355
  this.token = null;
332
356
  let value = '';
@@ -357,6 +381,13 @@ class Tokenizer {
357
381
  }
358
382
  return this.code[i];
359
383
  }
384
+ peekCharIsEol() {
385
+ const char = this.peekChar();
386
+ return char === '\n' || char === '/';
387
+ }
388
+ charIsEol(char) {
389
+ return char === '\n' || char === '/';
390
+ }
360
391
  assignment() {
361
392
  this.setToken(TokenType.Assign, '=');
362
393
  }
@@ -476,6 +507,9 @@ class Tokenizer {
476
507
  case '\n':
477
508
  nextC = '\n';
478
509
  break;
510
+ case '/':
511
+ nextC = '/';
512
+ break;
479
513
  default:
480
514
  nextC = '';
481
515
  break;
@@ -484,6 +518,12 @@ class Tokenizer {
484
518
  isEmptyLine = true;
485
519
  break;
486
520
  }
521
+ if (nextC === '/') {
522
+ value += this.getComment();
523
+ this.next();
524
+ isEmptyLine = true;
525
+ break;
526
+ }
487
527
  if (!nextC) {
488
528
  break;
489
529
  }
@@ -513,6 +553,7 @@ class Tokenizer {
513
553
  isEmptyLine = _this$getDentValue2.isEmptyLine;
514
554
  if (isEmptyLine) {
515
555
  this.needIndent = true;
556
+ this.next();
516
557
  return;
517
558
  }
518
559
  this.needIndent = false;
@@ -922,6 +963,7 @@ var NodeType = function (NodeType) {
922
963
  NodeType["Element"] = "Element";
923
964
  NodeType["Text"] = "Text";
924
965
  NodeType["Interpolation"] = "Interpolation";
966
+ NodeType["Comment"] = "Comment";
925
967
  NodeType["Property"] = "Property";
926
968
  NodeType["PropertyKey"] = "PropertyKey";
927
969
  NodeType["StaticValue"] = "StaticValue";
@@ -1592,7 +1634,7 @@ class Interpreter {
1592
1634
  i: 0
1593
1635
  };
1594
1636
  if (keyExp) {
1595
- forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}};return v;`);
1637
+ forNode.getKey = new Function('data', `let v;with(data){v=${keyExp}\n};return v;`);
1596
1638
  }
1597
1639
  window['for1'] = forNode;
1598
1640
  const data = this.getData();