guybedford / es-module-lexer

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

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

Closed sapphi-red closed 8 months ago

sapphi-red commented 9 months 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 9 months 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.