pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
744 stars 46 forks source link

dynamic imports: where the usage is in a separate statement from the import #144

Open mrseanryan opened 4 years ago

mrseanryan commented 4 years ago

The current implementation of dynamic import handling, assumes that the import and the usage of the import are within the same statement.

This issue is about cases where the import is in a separate statement, from the usage.

Example:

usedExport is marked as unused.

const module = await import("./myModule");
const usedExport = module.usedExport;

Originally posted by @jp7837 in https://github.com/pzavolinsky/ts-unused-exports/pull/142#issuecomment-636184346

mrseanryan commented 4 years ago

Another example:

const module = import("./myModule");
module.then(({ usedExport }) => {
    console.log(usedExport); // Or whatever
});
mrseanryan commented 4 years ago

To support these cases, requires:

simplification: We could assume that within a nested scope, an identifier is unique

mrseanryan commented 4 years ago

update: I'm not sure if we can ever support this 100% (at least, with the current architecture).

If a dynamic import can be assigned to a variable, then this means that the variable can be passed around into other functions, which could be in other modules (even dynamically imported modules!).

So the complexity is high.

If our architecture changed to have a fully compiled model to lean on, then this would be more practical to cover (possibly via ts-morph?).

yujiaze commented 4 weeks ago

any update about this?