guybedford / es-module-lexer

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

Feature request: Include an information whether the code includes `export {}` #159

Closed sapphi-red closed 1 year ago

sapphi-red commented 1 year ago

Currently es-module-lexer doesn't return any information that export {} existed. https://stackblitz.com/edit/node-1bnjp9?file=package.json,index.js

It would be useful if es-module-lexer could return that information. Because export {} is sometimes used to indicate that the file is written in ESM.

I'm not sure how to put this information in the current API. Maybe returning -1 for ExportSpecifier['s']?

guybedford commented 1 year ago

This is a good idea, especially now that Node.js is doing syntax detection.

I'd suggest we follow Node.js and make it a full "has module syntax" flag. Ie any of export {} or import syntax triggers it, as well as any use of import.meta.url.

Will leave this open as a feature request - PRs very welcome.