Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (p *fileLoader) addProjectReferenceTasks(singleThreaded bool) {
})
}
} else {
for outputDts := range resolved.GetOutputDeclarationFileNames() {
for outputDts := range resolved.GetOutputDeclarationAndSourceFileNames() {
if outputDts != "" {
p.rootTasks = append(p.rootTasks, &parseTask{
normalizedFilePath: outputDts,
Expand Down
56 changes: 56 additions & 0 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,62 @@ func TestTscModuleResolution(t *testing.T) {
},
},
},
{
subScenario: "resolution from d.ts of referenced project",
files: FileMap{
"/home/src/workspaces/project/common.d.ts": "export type OnValue = (value: number) => void",
"/home/src/workspaces/project/producer/index.ts": stringtestutil.Dedent(`
export { ValueProducerDeclaration } from "./in-js"
import { OnValue } from "@common"
export interface ValueProducerFromTs {
onValue: OnValue;
}
`),
"/home/src/workspaces/project/producer/in-js.d.ts": stringtestutil.Dedent(`
import { OnValue } from "@common"
export interface ValueProducerDeclaration {
onValue: OnValue;
}
`),
"/home/src/workspaces/project/producer/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"strict": true,
"composite": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"paths": {
"@common": ["../common.d.ts"],
},
},
}`),
"/home/src/workspaces/project/consumer/index.ts": stringtestutil.Dedent(`
import { ValueProducerDeclaration, ValueProducerFromTs } from "@producer"
declare let v: ValueProducerDeclaration;
// n is implicitly any because onValue is actually any (despite what the tooltip says)
v.onValue = (n) => {
}
// n is implicitly number as expected
declare let v2: ValueProducerFromTs;
v2.onValue = (n) => {
}`),
"/home/src/workspaces/project/consumer/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"strict": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"paths": {
"@producer": ["../producer/index"],
},
},
"references": [
{ "path": "../producer" },
],
}`),
},
commandLineArgs: []string{"--b", "consumer", "--traceResolution", "-v"},
},
}

for _, test := range testCases {
Expand Down
8 changes: 4 additions & 4 deletions internal/testutil/stringtestutil/stringtestutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ func Dedent(text string) string {
startLine := -1
lastLine := 0
for i, line := range lines {
firstNonTab := strings.IndexFunc(line, func(r rune) bool {
return r != '\t'
firstNonWhite := strings.IndexFunc(line, func(r rune) bool {
return !stringutil.IsWhiteSpaceLike(r)
})
if firstNonTab > 0 {
line = strings.Repeat(" ", firstNonTab) + line[firstNonTab:]
if firstNonWhite > 0 {
line = strings.ReplaceAll(line[0:firstNonWhite], "\t", " ") + line[firstNonWhite:]
lines[i] = line
}
line = strings.TrimSpace(line)
Expand Down
9 changes: 3 additions & 6 deletions internal/tsoptions/parsedcommandline.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (p *ParsedCommandLine) ParseInputOutputNames() {
sourceToOutput := map[tspath.Path]*SourceOutputAndProjectReference{}
outputDtsToSource := map[tspath.Path]*SourceOutputAndProjectReference{}

for outputDts, source := range p.GetOutputDeclarationFileNames() {
for outputDts, source := range p.GetOutputDeclarationAndSourceFileNames() {
path := tspath.ToPath(source, p.GetCurrentDirectory(), p.UseCaseSensitiveFileNames())
projectReference := &SourceOutputAndProjectReference{
Source: source,
Expand Down Expand Up @@ -131,14 +131,11 @@ func (p *ParsedCommandLine) UseCaseSensitiveFileNames() bool {
return p.comparePathsOptions.UseCaseSensitiveFileNames
}

func (p *ParsedCommandLine) GetOutputDeclarationFileNames() iter.Seq2[string, string] {
func (p *ParsedCommandLine) GetOutputDeclarationAndSourceFileNames() iter.Seq2[string, string] {
return func(yield func(dtsName string, inputName string) bool) {
for _, fileName := range p.ParsedConfig.FileNames {
if tspath.IsDeclarationFileName(fileName) {
continue
}
var outputDts string
if !tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
if !tspath.IsDeclarationFileName(fileName) && !tspath.FileExtensionIs(fileName, tspath.ExtensionJson) {
outputDts = outputpaths.GetOutputDeclarationFileNameWorker(fileName, p.CompilerOptions(), p)
}
if !yield(outputDts, fileName) {
Expand Down
Loading
Loading