guybedford / es-module-lexer

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

Glob imports don't parse #137

Open dzearing opened 2 years ago

dzearing commented 2 years ago

When parsing this import:

import(`@scope/package/intl/${getLocaleName(
      locale
    )}/strings.js`);

...it returns { n: undefined }.

Expected:

Returns { n: '@scope/packages/intl/${...}/strings.js' }

I recognize the content within the variable could be anything which would make the string a lot less useful to parse. I think it would be ok to strip content in the template string injected variable, so long as the glob were identifiable. For example, something like an asterisk replacement would work too:

{ n: '@scope/packages/intl/*/strings.js' }

This would allow the glob match to be handled dynamically.

Workaround:

The s and e args are intact, so we can slice this out in js and try to simplify to work around, but maybe it would be more efficient in the lower layer.

guybedford commented 2 years ago

It would be great to support a feature like this definitely!