kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.3k stars 42 forks source link

Parsing bug w/ `do while` found by `parser/fuzz/module_roundtrip_structured` #171

Open jasikpark opened 3 days ago

jasikpark commented 3 days ago

https://github.com/kaleidawave/ezno/blob/245d530049518955b3396a5216ab14957a2d4522/parser/fuzz/fuzz_targets/module_roundtrip_structured.rs#L31-L35 strikes again.

input: `do (/a/d); while (this);
`
output1: `do /a/d; while (this);
`

It looks like the parse and print removes the parentheses from the do statement, which causes Ezno to interpret the first / as a "divide" statement.

image

Biome Playground of input: https://biomejs.dev/playground/?code=ZABvACAAKAAvAGEALwBkACkAOwAgAHcAaABpAGwAZQAgACgAdABoAGkAcwApADsACgA%3D

Biome Playground of output1: https://biomejs.dev/playground/?code=ZABvACAALwBhAC8AZAA7ACAAdwBoAGkAbABlACAAKAB0AGgAaQBzACkAOwAKAA%3D%3D

jasikpark commented 2 days ago

Another example I think:

input: `while (class e extends async function({ [(/a/d)] : d }) {} {}) {
}
`
output1: `while (class e extends async function ({ [/a/d]: d }) {} {}) {}
`

This parse should not error because it was just parsed above. 
error: `ParseError { reason: "Expected identifier at variable reference, found Divide", position: 42..43 }`

https://www.typescriptlang.org/play/?#code/O4CwlgNgpgBAFAYwgQwM6prKAPALlAOwBMM0BPAhGAMwFdLcwB7AuAbxgG04B6ZHogEoAujABcMIjAC+gmG2nzZ8gFDSgA

sounds like the actual JS is a bit angry at runtime, since the async fn doesn't count as a constructor, but I think it's syntactically correct. The printed version (output1) is also close to what biome and prettier output.

jasikpark commented 2 days ago
image

this seems relevant

jasikpark commented 2 days ago

Sounds like

https://github.com/kaleidawave/ezno/blob/245d530049518955b3396a5216ab14957a2d4522/parser/src/tokens.rs#L502-L522

needs to allow regex as a name for variables, or there's a bug somewhere where it initially thinks it can permit regex as names for variables