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
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],
|
|
@@ -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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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.
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
if (char === '
|
|
361
|
-
this.
|
|
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.
|
|
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 === '"'
|
|
465
|
-
|
|
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 &&
|
|
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
|
-
|
|
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 ===
|
|
668
|
+
if (nextC === head && memoCount % 2 === 0) {
|
|
688
669
|
break;
|
|
689
670
|
}
|
|
690
|
-
|
|
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.
|
|
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.
|
|
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;
|