MCPcopy Create free account
hub / github.com/microsoft/typescript-go / ParseBuildCommandLine

Function ParseBuildCommandLine

internal/tsoptions/commandlineparser.go:63–112  ·  view source on GitHub ↗
(
	commandLine []string,
	host ParseConfigHost,
)

Source from the content-addressed store, hash-verified

61}
62
63func ParseBuildCommandLine(
64 commandLine []string,
65 host ParseConfigHost,
66) *ParsedBuildCommandLine {
67 if commandLine == nil {
68 commandLine = []string{}
69 }
70 parser := parseCommandLineWorker(buildOptionsDidYouMeanDiagnostics, commandLine, host.FS(), host.GetCurrentDirectory())
71 compilerOptions := &core.CompilerOptions{}
72 for key, value := range parser.options.Entries() {
73 buildOption := BuildNameMap.Get(key)
74 if buildOption == &TscBuildOption || buildOption == CompilerNameMap.Get(key) {
75 ParseCompilerOptions(key, value, compilerOptions)
76 }
77 }
78 result := &ParsedBuildCommandLine{
79 BuildOptions: convertMapToOptions(parser.options, &buildOptionsParser{&core.BuildOptions{}}).BuildOptions,
80 CompilerOptions: compilerOptions,
81 WatchOptions: convertMapToOptions(parser.options, &watchOptionsParser{&core.WatchOptions{}}).WatchOptions,
82 Projects: parser.fileNames,
83 Errors: parser.errors,
84 Raw: parser.options,
85
86 comparePathsOptions: tspath.ComparePathsOptions{
87 UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
88 CurrentDirectory: host.GetCurrentDirectory(),
89 },
90 }
91
92 if len(result.Projects) == 0 {
93 // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ."
94 result.Projects = append(result.Projects, ".")
95 }
96
97 // Nonsensical combinations
98 if result.BuildOptions.Clean.IsTrue() && result.BuildOptions.Force.IsTrue() {
99 result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force"))
100 }
101 if result.BuildOptions.Clean.IsTrue() && result.BuildOptions.Verbose.IsTrue() {
102 result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose"))
103 }
104 if result.BuildOptions.Clean.IsTrue() && result.CompilerOptions.Watch.IsTrue() {
105 result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch"))
106 }
107 if result.CompilerOptions.Watch.IsTrue() && result.BuildOptions.Dry.IsTrue() {
108 result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry"))
109 }
110
111 return result
112}
113
114func parseCommandLineWorker(
115 parseCommandLineWithDiagnostics *ParseCommandLineWorkerDiagnostics,

Callers 2

CommandLineFunction · 0.92

Calls 12

NewCompilerDiagnosticFunction · 0.92
parseCommandLineWorkerFunction · 0.85
ParseCompilerOptionsFunction · 0.85
convertMapToOptionsFunction · 0.85
lenFunction · 0.85
IsTrueMethod · 0.80
FSMethod · 0.65
GetCurrentDirectoryMethod · 0.65
GetMethod · 0.65
appendFunction · 0.50
EntriesMethod · 0.45

Tested by 1