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