Skip to content
Open
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
13 changes: 13 additions & 0 deletions tsc/internal/execute/tsctests/showconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ func TestShowConfig(t *testing.T) {
},
commandLineArgs: []string{"-p", "tsconfig.json", "--showConfig"},
},
{
subScenario: "Show TSConfig rejects bare relative extends",
cwd: "/home/src/workspaces/project/foo",
files: FileMap{
"/home/src/workspaces/project/tsconfig.json": `{}`,
"/home/src/workspaces/project/foo/a.ts": `export const a = 1;`,
"/home/src/workspaces/project/foo/tsconfig.json": stringtestutil.Dedent(`
{
"extends": ".."
}`),
},
commandLineArgs: []string{"-p", "tsconfig.json", "--showConfig"},
},
}

for _, value := range []string{"true", "false"} {
Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/tsoptions/tsconfigparsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func getExtendsConfigPath(
errors = append(errors, CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic(errorFile, valueExpression, diagnostics.Network_path_0_is_not_supported, extendedConfig))
return "", errors
}
if tspath.IsRootedDiskPath(extendedConfig) || strings.HasPrefix(extendedConfig, "./") || strings.HasPrefix(extendedConfig, "../") {
if tspath.IsRootedDiskPath(extendedConfig) || tspath.PathIsRelative(extendedConfig) {
extendedConfigPath := tspath.ToRootedFilePath(extendedConfig, basePath)
if !fs.FileExists(extendedConfigPath) && !extendedConfigPath.ExtensionIs(tspath.ExtensionJson) {
extendedConfigPath = extendedConfigPath.AppendSuffix(tspath.ExtensionJson)
Expand Down
39 changes: 39 additions & 0 deletions tsc/internal/tsoptions/tsconfigparsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,45 @@ func TestParseJsonSourceFileConfigFileContentReportsCircularExtendsChain(t *test
})
}

// Bare "." / ".." must use filesystem extends resolution, not module lookup (#51782).
func TestParseJsonSourceFileConfigFileContentRejectsBareRelativeExtends(t *testing.T) {
t.Parallel()
for _, extends := range []string{".", ".."} {
t.Run(extends, func(t *testing.T) {
t.Parallel()
files := map[string]string{
"/project/tsconfig.json": `{}`,
"/project/foo/tsconfig.json": `{ "extends": "` + extends + `" }`,
"/project/foo/main.ts": "export const x = 1;",
}
fs := tsoptionstest.NewVFS(files, tspath.CaseSensitive /*caseSensitivity*/)
configFileName := tspath.RootedFilePath("/project/foo/tsconfig.json")
configFile := tsoptions.NewTsconfigSourceFileFromFilePath(
configFileName,
fs.CaseSensitivity().PathKey(tspath.RootedPath(configFileName)),
files[configFileName.AsString()],
)

parsed := tsoptions.ParseJsonSourceFileConfigFileContent(
configFile,
tsoptions.NewDefaultParseConfigHost(fs),
"/project/foo",
nil,
nil,
nil,
nil,
)

notFound := core.Filter(parsed.Errors, func(diagnostic *ast.Diagnostic) bool {
return diagnostic.Code() == diagnostics.File_0_not_found.Code()
})
assert.DeepEqual(t, core.Map(notFound, (*ast.Diagnostic).MessageArgs), [][]string{
{extends},
})
})
}
}

// Extending an empty config file used to panic on nil Statements (#4265).
func TestParseJsonSourceFileConfigFileContentWithEmptyExtendedConfig(t *testing.T) {
t.Parallel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
currentDirectory::/home/src/workspaces/project/foo
useCaseSensitiveFileNames::true
Input::
//// [/home/src/workspaces/project/foo/a.ts] *new*
export const a = 1;
//// [/home/src/workspaces/project/foo/tsconfig.json] *new*
{
"extends": ".."
}
//// [/home/src/workspaces/project/tsconfig.json] *new*
{}

tsc -p tsconfig.json --showConfig
ExitStatus:: DiagnosticsPresent_OutputsSkipped
Output::
tsconfig.json:2:16 - error TS6053: File '..' not found.

2 "extends": ".."
   ~~~~