Merge pull request #29695 from Microsoft/fixDtsTypeReferenceEmit

Fix type reference dts emit failure
This commit is contained in:
Ron Buckton 2019-02-04 13:03:07 -08:00 committed by GitHub
commit 55762271af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 1 deletions

View file

@ -29591,9 +29591,12 @@ namespace ts {
return;
}
const file = host.getSourceFile(resolvedDirective.resolvedFileName)!;
fileToDirective.set(file.path, key);
// Add the transitive closure of path references loaded by this file (as long as they are not)
// part of an existing type reference.
addReferencedFilesToTypeDirective(file, key);
});
}
return {
getReferencedExportContainer,
getReferencedImportDeclaration,
@ -29752,6 +29755,18 @@ namespace ts {
}
return false;
}
function addReferencedFilesToTypeDirective(file: SourceFile, key: string) {
if (fileToDirective.has(file.path)) return;
fileToDirective.set(file.path, key);
for (const { fileName } of file.referencedFiles) {
const resolvedFile = resolveTripleslashReference(fileName, file.originalFileName);
const referencedFile = host.getSourceFile(resolvedFile);
if (referencedFile) {
addReferencedFilesToTypeDirective(referencedFile, key);
}
}
}
}
function getExternalModuleFileFromDeclaration(declaration: AnyImportOrReExport | ModuleDeclaration | ImportTypeNode): SourceFile | undefined {

View file

@ -0,0 +1,34 @@
//// [tests/cases/conformance/declarationEmit/typeReferenceRelatedFiles.ts] ////
//// [index.d.ts]
/// <reference path="fs.d.ts" />
//// [fs.d.ts]
declare module "fs" {
interface FSWatcher {}
}
//// [package.json]
{
"name": "@types/node",
"version": "1.0.0"
}
//// [main.ts]
/// <reference types="node" />
import { FSWatcher } from "fs";
export function f() {
return {} as FSWatcher;
}
//// [main.js]
"use strict";
exports.__esModule = true;
function f() {
return {};
}
exports.f = f;
//// [main.d.ts]
/// <reference types="node" />
import { FSWatcher } from "fs";
export declare function f(): FSWatcher;

View file

@ -0,0 +1,21 @@
=== tests/cases/conformance/declarationEmit/node_modules/@types/node/index.d.ts ===
/// <reference path="fs.d.ts" />
No type information for this code.=== tests/cases/conformance/declarationEmit/node_modules/@types/node/fs.d.ts ===
declare module "fs" {
>"fs" : Symbol("fs", Decl(fs.d.ts, 0, 0))
interface FSWatcher {}
>FSWatcher : Symbol(FSWatcher, Decl(fs.d.ts, 0, 21))
}
=== tests/cases/conformance/declarationEmit/main.ts ===
/// <reference types="node" />
import { FSWatcher } from "fs";
>FSWatcher : Symbol(FSWatcher, Decl(main.ts, 1, 8))
export function f() {
>f : Symbol(f, Decl(main.ts, 1, 31))
return {} as FSWatcher;
>FSWatcher : Symbol(FSWatcher, Decl(main.ts, 1, 8))
}

View file

@ -0,0 +1,21 @@
=== tests/cases/conformance/declarationEmit/node_modules/@types/node/index.d.ts ===
/// <reference path="fs.d.ts" />
No type information for this code.=== tests/cases/conformance/declarationEmit/node_modules/@types/node/fs.d.ts ===
declare module "fs" {
>"fs" : typeof import("fs")
interface FSWatcher {}
}
=== tests/cases/conformance/declarationEmit/main.ts ===
/// <reference types="node" />
import { FSWatcher } from "fs";
>FSWatcher : any
export function f() {
>f : () => FSWatcher
return {} as FSWatcher;
>{} as FSWatcher : FSWatcher
>{} : {}
}

View file

@ -0,0 +1,18 @@
// @declaration: true
// @filename: node_modules/@types/node/index.d.ts
/// <reference path="fs.d.ts" />
// @filename: node_modules/@types/node/fs.d.ts
declare module "fs" {
interface FSWatcher {}
}
// @filename: node_modules/@types/node/package.json
{
"name": "@types/node",
"version": "1.0.0"
}
// @filename: main.ts
/// <reference types="node" />
import { FSWatcher } from "fs";
export function f() {
return {} as FSWatcher;
}