mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Merge pull request #27625 from Microsoft/fileAddedWithAmbientModule
Use ambient modules as references to keep track of reporting and usage of modules correctly
This commit is contained in:
@@ -148,8 +148,39 @@ namespace ts.BuilderState {
|
||||
});
|
||||
}
|
||||
|
||||
// Add module augmentation as references
|
||||
if (sourceFile.moduleAugmentations.length) {
|
||||
const checker = program.getTypeChecker();
|
||||
for (const moduleName of sourceFile.moduleAugmentations) {
|
||||
if (!isStringLiteral(moduleName)) { continue; }
|
||||
const symbol = checker.getSymbolAtLocation(moduleName);
|
||||
if (!symbol) { continue; }
|
||||
|
||||
// Add any file other than our own as reference
|
||||
addReferenceFromAmbientModule(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
// From ambient modules
|
||||
for (const ambientModule of program.getTypeChecker().getAmbientModules()) {
|
||||
if (ambientModule.declarations.length > 1) {
|
||||
addReferenceFromAmbientModule(ambientModule);
|
||||
}
|
||||
}
|
||||
|
||||
return referencedFiles;
|
||||
|
||||
function addReferenceFromAmbientModule(symbol: Symbol) {
|
||||
// Add any file other than our own as reference
|
||||
for (const declaration of symbol.declarations) {
|
||||
const declarationSourceFile = getSourceFileOfNode(declaration);
|
||||
if (declarationSourceFile &&
|
||||
declarationSourceFile !== sourceFile) {
|
||||
addReferencedFile(declarationSourceFile.resolvedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addReferencedFile(referencedPath: Path) {
|
||||
if (!referencedFiles) {
|
||||
referencedFiles = createMap<true>();
|
||||
|
||||
Reference in New Issue
Block a user