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