bobe 0.0.40 → 0.0.42

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/index.d.ts CHANGED
@@ -347,6 +347,7 @@ declare class Tokenizer {
347
347
  private dent;
348
348
  private shorterThanBaseDentEof;
349
349
  private identifier;
350
+ private getStr;
350
351
  private str;
351
352
  private number;
352
353
  private eof;
package/dist/index.umd.js CHANGED
@@ -227,7 +227,7 @@
227
227
  if (!this.token) return false;
228
228
  return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
229
229
  }
230
- setToken(type, value) {
230
+ setToken(type, value, dt = 1) {
231
231
  this.token = {
232
232
  type,
233
233
  typeName: TokenType[type],
@@ -326,28 +326,23 @@
326
326
  }
327
327
  comment() {
328
328
  this.getComment();
329
- this.next();
330
329
  }
331
330
  condExp() {
332
331
  let value = '';
333
332
  this.token = null;
334
- try {
335
- if (this.code[this.i] === '\n') {
336
- this.setToken(TokenType.Identifier, true);
337
- return this.token;
338
- }
339
- while (this.code[this.i + 1] !== '\n') {
340
- value += this.code[this.i];
341
- this.next();
333
+ let char = this.code[this.i];
334
+ while (char !== '\n') {
335
+ if (char === '"' || char === "'") {
336
+ value += char + this.getStr(char);
342
337
  }
343
338
  value += this.code[this.i];
344
- const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
345
- this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
346
- return this.token;
347
- } finally {
348
339
  this.next();
349
- this.handledTokens.push(this.token);
340
+ char = this.code[this.i];
350
341
  }
342
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
343
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true, 0);
344
+ this.handledTokens.push(this.token);
345
+ return this.token;
351
346
  }
352
347
  isEol(i) {
353
348
  return this.code[i] === '\n' || this.code[i] === '/';
@@ -355,25 +350,18 @@
355
350
  jsExp() {
356
351
  this.token = null;
357
352
  let value = '';
358
- try {
359
- const char = this.code[this.i];
360
- if (char === ';' || char === '\n') {
361
- this.setToken(TokenType.Identifier, value);
362
- return this.token;
363
- }
364
- let nextC = this.code[this.i + 1];
365
- while (nextC !== ';' && nextC !== '\n') {
366
- value += this.code[this.i];
367
- this.next();
368
- nextC = this.code[this.i + 1];
353
+ let char = this.code[this.i];
354
+ while (char !== ';' && char !== '\n') {
355
+ if (char === '"' || char === "'") {
356
+ value += char + this.getStr(char);
369
357
  }
370
358
  value += this.code[this.i];
371
- this.setToken(TokenType.Identifier, value);
372
- return this.token;
373
- } finally {
374
359
  this.next();
375
- this.handledTokens.push(this.token);
360
+ char = this.code[this.i];
376
361
  }
362
+ this.setToken(TokenType.Identifier, value, 0);
363
+ this.handledTokens.push(this.token);
364
+ return this.token;
377
365
  }
378
366
  peekChar() {
379
367
  let i = this.i;
@@ -431,10 +419,8 @@
431
419
  startLine = this.line,
432
420
  startCol = this.preCol;
433
421
  let inComment,
434
- inString,
435
422
  count = 0,
436
- value = '',
437
- backslashCount = 0;
423
+ value = '';
438
424
  while (1) {
439
425
  const char = this.code[this.i];
440
426
  if (char === undefined) {
@@ -447,11 +433,6 @@
447
433
  inComment = null;
448
434
  value += this.code[this.i];
449
435
  this.next();
450
- } else if (inString) {
451
- if (char === inString && backslashCount % 2 === 0) {
452
- inString = null;
453
- }
454
- backslashCount = char === '\\' ? backslashCount + 1 : 0;
455
436
  } else {
456
437
  if (char === '/' && nextChar === '/') {
457
438
  inComment = 'single';
@@ -461,15 +442,15 @@
461
442
  inComment = 'multi';
462
443
  value += this.code[this.i];
463
444
  this.next();
464
- } else if (char === "'" || char === '"' || char === '`') {
465
- inString = char;
445
+ } else if (char === "'" || char === '"') {
446
+ value += char + this.getStr(char);
466
447
  } else if (char === '{') {
467
448
  count++;
468
449
  } else if (char === '}') {
469
450
  count--;
470
451
  }
471
452
  }
472
- if (count === 0 && inString == null && inComment == null) {
453
+ if (count === 0 && inComment == null) {
473
454
  return value.slice(1);
474
455
  }
475
456
  value += this.code[this.i];
@@ -665,7 +646,7 @@
665
646
  }
666
647
  this.setToken(tokenType, realValue);
667
648
  }
668
- str(char) {
649
+ getStr(head, parseEscape = true) {
669
650
  const startOffset = this.preI,
670
651
  startLine = this.line,
671
652
  startCol = this.preCol;
@@ -684,11 +665,20 @@
684
665
  continuousBackslashCount = 0;
685
666
  }
686
667
  this.next();
687
- if (nextC === char && memoCount % 2 === 0) {
668
+ if (nextC === head && memoCount % 2 === 0) {
688
669
  break;
689
670
  }
690
- value += nextC;
671
+ const mapped = bobeShared.escapeMap[nextC];
672
+ if (parseEscape && mapped) {
673
+ value += mapped;
674
+ } else {
675
+ value += nextC;
676
+ }
691
677
  }
678
+ return value;
679
+ }
680
+ str(char) {
681
+ const value = this.getStr(char, false);
692
682
  this.setToken(TokenType.String, value);
693
683
  }
694
684
  number(char) {
@@ -1128,7 +1118,7 @@
1128
1118
  }
1129
1119
  parseLoopNode(node) {
1130
1120
  const forLoc = this.tokenizer.token.loc ?? this.tokenizer.emptyLoc();
1131
- this.tokenizer.nextToken();
1121
+ this.tokenizer.jsExp();
1132
1122
  const collection = this.parseJsExp();
1133
1123
  if (!collection.value && collection.value !== 0) {
1134
1124
  this.addError(ParseErrorCode.MISSING_FOR_COLLECTION, '"for" 缺少集合表达式', forLoc, node);
@@ -1589,7 +1579,7 @@
1589
1579
  return _node;
1590
1580
  }
1591
1581
  forDeclaration() {
1592
- const arrExp = this.tokenizer.nextToken().value;
1582
+ const arrExp = this.tokenizer.jsExp().value;
1593
1583
  this.tokenizer.nextToken();
1594
1584
  const itemToken = this.tokenizer.nextToken();
1595
1585
  const isDestruct = itemToken.type === TokenType.InsertionExp;