guybedford / es-module-lexer

Low-overhead lexer dedicated to ES module parsing for fast analysis
MIT License
912 stars 47 forks source link

Another `of` parse error since 1.5.1 #177

Closed simonbuchan closed 1 month ago

simonbuchan commented 1 month ago

Similar, but not the same issue as #173

Minimal source code:

if (of / 2) {}

Error stack:

Error: Parse error @:1:18
    at parse (file:///D:/scratch/parse-error/node_modules/.pnpm/es-module-lexer@1.5.3/node_modules/es-module-lexer/dist/lexer.js:2:594)
    at file:///D:/scratch/parse-error/node_modules/.pnpm/es-module-lexer@1.5.3/node_modules/es-module-lexer/dist/lexer.js:2:355 {
  idx: 17
}

Requires:

So probably the context/backtracking getting confused by the not-quite keyword.

Reproduces in 1.5.1 to 1.5.3, but not in 1.5.0 or 1.4.2

We had the poor luck to have this be spit out into our vite output chunks, which made this very confusing to debug!

guybedford commented 1 month ago

Well isolated! I can imagine it must have been a hard one to find. Fix in https://github.com/guybedford/es-module-lexer/pull/178 will post the release out now.

simonbuchan commented 1 month ago

👍 Wow, nice work! Really saving my butt here!

I was banging my head against trying to work around this one, forcing v1.5.0 simply hit the other issue, so I was down to trying to see if I could inject a plugin that would replace of in the minified chunk without just colliding with something else... skin-crawling stuff 😅

simonbuchan commented 1 month ago

Argh. Of course, we're going through vite, which bundles you in with their distribution. I'll have to open an issue over there too, though at least I can try a vendored / patched build for now.

simonbuchan commented 1 month ago

To close the loop: https://github.com/vitejs/vite/pull/17555