mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Cherry-pick PR #32878 into release-3.6
Component commits: c78c88f447 Fix references to path-mapped ambient modules in declaration files 48a1fc33f5 Fix lint
This commit is contained in:
parent
635a158d4f
commit
ef222a5892
@ -748,6 +748,7 @@ namespace ts {
|
||||
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
|
||||
getProgramBuildInfo: returnUndefined,
|
||||
getSourceFileFromReference: returnUndefined,
|
||||
redirectTargetsMap: createMultiMap()
|
||||
};
|
||||
emitFiles(
|
||||
notImplementedResolver,
|
||||
|
||||
@ -1446,6 +1446,7 @@ namespace ts {
|
||||
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
|
||||
getProgramBuildInfo: () => program.getProgramBuildInfo && program.getProgramBuildInfo(),
|
||||
getSourceFileFromReference: (file, ref) => program.getSourceFileFromReference(file, ref),
|
||||
redirectTargetsMap,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -327,6 +327,26 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (declFileName) {
|
||||
const specifier = moduleSpecifiers.getModuleSpecifier(
|
||||
// We pathify the baseUrl since we pathify the other paths here, so we can still easily check if the other paths are within the baseUrl
|
||||
// TODO: Should we _always_ be pathifying the baseUrl as we read it in?
|
||||
{ ...options, baseUrl: options.baseUrl && toPath(options.baseUrl, host.getCurrentDirectory(), host.getCanonicalFileName) },
|
||||
currentSourceFile,
|
||||
toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName),
|
||||
toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName),
|
||||
host,
|
||||
host.getSourceFiles(),
|
||||
/*preferences*/ undefined,
|
||||
host.redirectTargetsMap
|
||||
);
|
||||
if (!pathIsRelative(specifier)) {
|
||||
// If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
|
||||
// via a non-relative name, emit a type reference directive to that non-relative name, rather than
|
||||
// a relative path to the declaration file
|
||||
recordTypeReferenceDirectivesIfNecessary([specifier]);
|
||||
return;
|
||||
}
|
||||
|
||||
let fileName = getRelativePathToDirectoryOrUrl(
|
||||
outputFilePath,
|
||||
declFileName,
|
||||
|
||||
@ -5444,6 +5444,7 @@ namespace ts {
|
||||
writeFile: WriteFileCallback;
|
||||
getProgramBuildInfo(): ProgramBuildInfo | undefined;
|
||||
getSourceFileFromReference: Program["getSourceFileFromReference"];
|
||||
readonly redirectTargetsMap: RedirectTargetsMap;
|
||||
}
|
||||
|
||||
export interface TransformationContext {
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
//// [tests/cases/compiler/declarationEmitPathMappingMonorepo.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
declare module "@ts-bug/a" {
|
||||
export type AText = {
|
||||
value: string;
|
||||
};
|
||||
export function a(text: string): AText;
|
||||
}
|
||||
|
||||
//// [index.ts]
|
||||
import { a } from "@ts-bug/a";
|
||||
|
||||
export function b(text: string) {
|
||||
return a(text);
|
||||
}
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var a_1 = require("@ts-bug/a");
|
||||
function b(text) {
|
||||
return a_1.a(text);
|
||||
}
|
||||
exports.b = b;
|
||||
|
||||
|
||||
//// [index.d.ts]
|
||||
/// <reference types="@ts-bug/a" />
|
||||
export declare function b(text: string): import("@ts-bug/a").AText;
|
||||
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/packages/a/index.d.ts ===
|
||||
declare module "@ts-bug/a" {
|
||||
>"@ts-bug/a" : Symbol("@ts-bug/a", Decl(index.d.ts, 0, 0))
|
||||
|
||||
export type AText = {
|
||||
>AText : Symbol(AText, Decl(index.d.ts, 0, 28))
|
||||
|
||||
value: string;
|
||||
>value : Symbol(value, Decl(index.d.ts, 1, 25))
|
||||
|
||||
};
|
||||
export function a(text: string): AText;
|
||||
>a : Symbol(a, Decl(index.d.ts, 3, 6))
|
||||
>text : Symbol(text, Decl(index.d.ts, 4, 22))
|
||||
>AText : Symbol(AText, Decl(index.d.ts, 0, 28))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/packages/b/src/index.ts ===
|
||||
import { a } from "@ts-bug/a";
|
||||
>a : Symbol(a, Decl(index.ts, 0, 8))
|
||||
|
||||
export function b(text: string) {
|
||||
>b : Symbol(b, Decl(index.ts, 0, 30))
|
||||
>text : Symbol(text, Decl(index.ts, 2, 18))
|
||||
|
||||
return a(text);
|
||||
>a : Symbol(a, Decl(index.ts, 0, 8))
|
||||
>text : Symbol(text, Decl(index.ts, 2, 18))
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/packages/a/index.d.ts ===
|
||||
declare module "@ts-bug/a" {
|
||||
>"@ts-bug/a" : typeof import("@ts-bug/a")
|
||||
|
||||
export type AText = {
|
||||
>AText : AText
|
||||
|
||||
value: string;
|
||||
>value : string
|
||||
|
||||
};
|
||||
export function a(text: string): AText;
|
||||
>a : (text: string) => AText
|
||||
>text : string
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/packages/b/src/index.ts ===
|
||||
import { a } from "@ts-bug/a";
|
||||
>a : (text: string) => import("@ts-bug/a").AText
|
||||
|
||||
export function b(text: string) {
|
||||
>b : (text: string) => import("@ts-bug/a").AText
|
||||
>text : string
|
||||
|
||||
return a(text);
|
||||
>a(text) : import("@ts-bug/a").AText
|
||||
>a : (text: string) => import("@ts-bug/a").AText
|
||||
>text : string
|
||||
}
|
||||
28
tests/cases/compiler/declarationEmitPathMappingMonorepo.ts
Normal file
28
tests/cases/compiler/declarationEmitPathMappingMonorepo.ts
Normal file
@ -0,0 +1,28 @@
|
||||
// @filename: packages/a/index.d.ts
|
||||
declare module "@ts-bug/a" {
|
||||
export type AText = {
|
||||
value: string;
|
||||
};
|
||||
export function a(text: string): AText;
|
||||
}
|
||||
|
||||
// @filename: packages/b/src/index.ts
|
||||
import { a } from "@ts-bug/a";
|
||||
|
||||
export function b(text: string) {
|
||||
return a(text);
|
||||
}
|
||||
// @filename: packages/b/tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"declaration": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@ts-bug/a": ["../a"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @link: tests/cases/compiler/packages/a -> tests/cases/compiler/node_modules/@ts-bug/a
|
||||
// @link: tests/cases/compiler/packages/b -> tests/cases/compiler/node_modules/@ts-bug/b
|
||||
Loading…
x
Reference in New Issue
Block a user