nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
72 stars 27 forks source link

Doesn't handle exports with invalid identifiers #94

Open timfish opened 6 months ago

timfish commented 6 months ago

CommonJs supports exports keyed with arbitrary strings which are not valid identifiers:

exports["unsigned short"] = "something"

This means the webidl-conversions package results in the following error due to invalid iitm code:

file:///Users/tim/Documents/Repositories/import-in-the-middle/test/check-exports/node_modules/webidl-conversions/lib/index.js?iitm=true:69
      let $unsigned short = _.unsigned short
                    ^^^^^
SyntaxError: Unexpected identifier 'short'
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:118:18)
    at callTranslator (node:internal/modules/esm/loader:273:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:30)