Skip to content

Commit 4c9b8f6

Browse files
authored
Fix incorrectly ignored dts file from project reference for resolution (#1712)
1 parent 81bb6b9 commit 4c9b8f6

File tree

5 files changed

+354
-11
lines changed

5 files changed

+354
-11
lines changed

internal/compiler/fileloader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (p *fileLoader) addProjectReferenceTasks(singleThreaded bool) {
356356
})
357357
}
358358
} else {
359-
for outputDts := range resolved.GetOutputDeclarationFileNames() {
359+
for outputDts := range resolved.GetOutputDeclarationAndSourceFileNames() {
360360
if outputDts != "" {
361361
p.rootTasks = append(p.rootTasks, &parseTask{
362362
normalizedFilePath: outputDts,

internal/execute/tsctests/tsc_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,62 @@ func TestTscModuleResolution(t *testing.T) {
25502550
},
25512551
},
25522552
},
2553+
{
2554+
subScenario: "resolution from d.ts of referenced project",
2555+
files: FileMap{
2556+
"/home/src/workspaces/project/common.d.ts": "export type OnValue = (value: number) => void",
2557+
"/home/src/workspaces/project/producer/index.ts": stringtestutil.Dedent(`
2558+
export { ValueProducerDeclaration } from "./in-js"
2559+
import { OnValue } from "@common"
2560+
export interface ValueProducerFromTs {
2561+
onValue: OnValue;
2562+
}
2563+
`),
2564+
"/home/src/workspaces/project/producer/in-js.d.ts": stringtestutil.Dedent(`
2565+
import { OnValue } from "@common"
2566+
export interface ValueProducerDeclaration {
2567+
onValue: OnValue;
2568+
}
2569+
`),
2570+
"/home/src/workspaces/project/producer/tsconfig.json": stringtestutil.Dedent(`
2571+
{
2572+
"compilerOptions": {
2573+
"strict": true,
2574+
"composite": true,
2575+
"module": "nodenext",
2576+
"moduleResolution": "nodenext",
2577+
"paths": {
2578+
"@common": ["../common.d.ts"],
2579+
},
2580+
},
2581+
}`),
2582+
"/home/src/workspaces/project/consumer/index.ts": stringtestutil.Dedent(`
2583+
import { ValueProducerDeclaration, ValueProducerFromTs } from "@producer"
2584+
declare let v: ValueProducerDeclaration;
2585+
// n is implicitly any because onValue is actually any (despite what the tooltip says)
2586+
v.onValue = (n) => {
2587+
}
2588+
// n is implicitly number as expected
2589+
declare let v2: ValueProducerFromTs;
2590+
v2.onValue = (n) => {
2591+
}`),
2592+
"/home/src/workspaces/project/consumer/tsconfig.json": stringtestutil.Dedent(`
2593+
{
2594+
"compilerOptions": {
2595+
"strict": true,
2596+
"module": "nodenext",
2597+
"moduleResolution": "nodenext",
2598+
"paths": {
2599+
"@producer": ["../producer/index"],
2600+
},
2601+
},
2602+
"references": [
2603+
{ "path": "../producer" },
2604+
],
2605+
}`),
2606+
},
2607+
commandLineArgs: []string{"--b", "consumer", "--traceResolution", "-v"},
2608+
},
25532609
}
25542610

25552611
for _, test := range testCases {

internal/testutil/stringtestutil/stringtestutil.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ func Dedent(text string) string {
1313
startLine := -1
1414
lastLine := 0
1515
for i, line := range lines {
16-
firstNonTab := strings.IndexFunc(line, func(r rune) bool {
17-
return r != '\t'
16+
firstNonWhite := strings.IndexFunc(line, func(r rune) bool {
17+
return !stringutil.IsWhiteSpaceLike(r)
1818
})
19-
if firstNonTab > 0 {
20-
line = strings.Repeat(" ", firstNonTab) + line[firstNonTab:]
19+
if firstNonWhite > 0 {
20+
line = strings.ReplaceAll(line[0:firstNonWhite], "\t", " ") + line[firstNonWhite:]
2121
lines[i] = line
2222
}
2323
line = strings.TrimSpace(line)

internal/tsoptions/parsedcommandline.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (p *ParsedCommandLine) ParseInputOutputNames() {
8787
sourceToOutput := map[tspath.Path]*SourceOutputAndProjectReference{}
8888
outputDtsToSource := map[tspath.Path]*SourceOutputAndProjectReference{}
8989

90-
for outputDts, source := range p.GetOutputDeclarationFileNames() {
90+
for outputDts, source := range p.GetOutputDeclarationAndSourceFileNames() {
9191
path := tspath.ToPath(source, p.GetCurrentDirectory(), p.UseCaseSensitiveFileNames())
9292
projectReference := &SourceOutputAndProjectReference{
9393
Source: source,
@@ -131,14 +131,11 @@ func (p *ParsedCommandLine) UseCaseSensitiveFileNames() bool {
131131
return p.comparePathsOptions.UseCaseSensitiveFileNames
132132
}
133133

134-
func (p *ParsedCommandLine) GetOutputDeclarationFileNames() iter.Seq2[string, string] {
134+
func (p *ParsedCommandLine) GetOutputDeclarationAndSourceFileNames() iter.Seq2[string, string] {
135135
return func(yield func(dtsName string, inputName string) bool) {
136136
for _, fileName := range p.ParsedConfig.FileNames {
137-
if tspath.IsDeclarationFileName(fileName) {
138-
continue
139-
}
140137
var outputDts string
141-
if !tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
138+
if !tspath.IsDeclarationFileName(fileName) && !tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
142139
outputDts = outputpaths.GetOutputDeclarationFileNameWorker(fileName, p.CompilerOptions(), p)
143140
}
144141
if !yield(outputDts, fileName) {

0 commit comments

Comments
 (0)