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.cjs.js +36 -46
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +43 -55
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +44 -56
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +37 -47
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.umd.js +36 -46
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
|
@@ -235,7 +235,7 @@ class Tokenizer {
|
|
|
235
235
|
if (!this.token) return false;
|
|
236
236
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
237
237
|
}
|
|
238
|
-
setToken(type, value) {
|
|
238
|
+
setToken(type, value, dt = 1) {
|
|
239
239
|
this.token = {
|
|
240
240
|
type,
|
|
241
241
|
typeName: TokenType[type],
|
|
@@ -247,11 +247,11 @@ class Tokenizer {
|
|
|
247
247
|
column: this.preCol
|
|
248
248
|
},
|
|
249
249
|
end: {
|
|
250
|
-
offset: this.i +
|
|
250
|
+
offset: this.i + dt,
|
|
251
251
|
line: this.line,
|
|
252
|
-
column: this.column +
|
|
252
|
+
column: this.column + dt
|
|
253
253
|
},
|
|
254
|
-
source: this.code.slice(this.preI, this.i +
|
|
254
|
+
source: this.code.slice(this.preI, this.i + dt)
|
|
255
255
|
} : null
|
|
256
256
|
};
|
|
257
257
|
this.isFirstToken = false;
|
|
@@ -352,7 +352,6 @@ class Tokenizer {
|
|
|
352
352
|
}
|
|
353
353
|
comment() {
|
|
354
354
|
this.getComment();
|
|
355
|
-
this.next();
|
|
356
355
|
}
|
|
357
356
|
condExp() {
|
|
358
357
|
{
|
|
@@ -362,26 +361,22 @@ class Tokenizer {
|
|
|
362
361
|
}
|
|
363
362
|
let value = '';
|
|
364
363
|
this.token = null;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
while (this.code[this.i + 1] !== '\n') {
|
|
371
|
-
value += this.code[this.i];
|
|
372
|
-
this.next();
|
|
364
|
+
let char = this.code[this.i];
|
|
365
|
+
while (char !== '\n') {
|
|
366
|
+
if (char === '"' || char === "'") {
|
|
367
|
+
value += char + this.getStr(char);
|
|
373
368
|
}
|
|
374
369
|
value += this.code[this.i];
|
|
375
|
-
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
376
|
-
this.setToken(TokenType.Identifier, trimmed ? trimmed : true);
|
|
377
|
-
return this.token;
|
|
378
|
-
} finally {
|
|
379
370
|
this.next();
|
|
380
|
-
this.
|
|
381
|
-
{
|
|
382
|
-
this.needLoc = false;
|
|
383
|
-
}
|
|
371
|
+
char = this.code[this.i];
|
|
384
372
|
}
|
|
373
|
+
const trimmed = value.replace(/\/\/[\s\S]+/, '').trim();
|
|
374
|
+
this.setToken(TokenType.Identifier, trimmed ? trimmed : true, 0);
|
|
375
|
+
this.handledTokens.push(this.token);
|
|
376
|
+
{
|
|
377
|
+
this.needLoc = false;
|
|
378
|
+
}
|
|
379
|
+
return this.token;
|
|
385
380
|
}
|
|
386
381
|
isEol(i) {
|
|
387
382
|
return this.code[i] === '\n' || this.code[i] === '/';
|
|
@@ -394,28 +389,21 @@ class Tokenizer {
|
|
|
394
389
|
}
|
|
395
390
|
this.token = null;
|
|
396
391
|
let value = '';
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (char === '
|
|
400
|
-
this.
|
|
401
|
-
return this.token;
|
|
402
|
-
}
|
|
403
|
-
let nextC = this.code[this.i + 1];
|
|
404
|
-
while (nextC !== ';' && nextC !== '\n') {
|
|
405
|
-
value += this.code[this.i];
|
|
406
|
-
this.next();
|
|
407
|
-
nextC = this.code[this.i + 1];
|
|
392
|
+
let char = this.code[this.i];
|
|
393
|
+
while (char !== ';' && char !== '\n') {
|
|
394
|
+
if (char === '"' || char === "'") {
|
|
395
|
+
value += char + this.getStr(char);
|
|
408
396
|
}
|
|
409
397
|
value += this.code[this.i];
|
|
410
|
-
this.setToken(TokenType.Identifier, value);
|
|
411
|
-
return this.token;
|
|
412
|
-
} finally {
|
|
413
398
|
this.next();
|
|
414
|
-
this.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
399
|
+
char = this.code[this.i];
|
|
400
|
+
}
|
|
401
|
+
this.setToken(TokenType.Identifier, value, 0);
|
|
402
|
+
this.handledTokens.push(this.token);
|
|
403
|
+
{
|
|
404
|
+
this.needLoc = false;
|
|
418
405
|
}
|
|
406
|
+
return this.token;
|
|
419
407
|
}
|
|
420
408
|
peekChar() {
|
|
421
409
|
let i = this.i;
|
|
@@ -473,10 +461,8 @@ class Tokenizer {
|
|
|
473
461
|
startLine = this.line,
|
|
474
462
|
startCol = this.preCol;
|
|
475
463
|
let inComment,
|
|
476
|
-
inString,
|
|
477
464
|
count = 0,
|
|
478
|
-
value = ''
|
|
479
|
-
backslashCount = 0;
|
|
465
|
+
value = '';
|
|
480
466
|
while (1) {
|
|
481
467
|
const char = this.code[this.i];
|
|
482
468
|
if (char === undefined) {
|
|
@@ -489,11 +475,6 @@ class Tokenizer {
|
|
|
489
475
|
inComment = null;
|
|
490
476
|
value += this.code[this.i];
|
|
491
477
|
this.next();
|
|
492
|
-
} else if (inString) {
|
|
493
|
-
if (char === inString && backslashCount % 2 === 0) {
|
|
494
|
-
inString = null;
|
|
495
|
-
}
|
|
496
|
-
backslashCount = char === '\\' ? backslashCount + 1 : 0;
|
|
497
478
|
} else {
|
|
498
479
|
if (char === '/' && nextChar === '/') {
|
|
499
480
|
inComment = 'single';
|
|
@@ -503,15 +484,15 @@ class Tokenizer {
|
|
|
503
484
|
inComment = 'multi';
|
|
504
485
|
value += this.code[this.i];
|
|
505
486
|
this.next();
|
|
506
|
-
} else if (char === "'" || char === '"'
|
|
507
|
-
|
|
487
|
+
} else if (char === "'" || char === '"') {
|
|
488
|
+
value += char + this.getStr(char);
|
|
508
489
|
} else if (char === '{') {
|
|
509
490
|
count++;
|
|
510
491
|
} else if (char === '}') {
|
|
511
492
|
count--;
|
|
512
493
|
}
|
|
513
494
|
}
|
|
514
|
-
if (count === 0 &&
|
|
495
|
+
if (count === 0 && inComment == null) {
|
|
515
496
|
return value.slice(1);
|
|
516
497
|
}
|
|
517
498
|
value += this.code[this.i];
|
|
@@ -707,7 +688,7 @@ class Tokenizer {
|
|
|
707
688
|
}
|
|
708
689
|
this.setToken(tokenType, realValue);
|
|
709
690
|
}
|
|
710
|
-
|
|
691
|
+
getStr(head, parseEscape = true) {
|
|
711
692
|
const startOffset = this.preI,
|
|
712
693
|
startLine = this.line,
|
|
713
694
|
startCol = this.preCol;
|
|
@@ -726,11 +707,18 @@ class Tokenizer {
|
|
|
726
707
|
continuousBackslashCount = 0;
|
|
727
708
|
}
|
|
728
709
|
this.next();
|
|
729
|
-
if (nextC ===
|
|
710
|
+
if (nextC === head && memoCount % 2 === 0) {
|
|
730
711
|
break;
|
|
731
712
|
}
|
|
732
|
-
|
|
713
|
+
bobeShared.escapeMap[nextC];
|
|
714
|
+
{
|
|
715
|
+
value += nextC;
|
|
716
|
+
}
|
|
733
717
|
}
|
|
718
|
+
return value;
|
|
719
|
+
}
|
|
720
|
+
str(char) {
|
|
721
|
+
const value = this.getStr(char, false);
|
|
734
722
|
this.setToken(TokenType.String, value);
|
|
735
723
|
}
|
|
736
724
|
number(char) {
|
|
@@ -1170,7 +1158,7 @@ class Compiler {
|
|
|
1170
1158
|
}
|
|
1171
1159
|
parseLoopNode(node) {
|
|
1172
1160
|
const forLoc = this.tokenizer.token.loc ?? this.tokenizer.emptyLoc();
|
|
1173
|
-
this.tokenizer.
|
|
1161
|
+
this.tokenizer.jsExp();
|
|
1174
1162
|
const collection = this.parseJsExp();
|
|
1175
1163
|
if (!collection.value && collection.value !== 0) {
|
|
1176
1164
|
this.addError(ParseErrorCode.MISSING_FOR_COLLECTION, '"for" 缺少集合表达式', forLoc, node);
|
|
@@ -1631,7 +1619,7 @@ class Interpreter {
|
|
|
1631
1619
|
return _node;
|
|
1632
1620
|
}
|
|
1633
1621
|
forDeclaration() {
|
|
1634
|
-
const arrExp = this.tokenizer.
|
|
1622
|
+
const arrExp = this.tokenizer.jsExp().value;
|
|
1635
1623
|
this.tokenizer.nextToken();
|
|
1636
1624
|
const itemToken = this.tokenizer.nextToken();
|
|
1637
1625
|
const isDestruct = itemToken.type === TokenType.InsertionExp;
|