guybedford / es-module-lexer

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

Return start position of export statements #112

Open overlookmotel opened 2 years ago

overlookmotel commented 2 years ago

It appears that #36 is stalled for now and is a tricky problem to solve.

Would it be possible just to return the start position of export statements?

My aim is to parse export statements in a file without parsing the entire file. With just the start position, this would be achievable without a lot of overhead:

  1. Get start position of export statement from es-module-lexer.
  2. Get slice of file content from start position of the export statement to end of the file.
  3. Pass that slice to a parser with instruction to bail out after 1 statement.

From #36, it sounds like finding the start of export statements is the easy part, and would be inexpensive, but it's finding the end which is hard.

Would you consider supporting this as a stopgap until full export parsing is supported?

guybedford commented 2 years ago

We now support export binding information from https://github.com/guybedford/es-module-lexer/pull/119.

Extending this to full export statement tracking is a logical next step.