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
16 changes: 16 additions & 0 deletions internal/tsoptions/commandlineparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ func TestCommandLineParseResult(t *testing.T) {
}
}

func TestParseCommandLineTypeRootsRelativePath(t *testing.T) {
t.Parallel()

host := tsoptionstest.NewVFSParseConfigHost(map[string]string{
"/home/project/bug.ts": `let x = 1;`,
}, "/home/project", true)

cmdLine := tsoptions.ParseCommandLine([]string{"--typeRoots", "t", "bug.ts"}, host)

typeRoots := cmdLine.CompilerOptions().TypeRoots
assert.Assert(t, typeRoots != nil, "typeRoots should not be nil")
assert.Equal(t, len(typeRoots), 1)
assert.Assert(t, tspath.IsRootedDiskPath(typeRoots[0]), "typeRoots entry should be an absolute path, got: %s", typeRoots[0])
assert.Assert(t, strings.HasSuffix(typeRoots[0], "/t"), "typeRoots entry should end with '/t', got: %s", typeRoots[0])
}

func TestCustomConditionsNullOverride(t *testing.T) {
t.Parallel()

Expand Down
8 changes: 8 additions & 0 deletions internal/tsoptions/parsinghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ func ConvertOptionToAbsolutePath(o string, v any, optionMap CommandLineOptionNam
return tspath.GetNormalizedAbsolutePath(item, cwd)
}), true
}
if arr, ok := v.([]any); ok {
return core.Map(arr, func(item any) any {
if s, isStr := item.(string); isStr {
return tspath.GetNormalizedAbsolutePath(s, cwd)
}
return item
}), true
}
Comment on lines +645 to +652
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot investigate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reviewer was correct — the compiler test exercises the []string path via the test harness (which manually normalizes TypeRoots on lines 183-185 of harnessutil.go), not the []any CLI parser path. Added a unit test TestParseCommandLineTypeRootsRelativePath in 97e9f6b that calls ParseCommandLine with --typeRoots t and asserts the result is an absolute path, directly exercising the []any branch.

Comment on lines 642 to +652
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work, slices are invariant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, Go slices are invariant so []any and []string can't share a common generic handler. The two branches are necessary.

}
} else if option.IsFilePath {
if value, ok := v.(string); ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error TS2688: Cannot find type definition file for 'n'.
The file is in the program because:
Entry point of type library 'n' specified in compilerOptions


!!! error TS2688: Cannot find type definition file for 'n'.
!!! error TS2688: The file is in the program because:
!!! error TS2688: Entry point of type library 'n' specified in compilerOptions
==== typeRootsRelativePath.ts (0 errors) ====
let x = 1;

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/typeRootsRelativePath.ts] ////

=== typeRootsRelativePath.ts ===
let x = 1;
>x : Symbol(x, Decl(typeRootsRelativePath.ts, 0, 3))

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [tests/cases/compiler/typeRootsRelativePath.ts] ////

=== typeRootsRelativePath.ts ===
let x = 1;
>x : number
>1 : 1

5 changes: 5 additions & 0 deletions testdata/tests/cases/compiler/typeRootsRelativePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @typeRoots: t
// @types: n
// @noEmit: true

let x = 1;
Loading