guybedford / es-module-lexer

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

Glob imports don't parse #137

Open dzearing opened 1 year ago

dzearing commented 1 year 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 1 year ago

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