guybedford / es-module-lexer

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

v1.1.1 fails with export specifier in string #148

Closed bluwy closed 1 year ago

bluwy commented 1 year ago

In v1.1.1, es-module-lexer errors when parsing these valid JS code:

export default "export default a"
export default "export default 'a'"
export default "export function foo() {}"
export default "export function foo() {return bar}"

Here's a stackblitz repro, installing v1.1.0 instead fixes the issue. From the patterns, it looks like it's parsing the export specifier within the string.

Stumbled upon this in Vite: https://github.com/vitejs/vite/pull/12036

guybedford commented 1 year ago

Thanks for reporting, fix in https://github.com/guybedford/es-module-lexer/pull/149.