Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions internal/tsoptions/commandlineparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type commandLineParser struct {
workerDiagnostics *ParseCommandLineWorkerDiagnostics
optionsMap *NameMap
fs vfs.FS
currentDirectory string
options *collections.OrderedMap[string, any]
fileNames []string
errors []*ast.Diagnostic
Expand All @@ -45,7 +46,7 @@ func ParseCommandLine(
if commandLine == nil {
commandLine = []string{}
}
parser := parseCommandLineWorker(CompilerOptionsDidYouMeanDiagnostics, commandLine, host.FS())
parser := parseCommandLineWorker(CompilerOptionsDidYouMeanDiagnostics, commandLine, host.FS(), host.GetCurrentDirectory())
optionsWithAbsolutePaths := convertToOptionsWithAbsolutePaths(parser.options.Clone(), CommandLineCompilerOptionsMap, host.GetCurrentDirectory())
compilerOptions := convertMapToOptions(optionsWithAbsolutePaths, &compilerOptionsParser{&core.CompilerOptions{}}).CompilerOptions
watchOptions := convertMapToOptions(optionsWithAbsolutePaths, &watchOptionsParser{&core.WatchOptions{}}).WatchOptions
Expand All @@ -66,7 +67,7 @@ func ParseBuildCommandLine(
if commandLine == nil {
commandLine = []string{}
}
parser := parseCommandLineWorker(buildOptionsDidYouMeanDiagnostics, commandLine, host.FS())
parser := parseCommandLineWorker(buildOptionsDidYouMeanDiagnostics, commandLine, host.FS(), host.GetCurrentDirectory())
compilerOptions := &core.CompilerOptions{}
for key, value := range parser.options.Entries() {
buildOption := BuildNameMap.Get(key)
Expand Down Expand Up @@ -114,9 +115,11 @@ func parseCommandLineWorker(
parseCommandLineWithDiagnostics *ParseCommandLineWorkerDiagnostics,
commandLine []string,
fs vfs.FS,
currentDirectory string,
) *commandLineParser {
parser := &commandLineParser{
fs: fs,
currentDirectory: currentDirectory,
workerDiagnostics: parseCommandLineWithDiagnostics,
fileNames: []string{},
options: &collections.OrderedMap[string, any]{},
Expand Down Expand Up @@ -163,6 +166,7 @@ func getInputOptionName(input string) string {
}

func (p *commandLineParser) parseResponseFile(fileName string) {
fileName = tspath.GetNormalizedAbsolutePath(fileName, p.currentDirectory)
fileContents, errors := tryReadFile(fileName, func(fileName string) (string, bool) {
if p.fs == nil {
return "", false
Expand Down
18 changes: 18 additions & 0 deletions internal/tsoptions/commandlineparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ func TestCommandLineParseResult(t *testing.T) {
}
}

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

// Passing `@` with an empty or relative filename should not panic.
// It should produce a diagnostic error instead.
t.Run("empty response file", func(t *testing.T) {
t.Parallel()
parsed := tsoptions.ParseCommandLineTestWorker(nil, []string{"@"}, osvfs.FS(), "/")
assert.Assert(t, len(parsed.Errors) > 0, "expected an error for empty response file name")
})

t.Run("relative response file", func(t *testing.T) {
t.Parallel()
parsed := tsoptions.ParseCommandLineTestWorker(nil, []string{"@blah"}, osvfs.FS(), "/")
assert.Assert(t, len(parsed.Errors) > 0, "expected an error for non-existent response file")
})
}

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

Expand Down
6 changes: 6 additions & 0 deletions internal/tsoptions/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ func ParseCommandLineTestWorker(
decls []*CommandLineOption,
commandLine []string,
fs vfs.FS,
currentDirectory ...string,
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 why is this ...string instead of just a singular parameter?

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.

No good reason — I used variadic to avoid updating the existing call site that omitted it, but that's not worth the indirection. Changed to a plain string parameter and added the "" argument at the existing call site.

) *TestCommandLineParser {
cwd := ""
if len(currentDirectory) > 0 {
cwd = currentDirectory[0]
}
parser := &commandLineParser{
fs: fs,
currentDirectory: cwd,
workerDiagnostics: CompilerOptionsDidYouMeanDiagnostics,
fileNames: []string{},
options: &collections.OrderedMap[string, any]{},
Expand Down