dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
https://ts-morph.com
MIT License
5.03k stars 196 forks source link

why module name judge like this? #1509

Open fantian007 opened 9 months ago

fantian007 commented 9 months ago

Describe the bug

Version: 21.0.1

sourceText:

declare module '@x/y' {};

judge:

const modules = sourceFile.getModules();

modules.forEach(m => {
  if (m.getName() === "'@x/y'") {
    console.log('enter');
  }
});

so, Why ? "'@x/y'" instead of '@x/y'?

And:

const t = sourceFile.getModule('@x/y'); // => undefined ?
const t = sourceFile.getModule("'@x/y'"); // => it works...

Expected behavior '@x/y'

fantian007 commented 9 months ago

I'm confused...

dsherret commented 8 months ago

These two module names are distinct:

declare module "example" {}
declare module example {}

That said, perhaps it should be normalizing single quotes to double quotes.