This project is read-only.

Resolution of top-level external module names

Topics: Language Specification
Mar 21, 2014 at 5:21 PM
Subject is discussed in specification in 11.1.1 and 11.2.1, but essentially boils down to a magical phrase "the name is resolved in a host dependent manner". From my experiments with a default TypeScript HTML application project in Visual Studio, I can deduce the following algorithm:
  1. Directories are iterated, starting with a directory where current source file resides, then taking its parent, grandparent, etc., upto the project root.
  2. Each directory is combined with our module name (including the path).
  3. File is searched for each combined module name, first with a ".ts" extension, then with a ".d.ts" extension.
  4. If such file exists, then our module name is resolved to it. Otherwise, proceed to the next (parent) directory.
My questions:
  1. What kind of hosts are implied in the specification?
  2. Is my described algorithm correct for a default TS application?
  3. In which situation a different algorithm is used? Could you provide an example? Where could I read more about them?
I'd be very thankful for answers. And I think that the specification should be more detailed here :)
Mar 24, 2014 at 11:21 PM
I was wrong. Directories are iterated upto file system root, not upto project root. Even more interesting.
Apr 1, 2014 at 7:45 PM
This is still actual and important for us. Anybody care to comment?
Apr 1, 2014 at 7:49 PM
This is handled in referenceResovler.ts

See the methods 'resolveImportedFile' and 'resolveIncludedFile' - they're fairly straightforward.
Apr 1, 2014 at 7:57 PM
Thanks, would take a look