getify / moduloze

Convert CommonJS (CJS) modules to UMD and ESM formats
MIT License
208 stars 11 forks source link

Incorrect import conversion #3

Closed getify closed 4 years ago

getify commented 4 years ago
var x = require("..").another()

Currently becomes:

import { another as _imp } from "..";
var x = _imp();

It should be:

import _imp from "..";    // or:   import * as _imp from "..";
var x = _imp.another();

This strange behavior is because a require(..).whatever is a recognized MemberExpression, but itself can be the callee of a CallExpression. It might technically work the way it currently is, but it's pretty unintuitive. I think the specificity of trying to import the named-export (another), instead of the whole module/namespace, is the problem, and should be pulled back.