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/bobe.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Queue, isNum, matchIdStart2, matchId, jsVarRegexp } from 'bobe-shared';
1
+ import { Queue, isNum, matchIdStart2, matchId, escapeMap, jsVarRegexp } from 'bobe-shared';
2
2
  import { getPulling, setPulling, Keys, Computed, Effect, toRaw, runWithPulling, Scope, deepSignal, Store, shareSignal, effect } from 'aoye';
3
3
  export * from 'aoye';
4
4
 
@@ -225,7 +225,7 @@ class Tokenizer {
225
225
  if (!this.token) return false;
226
226
  return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
227
227
  }
228
- setToken(type, value) {
228
+ setToken(type, value, dt = 1) {
229
229
  this.token = {
230
230
  type,
231
231
  typeName: TokenType[type],
@@ -324,28 +324,23 @@ class Tokenizer {
324
324
  }
325
325
  comment() {
326
326
  this.getComment();
327
- this.next();
328
327
  }
329
328
  condExp() {
330
329
  let value = '';
331
330
  this.token = null;
332
- try {
333
- if (this.code[this.i] === '\n') {
334
- this.setToken(TokenType.Identifier, true);
335
- return this.token;
336
- }
337
- while (this.code[this.i + 1] !== '\n') {
338
- value += this.code[this.i];
339
- this.next();
331
+ let char = this.code[this.i];
332
+ while (char !== '\n') {
333
+ if (char === '"' || char === "'") {
334
+ value += char + this.getStr(char);
340
335
  }
341
336
  value += this.code[this.i];
342
- const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
343
- this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
344
- return this.token;
345
- } finally {
346
337
  this.next();
347
- this.handledTokens.push(this.token);
338
+ char = this.code[this.i];
348
339
  }
340
+ const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
341
+ this.setToken(TokenType.Identifier, trimmed ? trimmed : true, 0);
342
+ this.handledTokens.push(this.token);
343
+ return this.token;
349
344
  }
350
345
  isEol(i) {
351
346
  return this.code[i] === '\n' || this.code[i] === '/';
@@ -353,25 +348,18 @@ class Tokenizer {
353
348
  jsExp() {
354
349
  this.token = null;
355
350
  let value = '';
356
- try {
357
- const char = this.code[this.i];
358
- if (char === ';' || char === '\n') {
359
- this.setToken(TokenType.Identifier, value);
360
- return this.token;
361
- }
362
- let nextC = this.code[this.i + 1];
363
- while (nextC !== ';' && nextC !== '\n') {
364
- value += this.code[this.i];
365
- this.next();
366
- nextC = this.code[this.i + 1];
351
+ let char = this.code[this.i];
352
+ while (char !== ';' && char !== '\n') {
353
+ if (char === '"' || char === "'") {
354
+ value += char + this.getStr(char);
367
355
  }
368
356
  value += this.code[this.i];
369
- this.setToken(TokenType.Identifier, value);
370
- return this.token;
371
- } finally {
372
357
  this.next();
373
- this.handledTokens.push(this.token);
358
+ char = this.code[this.i];
374
359
  }
360
+ this.setToken(TokenType.Identifier, value, 0);
361
+ this.handledTokens.push(this.token);
362
+ return this.token;
375
363
  }
376
364
  peekChar() {
377
365
  let i = this.i;
@@ -429,10 +417,8 @@ class Tokenizer {
429
417
  startLine = this.line,
430
418
  startCol = this.preCol;
431
419
  let inComment,
432
- inString,
433
420
  count = 0,
434
- value = '',
435
- backslashCount = 0;
421
+ value = '';
436
422
  while (1) {
437
423
  const char = this.code[this.i];
438
424
  if (char === undefined) {
@@ -445,11 +431,6 @@ class Tokenizer {
445
431
  inComment = null;
446
432
  value += this.code[this.i];
447
433
  this.next();
448
- } else if (inString) {
449
- if (char === inString && backslashCount % 2 === 0) {
450
- inString = null;
451
- }
452
- backslashCount = char === '\\' ? backslashCount + 1 : 0;
453
434
  } else {
454
435
  if (char === '/' && nextChar === '/') {
455
436
  inComment = 'single';
@@ -459,15 +440,15 @@ class Tokenizer {
459
440
  inComment = 'multi';
460
441
  value += this.code[this.i];
461
442
  this.next();
462
- } else if (char === "'" || char === '"' || char === '`') {
463
- inString = char;
443
+ } else if (char === "'" || char === '"') {
444
+ value += char + this.getStr(char);
464
445
  } else if (char === '{') {
465
446
  count++;
466
447
  } else if (char === '}') {
467
448
  count--;
468
449
  }
469
450
  }
470
- if (count === 0 && inString == null && inComment == null) {
451
+ if (count === 0 && inComment == null) {
471
452
  return value.slice(1);
472
453
  }
473
454
  value += this.code[this.i];
@@ -663,7 +644,7 @@ class Tokenizer {
663
644
  }
664
645
  this.setToken(tokenType, realValue);
665
646
  }
666
- str(char) {
647
+ getStr(head, parseEscape = true) {
667
648
  const startOffset = this.preI,
668
649
  startLine = this.line,
669
650
  startCol = this.preCol;
@@ -682,11 +663,20 @@ class Tokenizer {
682
663
  continuousBackslashCount = 0;
683
664
  }
684
665
  this.next();
685
- if (nextC === char && memoCount % 2 === 0) {
666
+ if (nextC === head && memoCount % 2 === 0) {
686
667
  break;
687
668
  }
688
- value += nextC;
669
+ const mapped = escapeMap[nextC];
670
+ if (parseEscape && mapped) {
671
+ value += mapped;
672
+ } else {
673
+ value += nextC;
674
+ }
689
675
  }
676
+ return value;
677
+ }
678
+ str(char) {
679
+ const value = this.getStr(char, false);
690
680
  this.setToken(TokenType.String, value);
691
681
  }
692
682
  number(char) {
@@ -1126,7 +1116,7 @@ class Compiler {
1126
1116
  }
1127
1117
  parseLoopNode(node) {
1128
1118
  const forLoc = this.tokenizer.token.loc ?? this.tokenizer.emptyLoc();
1129
- this.tokenizer.nextToken();
1119
+ this.tokenizer.jsExp();
1130
1120
  const collection = this.parseJsExp();
1131
1121
  if (!collection.value && collection.value !== 0) {
1132
1122
  this.addError(ParseErrorCode.MISSING_FOR_COLLECTION, '"for" 缺少集合表达式', forLoc, node);
@@ -1587,7 +1577,7 @@ class Interpreter {
1587
1577
  return _node;
1588
1578
  }
1589
1579
  forDeclaration() {
1590
- const arrExp = this.tokenizer.nextToken().value;
1580
+ const arrExp = this.tokenizer.jsExp().value;
1591
1581
  this.tokenizer.nextToken();
1592
1582
  const itemToken = this.tokenizer.nextToken();
1593
1583
  const isDestruct = itemToken.type === TokenType.InsertionExp;