-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(typescript): correctly handle absolute paths for imported modules
Previously, it was assumed that all `ts.SourceFile#fileName` properties (and the thereof derived `ts.Symbol#name` properties) corresponding to imported modules would be paths relative to the project root. This used to be true with older versions of TypeScript (v3.x), but it stopped being true with the recent update to TypeScript v4.x. This would result in different values for things like `FileInfo#relativePath` and `ModuleDoc#id`, leading to errors. An example error is failing to match `module` doc IDs to special elements `relativePath`s [in angular.io][1]. This commit restores the previous behavior (i.e. ensuring that `FileInfo#relativePath` and `ModuleDoc#id` remain the same as with older versions) by making the following changes: - Explicitly compute the relative path from the project root to a source file's path for `FileInfo#relativePath` (instead of assuming that `ts.SourceFile#fileName` is relative). - Explicitly compute the relative path from the project root to a symbol's name, which is [based on `ts.SourceFile#fileName`][2] (instead of assuming that `ts.Symbol#name` is based on a relative path). - Remove unnecessary logic for keeping `fileName` relative to the project root when calling `ts.createSourceFile()` in `CustomCompilerHost#getSourceFile()`. Since the `ts.SourceFile`s created for files that TypeScript discovers by following imports in other files will not have a relative `fileName`, there is no gain in trying to retain that property for `CustomCompilerHost`. [1]: https://github.com/angular/angular/blob/8ebc946c0e7bf80d26ec8268acb4ff0af9e5c34a/aio/tools/transforms/angular-api-package/processors/processSpecialElements.js#L8-L21 [2]: https://github.com/microsoft/TypeScript/blob/1fe9bfdd0ee0ecf9dff23a40c0066645719e46b9/src/compiler/binder.ts#L2762
- Loading branch information
1 parent
3173635
commit 83eb73e
Showing
6 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { X } from './modules'; | ||
|
||
export const Y = !X; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters