Skip to content

Commit 53c22d1

Browse files
authored
fix(es/lexer): Use error when handling '\0' (#10964)
**Description:** After introducing `Token::Eof`, we need to distinguish true eof (pos >= len) and '\0'. Both oxc and typescript throw errors on the latter. **Related issue:** - Closes #10952
1 parent 6475070 commit 53c22d1

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

.changeset/great-rivers-draw.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_parser: patch
3+
swc_core: patch
4+
---
5+
6+
fix: error when handling '\0'

crates/swc_ecma_parser/src/lexer/table.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) type ByteHandler = fn(&mut Lexer<'_>) -> LexResult<Token>;
1919
/// Lookup table mapping any incoming byte to a handler function defined below.
2020
pub(super) static BYTE_HANDLERS: [ByteHandler; 256] = [
2121
// 0 1 2 3 4 5 6 7 8 9 A B C D E F //
22-
EOF, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, // 0
22+
ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, // 0
2323
ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, // 1
2424
ERR, EXL, QOT, HSH, IDN, PRC, AMP, QOT, PNO, PNC, ATR, PLS, COM, MIN, PRD, SLH, // 2
2525
ZER, DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, COL, SEM, LSS, EQL, MOR, QST, // 3
@@ -37,12 +37,6 @@ pub(super) static BYTE_HANDLERS: [ByteHandler; 256] = [
3737
UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, UNI, // F
3838
];
3939

40-
const EOF: ByteHandler = |lexer| {
41-
lexer.input.bump_bytes(1);
42-
43-
Ok(Token::Eof)
44-
};
45-
4640
const ERR: ByteHandler = |lexer| {
4741
let c = unsafe {
4842
// Safety: Byte handler is only called for non-last chracters
21 Bytes
Binary file not shown.
128 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)