diff --git a/tsc/internal/api/session_program_test.go b/tsc/internal/api/session_program_test.go index 6cdd99530fcd4..fb3b2181fdbcb 100644 --- a/tsc/internal/api/session_program_test.go +++ b/tsc/internal/api/session_program_test.go @@ -47,6 +47,57 @@ func TestProgramSourceFileIncludesSupplementalFile(t *testing.T) { assert.Assert(t, sourceFile != nil) } +// A file name with a trailing slash names the same source file. +// ToFileName normalizes the name and removes the trailing slash. +func TestProgramSourceFileNameWithTrailingSlash(t *testing.T) { + t.Parallel() + + const fileName = "/home/projects/p/a.ts" + projectSession, _ := projecttestutil.Setup(map[string]any{ + fileName: `export const a: number = "1";`, + }) + defer projectSession.Close() + session := NewLSPSession(projectSession, nil) + defer session.Close() + response, err := session.handleCreateSnapshot(context.Background(), &CreateSnapshotParams{ + CreatePrograms: []*CreateSnapshotProgramParams{{ + RootFiles: []DocumentIdentifier{{FileName: fileName}}, + CompilerOptions: core.CompilerOptions{NoLib: core.TSTrue}, + }}, + }) + assert.NilError(t, err) + file := DocumentIdentifier{FileName: fileName + "/"} + + metadata, err := session.handleGetSourceFileMetadata(context.Background(), &GetSourceFileParams{ + Snapshot: response.Snapshot, + Project: response.Projects[0].Handle, + File: file, + }) + assert.NilError(t, err) + assert.Assert(t, metadata != nil) + + // Position 13 is in the name `a`. + symbol, err := session.handleGetSymbolAtPosition(context.Background(), &GetSymbolAtPositionParams{ + Snapshot: response.Snapshot, + Project: response.Projects[0].Handle, + File: file, + Position: 13, + }) + assert.NilError(t, err) + assert.Assert(t, symbol != nil) + assert.Equal(t, symbol.Name, "a") + + diagnostics, err := session.handleGetSemanticDiagnostics(context.Background(), &GetDiagnosticsParams{ + Snapshot: response.Snapshot, + Project: response.Projects[0].Handle, + Files: []DocumentIdentifier{file}, + }) + assert.NilError(t, err) + assert.Equal(t, len(diagnostics), 1) + assert.Equal(t, diagnostics[0].Code, int32(2322)) + assert.Equal(t, diagnostics[0].FileName.AsString(), fileName) +} + func TestProgramStatisticsUseAPIChecker(t *testing.T) { t.Parallel() diff --git a/tsc/internal/execute/tsctests/sys.go b/tsc/internal/execute/tsctests/sys.go index 555377a2aed31..668e40f5ec527 100644 --- a/tsc/internal/execute/tsctests/sys.go +++ b/tsc/internal/execute/tsctests/sys.go @@ -613,6 +613,17 @@ func (s *TestSys) replaceFileText(path string, oldText string, newText string) { s.writeFileNoError(path, content) } +// replaceFileTextNoMiss is like replaceFileText, but it panics if the file does +// not contain oldText. Use it when an edit that changes nothing makes the test +// pass for the wrong reason. +func (s *TestSys) replaceFileTextNoMiss(path string, oldText string, newText string) { + content := s.readFileNoError(path) + if !strings.Contains(content, oldText) { + panic(fmt.Sprintf("Text %q not found in %s", oldText, path)) + } + s.writeFileNoError(path, strings.Replace(content, oldText, newText, 1)) +} + func (s *TestSys) replaceFileTextAll(path string, oldText string, newText string) { content := s.readFileNoError(path) content = strings.ReplaceAll(content, oldText, newText) diff --git a/tsc/internal/execute/tsctests/tsc_test.go b/tsc/internal/execute/tsctests/tsc_test.go index ee429a826f94a..6c78393a1b4d1 100644 --- a/tsc/internal/execute/tsctests/tsc_test.go +++ b/tsc/internal/execute/tsctests/tsc_test.go @@ -253,6 +253,20 @@ func TestTscCommandline(t *testing.T) { }, commandLineArgs: []string{"-p", "/home/src/workspaces/project"}, }, + { + subScenario: "Parse -p with path to subfolder that has only declaration files and outDir", + files: FileMap{ + "/home/src/workspaces/project/sub/a.d.ts": `declare const x: number;`, + "/home/src/workspaces/project/sub/tsconfig.json": `{ "compilerOptions": { "outDir": "../out" } }`, + }, + commandLineArgs: []string{"-p", "sub"}, + edits: []*tscEdit{ + { + caption: "build with -b", + commandLineArgs: []string{"-b", "sub"}, + }, + }, + }, { subScenario: "Parse -p with empty tsconfig file", files: FileMap{ @@ -392,6 +406,17 @@ func TestTscMissingFiles(t *testing.T) { }, commandLineArgs: []string{"-p", "./tsconfig.json"}, }, + { + subScenario: "rooted file names in tsconfig do not exist", + files: FileMap{ + "/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent( + `{ + "files": ["/x/", "C:"] + }`, + ), + }, + commandLineArgs: []string{"-p", "./tsconfig.json"}, + }, { subScenario: "extensionless file in tsconfig exists", files: FileMap{ @@ -1730,6 +1755,53 @@ func TestTscIncremental(t *testing.T) { }, }, }, + { + subScenario: "tsbuildinfo has tuple of wrong length", + files: FileMap{ + "/home/src/workspaces/project/a.ts": `import { b } from "./b"; export const a = b + 1;`, + "/home/src/workspaces/project/b.ts": "export const b = 2;", + "/home/src/workspaces/project/tsconfig.json": "{}", + }, + commandLineArgs: []string{"-i"}, + edits: []*tscEdit{ + { + caption: "referencedMap entry with one element", + edit: func(sys *TestSys) { + // The non incremental build has no tsbuildinfo to change + if !sys.forIncrementalCorrectness { + sys.replaceFileTextNoMiss("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"referencedMap":[[3,1]]`, `"referencedMap":[[3]]`) + } + }, + }, + { + caption: "referencedMap entry with three elements", + edit: func(sys *TestSys) { + // The non incremental build has no tsbuildinfo to change + if !sys.forIncrementalCorrectness { + sys.replaceFileTextNoMiss("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"referencedMap":[[3,1]]`, `"referencedMap":[[3,1,2]]`) + } + }, + }, + { + caption: "root entry with three elements", + edit: func(sys *TestSys) { + // The non incremental build has no tsbuildinfo to change + if !sys.forIncrementalCorrectness { + sys.replaceFileTextNoMiss("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"root":[[2,3]]`, `"root":[[1,2,3]]`) + } + }, + }, + { + caption: "root entry with no elements", + edit: func(sys *TestSys) { + // The non incremental build has no tsbuildinfo to change + if !sys.forIncrementalCorrectness { + sys.replaceFileTextNoMiss("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"root":[[2,3]]`, `"root":[[]]`) + } + }, + }, + }, + }, { subScenario: "when global file is added, the signatures are updated", files: FileMap{ diff --git a/tsc/internal/execute/tsctests/tscbuild_test.go b/tsc/internal/execute/tsctests/tscbuild_test.go index f0ce7ad4d53a9..12b590c10f924 100644 --- a/tsc/internal/execute/tsctests/tscbuild_test.go +++ b/tsc/internal/execute/tsctests/tscbuild_test.go @@ -721,6 +721,13 @@ func TestBuildConfigFileErrors(t *testing.T) { files: FileMap{}, commandLineArgs: []string{"--b", "bogus.json"}, }, + { + subScenario: "reports no inputs found", + files: FileMap{ + "/home/src/workspaces/project/tsconfig.json": `{ "include": ["missing.ts"] }`, + }, + commandLineArgs: []string{"--b"}, + }, { subScenario: "reports syntax errors in config file", files: FileMap{ diff --git a/tsc/internal/fourslash/tests/renameFilePackageJson_test.go b/tsc/internal/fourslash/tests/renameFilePackageJson_test.go index acd1be01b88db..4ad41cc4c8192 100644 --- a/tsc/internal/fourslash/tests/renameFilePackageJson_test.go +++ b/tsc/internal/fourslash/tests/renameFilePackageJson_test.go @@ -5,8 +5,10 @@ import ( "testing" "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" "github.com/microsoft/TypeScript/tsc/internal/testutil" "github.com/microsoft/TypeScript/tsc/internal/tspath" + "gotest.tools/v3/assert" ) func TestRenameFilePackageJson(t *testing.T) { @@ -51,3 +53,43 @@ import { value } from ".//*rename*/%s.js";`, fileName, tspath.RemoveFileExtensio }) } } + +func TestRenameFileNewNameIsNormalized(t *testing.T) { + t.Parallel() + + // The new URI of the file rename is a normalized path. It has no "." segment, + // no ".." segment, and no empty segment. + for _, test := range []struct { + name string + newName string + newURI lsproto.DocumentUri + }{ + {name: "dot segment", newName: "./b", newURI: "file:///src/b.ts"}, + {name: "dot dot segment", newName: "x/../b", newURI: "file:///src/b.ts"}, + {name: "empty segment", newName: "x//b", newURI: "file:///src/x/b.ts"}, + } { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /src/a.ts +export {}; +// @Filename: /src/main.ts +import ".//*rename*/a";` + + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "rename") + result := f.RenameAtCaret(t, test.newName) + if result.WorkspaceEdit == nil || result.WorkspaceEdit.DocumentChanges == nil { + t.Fatal("rename returned no document changes") + } + for _, change := range *result.WorkspaceEdit.DocumentChanges { + if change.RenameFile != nil { + assert.Equal(t, change.RenameFile.NewUri, test.newURI) + return + } + } + t.Fatal("rename returned no file rename") + }) + } +} diff --git a/tsc/internal/ls/lsconv/converters_test.go b/tsc/internal/ls/lsconv/converters_test.go index 1502cd466f469..09843a453ac78 100644 --- a/tsc/internal/ls/lsconv/converters_test.go +++ b/tsc/internal/ls/lsconv/converters_test.go @@ -30,6 +30,7 @@ func TestDocumentURIToFileName(t *testing.T) { {"file://server/share/file.ts", "//server/share/file.ts"}, {"file:///d%3A/work/ts932/lib/utils.ts", "d:/work/ts932/lib/utils.ts"}, {"file:///D%3A/work/ts932/lib/utils.ts", "D:/work/ts932/lib/utils.ts"}, + {"file:///d%3A", "d:/"}, {"file:///d%3A/work/ts932/app/%28test%29/comp/comp-test.tsx", "d:/work/ts932/app/(test)/comp/comp-test.tsx"}, {"file:///path/to/file.ts#section", "/path/to/file.ts"}, {"file:///c:/test/me", "c:/test/me"}, diff --git a/tsc/internal/module/resolver_test.go b/tsc/internal/module/resolver_test.go index 63a5b13e7de0f..d6871561d40cf 100644 --- a/tsc/internal/module/resolver_test.go +++ b/tsc/internal/module/resolver_test.go @@ -738,6 +738,57 @@ func TestResolveDynamicDottedDirectory(t *testing.T) { } } +func TestResolveDynamicTypeRoot(t *testing.T) { + t.Parallel() + + // In a type root under a dynamic URI, the file encoding and the directory + // encoding of the name differ. The file encoding keeps ".d.ts" outside the + // escape. The directory lookup uses the directory encoding. + const ( + sourceFile = "^/~ts-uri~/custom/ts-nul-authority/a.ts" + typeRoot = "^/~ts-uri~/custom/ts-nul-authority/types" + name = "~ts-uri-escape~thing.d.ts" + fileTargetFile = typeRoot + "/~ts-uri-escape~7e74732d7572692d6573636170657e7468696e67~.d.ts" + directoryTargetFile = typeRoot + "/~ts-uri-escape~7e74732d7572692d6573636170657e7468696e672e642e7473~/index.d.ts" + ) + for _, test := range []struct { + name string + targetFile tspath.RootedFilePath + module bool + }{ + {name: "type reference to directory", targetFile: directoryTargetFile}, + {name: "type reference to file", targetFile: fileTargetFile}, + {name: "module to directory", targetFile: directoryTargetFile, module: true}, + } { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + fs := vfstest.FromMap(map[string]string{ + sourceFile: "", + test.targetFile.AsString(): "declare const value: number;", + }, tspath.CaseSensitive) + host := &resolutionTestInputs{fs: fs, cwd: "^/~ts-uri~/custom/ts-nul-authority/"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + TypeRoots: []tspath.RootedDirectoryPath{typeRoot}, + } + + resolver := NewResolver(ResolverOptions{Host: host, CompilerOptions: opts}) + var resolvedFileName tspath.RootedFilePath + if test.module { + // The module lookup falls back to the type roots. + resolved, _, _ := resolver.ResolveModuleName(name, sourceFile, core.ModuleKindCommonJS, nil) + resolvedFileName = resolved.ResolvedFileName + } else { + resolved, _ := resolver.ResolveTypeReferenceDirective(name, sourceFile, core.ResolutionModeNone, nil) + resolvedFileName = resolved.ResolvedFileName + } + if resolvedFileName != test.targetFile { + t.Errorf("resolved file = %q, expected %q", resolvedFileName, test.targetFile) + } + }) + } +} + func TestResolvedModuleCarriesCaseInsensitivePath(t *testing.T) { t.Parallel() diff --git a/tsc/internal/outputpaths/outputpaths_test.go b/tsc/internal/outputpaths/outputpaths_test.go index 62dc9aac1d4df..b95cf394c9092 100644 --- a/tsc/internal/outputpaths/outputpaths_test.go +++ b/tsc/internal/outputpaths/outputpaths_test.go @@ -118,6 +118,19 @@ func TestGetBuildInfoFileNameAcrossRoots(t *testing.T) { configFilePath: "c:/src/project/...json", expected: "c:/out/...tsbuildinfo", }, + { + name: "drive-like filename stem without rootDir", + outDir: "c:/out", + configFilePath: "c:/src/project/c:.json", + expected: "c:/out/c:.tsbuildinfo", + }, + { + name: "drive-like filename stem in rootDir", + rootDir: "c:/src", + outDir: "c:/out", + configFilePath: "c:/src/c:.json", + expected: "c:/out/c:.tsbuildinfo", + }, { name: "empty filename stem without outDir", configFilePath: "c:/src/project/.json", diff --git a/tsc/internal/tsoptions/extensionsiblings_test.go b/tsc/internal/tsoptions/extensionsiblings_test.go index f9dcd01477879..2a411cdff1785 100644 --- a/tsc/internal/tsoptions/extensionsiblings_test.go +++ b/tsc/internal/tsoptions/extensionsiblings_test.go @@ -76,6 +76,7 @@ func TestGetFileNamesExtensionPriority(t *testing.T) { {files: []string{"A.ts", "a.d.ts"}, include: []string{"**/*"}, expected: []string{"/p/A.ts", "/p/a.d.ts"}}, {files: []string{"a.d.ts", "a.ts"}, include: []string{"**/*"}, literals: []string{"a.d.ts"}, expected: []string{"/p/a.d.ts", "/p/a.ts"}}, {files: []string{"a.ts", "a.d.ts"}, include: []string{"**/*"}, literals: []string{"a.ts"}, expected: []string{"/p/a.ts"}}, + {files: []string{"a.ts", "a.d.ts"}, include: []string{"*.d.ts"}, literals: []string{"a.ts"}, expected: []string{"/p/a.ts"}}, } for _, c := range cases { got, want := runGetFileNames(c.files, c.include, c.literals, c.allowJs, c.insens, nil, pattern, basePath) diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.errors.txt b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.errors.txt new file mode 100644 index 0000000000000..6d73fa5c24344 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.errors.txt @@ -0,0 +1,22 @@ +/src/main.ts(2,14): error TS2883: The inferred type of 'v' cannot be named without a reference to 'L' from '../node_modules/pkg/dist/foo'. This is likely not portable. A type annotation is necessary. + + +==== /src/main.ts (1 errors) ==== + import { make } from "dep"; + export const v = make(); + ~ +!!! error TS2883: The inferred type of 'v' cannot be named without a reference to 'L' from '../node_modules/pkg/dist/foo'. This is likely not portable. A type annotation is necessary. + +==== /node_modules/pkg/package.json (0 errors) ==== + { "name": "pkg", "exports": { "./*": "./dist/*/" } } + +==== /node_modules/pkg/dist/foo.d.ts (0 errors) ==== + export interface L { x: number } + +==== /node_modules/dep/package.json (0 errors) ==== + { "name": "dep" } + +==== /node_modules/dep/index.d.ts (0 errors) ==== + import type { L } from "../pkg/dist/foo"; + export declare function make(): L; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.js b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.js new file mode 100644 index 0000000000000..a791a05d82e6d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts] //// + +//// [package.json] +{ "name": "pkg", "exports": { "./*": "./dist/*/" } } + +//// [foo.d.ts] +export interface L { x: number } + +//// [package.json] +{ "name": "dep" } + +//// [index.d.ts] +import type { L } from "../pkg/dist/foo"; +export declare function make(): L; + +//// [main.ts] +import { make } from "dep"; +export const v = make(); + + +//// [main.js] +import { make } from "dep"; +export const v = make(); diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.symbols new file mode 100644 index 0000000000000..f361ad8a98950 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.symbols @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts] //// + +=== /src/main.ts === +import { make } from "dep"; +>make : Symbol(make, Decl(main.ts, 0, 8)) + +export const v = make(); +>v : Symbol(v, Decl(main.ts, 1, 12)) +>make : Symbol(make, Decl(main.ts, 0, 8)) + +=== /node_modules/pkg/dist/foo.d.ts === +export interface L { x: number } +>L : Symbol(L, Decl(foo.d.ts, 0, 0)) +>x : Symbol(L.x, Decl(foo.d.ts, 0, 20)) + +=== /node_modules/dep/index.d.ts === +import type { L } from "../pkg/dist/foo"; +>L : Symbol(L, Decl(index.d.ts, 0, 13)) + +export declare function make(): L; +>make : Symbol(make, Decl(index.d.ts, 0, 41)) +>L : Symbol(L, Decl(index.d.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.types b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.types new file mode 100644 index 0000000000000..afd08c5cc85e5 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsPatternTargetTrailingSlash.types @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts] //// + +=== /src/main.ts === +import { make } from "dep"; +>make : () => import("../node_modules/pkg/dist/foo.js").L + +export const v = make(); +>v : import("../node_modules/pkg/dist/foo").L +>make() : import("../node_modules/pkg/dist/foo").L +>make : () => import("../node_modules/pkg/dist/foo").L + +=== /node_modules/pkg/dist/foo.d.ts === +export interface L { x: number } +>x : number + +=== /node_modules/dep/index.d.ts === +import type { L } from "../pkg/dist/foo"; +>L : L + +export declare function make(): L; +>make : () => L + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.errors.txt b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.errors.txt new file mode 100644 index 0000000000000..3800490f85cbe --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.errors.txt @@ -0,0 +1,22 @@ +/src/main.ts(2,14): error TS2883: The inferred type of 'v' cannot be named without a reference to 'L' from '../node_modules/pkg'. This is likely not portable. A type annotation is necessary. + + +==== /src/main.ts (1 errors) ==== + import { make } from "dep"; + export const v = make(); + ~ +!!! error TS2883: The inferred type of 'v' cannot be named without a reference to 'L' from '../node_modules/pkg'. This is likely not portable. A type annotation is necessary. + +==== /node_modules/pkg/package.json (0 errors) ==== + { "name": "pkg", "exports": { ".": "./index.js/" } } + +==== /node_modules/pkg/index.d.ts (0 errors) ==== + export interface L { x: number } + +==== /node_modules/dep/package.json (0 errors) ==== + { "name": "dep" } + +==== /node_modules/dep/index.d.ts (0 errors) ==== + import type { L } from "../pkg/index"; + export declare function make(): L; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.js b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.js new file mode 100644 index 0000000000000..4fe2f6c02d984 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts] //// + +//// [package.json] +{ "name": "pkg", "exports": { ".": "./index.js/" } } + +//// [index.d.ts] +export interface L { x: number } + +//// [package.json] +{ "name": "dep" } + +//// [index.d.ts] +import type { L } from "../pkg/index"; +export declare function make(): L; + +//// [main.ts] +import { make } from "dep"; +export const v = make(); + + +//// [main.js] +import { make } from "dep"; +export const v = make(); diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.symbols new file mode 100644 index 0000000000000..8cafebc644f46 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.symbols @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts] //// + +=== /src/main.ts === +import { make } from "dep"; +>make : Symbol(make, Decl(main.ts, 0, 8)) + +export const v = make(); +>v : Symbol(v, Decl(main.ts, 1, 12)) +>make : Symbol(make, Decl(main.ts, 0, 8)) + +=== /node_modules/pkg/index.d.ts === +export interface L { x: number } +>L : Symbol(L, Decl(index.d.ts, 0, 0)) +>x : Symbol(L.x, Decl(index.d.ts, 0, 20)) + +=== /node_modules/dep/index.d.ts === +import type { L } from "../pkg/index"; +>L : Symbol(L, Decl(index.d.ts, 0, 13)) + +export declare function make(): L; +>make : Symbol(make, Decl(index.d.ts, 0, 38)) +>L : Symbol(L, Decl(index.d.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.types b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.types new file mode 100644 index 0000000000000..ee25e0060b37d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitExportsTargetTrailingSlash.types @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts] //// + +=== /src/main.ts === +import { make } from "dep"; +>make : () => import("../node_modules/pkg/index.js").L + +export const v = make(); +>v : import("../node_modules/pkg").L +>make() : import("../node_modules/pkg").L +>make : () => import("../node_modules/pkg").L + +=== /node_modules/pkg/index.d.ts === +export interface L { x: number } +>x : number + +=== /node_modules/dep/index.d.ts === +import type { L } from "../pkg/index"; +>L : L + +export declare function make(): L; +>make : () => L + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.js b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.js new file mode 100644 index 0000000000000..4be513595d11f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts] //// + +//// [index.ts] +export interface T { v: number } +export function make(): T { return { v: 1 }; } + +//// [lib.ts] +export const other = 1; + +//// [re.ts] +export { make } from "../../shared/lib/index"; + +//// [a.ts] +import { make } from "./re"; +export const v = make(); + + + + +//// [index.d.ts] +export interface T { + v: number; +} +export declare function make(): T; +//// [re.d.ts] +export { make } from "../../shared/lib/index"; +//// [a.d.ts] +export declare const v: import("../../shared/lib/index").T; diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.symbols new file mode 100644 index 0000000000000..8897998f8acbd --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.symbols @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts] //// + +=== /project/app/src/re.ts === +export { make } from "../../shared/lib/index"; +>make : Symbol(make, Decl(re.ts, 0, 8)) + +=== /project/app/src/a.ts === +import { make } from "./re"; +>make : Symbol(make, Decl(a.ts, 0, 8)) + +export const v = make(); +>v : Symbol(v, Decl(a.ts, 1, 12)) +>make : Symbol(make, Decl(a.ts, 0, 8)) + +=== /project/shared/lib/index.ts === +export interface T { v: number } +>T : Symbol(T, Decl(index.ts, 0, 0)) +>v : Symbol(T.v, Decl(index.ts, 0, 20)) + +export function make(): T { return { v: 1 }; } +>make : Symbol(make, Decl(index.ts, 0, 32)) +>T : Symbol(T, Decl(index.ts, 0, 0)) +>v : Symbol(v, Decl(index.ts, 1, 36)) + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.types b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.types new file mode 100644 index 0000000000000..78289f5fc40cb --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.types @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts] //// + +=== /project/app/src/re.ts === +export { make } from "../../shared/lib/index"; +>make : () => import("../../shared/lib/index").T + +=== /project/app/src/a.ts === +import { make } from "./re"; +>make : () => import("../../shared/lib/index.js").T + +export const v = make(); +>v : import("../../shared/lib/index").T +>make() : import("../../shared/lib/index").T +>make : () => import("../../shared/lib/index").T + +=== /project/shared/lib/index.ts === +export interface T { v: number } +>v : number + +export function make(): T { return { v: 1 }; } +>make : () => T +>{ v: 1 } : { v: number; } +>v : number +>1 : 1 + diff --git a/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js new file mode 100644 index 0000000000000..8609aacf16373 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/mapRootRelativeCaret.ts] //// + +//// [a.ts] +export const a = 1; + + +//// [a.js] +export const a = 1; +//# sourceMappingURL=%5E/a.js.map \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js.map b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js.map new file mode 100644 index 0000000000000..33a2c7106c31d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.js.map @@ -0,0 +1,2 @@ +//// [a.js.map] +{"version":3,"file":"a.js","sources":["../a.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.sourcemap.txt b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.sourcemap.txt new file mode 100644 index 0000000000000..0f257618ece5c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.sourcemap.txt @@ -0,0 +1,38 @@ +=================================================================== +JsFile: a.js +mapUrl: %5E/a.js.map +sourceRoot: +sources: ../a.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/proj/a.js +sourceFile:../a.ts +------------------------------------------------------------------- +>>>export const a = 1; +1 > +2 >^^^^^^ +3 > ^ +4 > ^^^^^^ +5 > ^ +6 > ^^^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^-> +1 > +2 >export +3 > +4 > const +5 > a +6 > = +7 > 1 +8 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 7) Source(1, 7) + SourceIndex(0) +3 >Emitted(1, 8) Source(1, 8) + SourceIndex(0) +4 >Emitted(1, 14) Source(1, 14) + SourceIndex(0) +5 >Emitted(1, 15) Source(1, 15) + SourceIndex(0) +6 >Emitted(1, 18) Source(1, 18) + SourceIndex(0) +7 >Emitted(1, 19) Source(1, 19) + SourceIndex(0) +8 >Emitted(1, 20) Source(1, 20) + SourceIndex(0) +--- +>>>//# sourceMappingURL=%5E/a.js.map \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.symbols b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.symbols new file mode 100644 index 0000000000000..b00c76e105d76 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.symbols @@ -0,0 +1,6 @@ +//// [tests/cases/compiler/mapRootRelativeCaret.ts] //// + +=== /proj/a.ts === +export const a = 1; +>a : Symbol(a, Decl(a.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.types b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.types new file mode 100644 index 0000000000000..bd75ef0692bfe --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootRelativeCaret.types @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/mapRootRelativeCaret.ts] //// + +=== /proj/a.ts === +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js new file mode 100644 index 0000000000000..c0ab976a1ff2d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/mapRootUrlWithDotDotSegment.ts] //// + +//// [a.ts] +export const a = 1; + + +//// [a.js] +export const a = 1; +//# sourceMappingURL=https://example.com/m/a.js.map \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js.map b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js.map new file mode 100644 index 0000000000000..73e347a4465df --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.js.map @@ -0,0 +1,2 @@ +//// [a.js.map] +{"version":3,"file":"a.js","sources":["file:///a.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.sourcemap.txt b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.sourcemap.txt new file mode 100644 index 0000000000000..6c65d1982c186 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.sourcemap.txt @@ -0,0 +1,38 @@ +=================================================================== +JsFile: a.js +mapUrl: https://example.com/m/a.js.map +sourceRoot: +sources: file:///a.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/a.js +sourceFile:file:///a.ts +------------------------------------------------------------------- +>>>export const a = 1; +1 > +2 >^^^^^^ +3 > ^ +4 > ^^^^^^ +5 > ^ +6 > ^^^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >export +3 > +4 > const +5 > a +6 > = +7 > 1 +8 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 7) Source(1, 7) + SourceIndex(0) +3 >Emitted(1, 8) Source(1, 8) + SourceIndex(0) +4 >Emitted(1, 14) Source(1, 14) + SourceIndex(0) +5 >Emitted(1, 15) Source(1, 15) + SourceIndex(0) +6 >Emitted(1, 18) Source(1, 18) + SourceIndex(0) +7 >Emitted(1, 19) Source(1, 19) + SourceIndex(0) +8 >Emitted(1, 20) Source(1, 20) + SourceIndex(0) +--- +>>>//# sourceMappingURL=https://example.com/m/a.js.map \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.symbols b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.symbols new file mode 100644 index 0000000000000..00f288d635678 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.symbols @@ -0,0 +1,6 @@ +//// [tests/cases/compiler/mapRootUrlWithDotDotSegment.ts] //// + +=== /a.ts === +export const a = 1; +>a : Symbol(a, Decl(a.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.types b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.types new file mode 100644 index 0000000000000..b39051ef4c854 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/mapRootUrlWithDotDotSegment.types @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/mapRootUrlWithDotDotSegment.ts] //// + +=== /a.ts === +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.errors.txt b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.errors.txt new file mode 100644 index 0000000000000..cae63d19e40b4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.errors.txt @@ -0,0 +1,18 @@ +/a.ts(1,25): error TS2305: Module '"lib/"' has no exported member 'fromFile'. + + +==== /a.ts (1 errors) ==== + import { fromDirectory, fromFile } from "lib/"; + ~~~~~~~~ +!!! error TS2305: Module '"lib/"' has no exported member 'fromFile'. + export const values = [fromDirectory, fromFile]; + +==== /types/lib.d.ts (0 errors) ==== + export declare const fromFile: number; + +==== /types/lib/.d.ts (0 errors) ==== + export declare const fromFile: number; + +==== /types/lib/index.d.ts (0 errors) ==== + export declare const fromDirectory: number; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.js b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.js new file mode 100644 index 0000000000000..c0f708e4f2c61 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts] //// + +//// [lib.d.ts] +export declare const fromFile: number; + +//// [.d.ts] +export declare const fromFile: number; + +//// [index.d.ts] +export declare const fromDirectory: number; + +//// [a.ts] +import { fromDirectory, fromFile } from "lib/"; +export const values = [fromDirectory, fromFile]; + + +//// [a.js] +import { fromDirectory, fromFile } from "lib/"; +export const values = [fromDirectory, fromFile]; diff --git a/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.symbols b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.symbols new file mode 100644 index 0000000000000..0c47636e43e4b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts] //// + +=== /a.ts === +import { fromDirectory, fromFile } from "lib/"; +>fromDirectory : Symbol(fromDirectory, Decl(a.ts, 0, 8)) +>fromFile : Symbol(fromFile, Decl(a.ts, 0, 23)) + +export const values = [fromDirectory, fromFile]; +>values : Symbol(values, Decl(a.ts, 1, 12)) +>fromDirectory : Symbol(fromDirectory, Decl(a.ts, 0, 8)) +>fromFile : Symbol(fromFile, Decl(a.ts, 0, 23)) + +=== /types/lib/index.d.ts === +export declare const fromDirectory: number; +>fromDirectory : Symbol(fromDirectory, Decl(index.d.ts, 0, 20)) + diff --git a/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.trace.json b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.trace.json new file mode 100644 index 0000000000000..7f4e539857fd2 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.trace.json @@ -0,0 +1,12 @@ +======== Resolving module 'lib/' from '/a.ts'. ======== +Explicitly specified module resolution kind: 'Bundler'. +Resolving in CJS mode with conditions 'import', 'types'. +File '/package.json' does not exist. +Loading module 'lib/' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON. +Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration. +Directory '/node_modules' does not exist, skipping all lookups in it. +Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON. +Directory '/node_modules' does not exist, skipping all lookups in it. +File '/types/lib/package.json' does not exist. +File '/types/lib/index.d.ts' exists - use it as a name resolution result. +======== Module name 'lib/' was successfully resolved to '/types/lib/index.d.ts'. ======== diff --git a/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.types b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.types new file mode 100644 index 0000000000000..7665bf4fc8dbe --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.types @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts] //// + +=== /a.ts === +import { fromDirectory, fromFile } from "lib/"; +>fromDirectory : number +>fromFile : any + +export const values = [fromDirectory, fromFile]; +>values : any[] +>[fromDirectory, fromFile] : any[] +>fromDirectory : number +>fromFile : any + +=== /types/lib/index.d.ts === +export declare const fromDirectory: number; +>fromDirectory : number + diff --git a/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.symbols b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.symbols new file mode 100644 index 0000000000000..dc61db8c7fcad --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.ts] //// + +=== /a.ts === +import { w } from "me/lib"; +>w : Symbol(w, Decl(a.ts, 0, 8)) + +w; +>w : Symbol(w, Decl(a.ts, 0, 8)) + +=== /lib.ts === +export const w = 1; +>w : Symbol(w, Decl(lib.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.types b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.types new file mode 100644 index 0000000000000..cc1b73f4af1df --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.types @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.ts] //// + +=== /a.ts === +import { w } from "me/lib"; +>w : 1 + +w; +>w : 1 + +=== /lib.ts === +export const w = 1; +>w : 1 +>1 : 1 + diff --git a/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.errors.txt b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.errors.txt new file mode 100644 index 0000000000000..5e44c0738aafc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.errors.txt @@ -0,0 +1,15 @@ +/src/a.ts(2,7): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== /src/a.ts (1 errors) ==== + import { x } from "pkg/x"; + const n: number = x; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + +==== /package.json (0 errors) ==== + { "name": "pkg", "version": "1.0.0", "type": "module", "exports": { "./x": "./dist/^/x.js" } } + +==== /src/^/x.ts (0 errors) ==== + export const x = "s"; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.symbols b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.symbols new file mode 100644 index 0000000000000..9794ce5d065fc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.symbols @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.ts] //// + +=== /src/a.ts === +import { x } from "pkg/x"; +>x : Symbol(x, Decl(a.ts, 0, 8)) + +const n: number = x; +>n : Symbol(n, Decl(a.ts, 1, 5)) +>x : Symbol(x, Decl(a.ts, 0, 8)) + +=== /src/^/x.ts === +export const x = "s"; +>x : Symbol(x, Decl(x.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.types b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.types new file mode 100644 index 0000000000000..fb304f9be673e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.types @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.ts] //// + +=== /src/a.ts === +import { x } from "pkg/x"; +>x : "s" + +const n: number = x; +>n : number +>x : "s" + +=== /src/^/x.ts === +export const x = "s"; +>x : "s" +>"s" : "s" + diff --git a/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.errors.txt b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.errors.txt new file mode 100644 index 0000000000000..a5734287497fd --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.errors.txt @@ -0,0 +1,15 @@ +/index.ts(1,20): error TS2307: Cannot find module '#js/' or its corresponding type declarations. + + +==== /index.ts (1 errors) ==== + import * as b from "#js/"; + ~~~~~~ +!!! error TS2307: Cannot find module '#js/' or its corresponding type declarations. + export { b }; + +==== /package.json (0 errors) ==== + { "name": "pkg", "type": "module", "imports": { "#js/": "./dist.js/" } } + +==== /dist.ts (0 errors) ==== + export const k = 3; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.symbols b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.symbols new file mode 100644 index 0000000000000..c5223eff94a02 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.symbols @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/packageJsonImportsDirectoryOnlyTarget.ts] //// + +=== /index.ts === +import * as b from "#js/"; +>b : Symbol(b, Decl(index.ts, 0, 6)) + +export { b }; +>b : Symbol(b, Decl(index.ts, 1, 8)) + diff --git a/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.trace.json b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.trace.json new file mode 100644 index 0000000000000..23c0be289135e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.trace.json @@ -0,0 +1,13 @@ +======== Resolving module '#js/' from '/index.ts'. ======== +Module resolution kind is not specified, using 'NodeNext'. +Resolving in ESM mode with conditions 'import', 'types', 'node'. +Found 'package.json' at '/package.json'. +Using 'imports' subpath '#js/' with target './dist.js/'. +Import specifier '#js/' does not exist in package.json scope at path '/'. +File '/package.json' exists according to earlier cached lookups. +Loading module '#js/' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON. +Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration. +Directory '/node_modules' does not exist, skipping all lookups in it. +Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON. +Directory '/node_modules' does not exist, skipping all lookups in it. +======== Module name '#js/' was not resolved. ======== diff --git a/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.types b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.types new file mode 100644 index 0000000000000..292b3729b0da9 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/packageJsonImportsDirectoryOnlyTarget.types @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/packageJsonImportsDirectoryOnlyTarget.ts] //// + +=== /index.ts === +import * as b from "#js/"; +>b : any + +export { b }; +>b : any + diff --git a/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.errors.txt b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.errors.txt new file mode 100644 index 0000000000000..905a7b438f759 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.errors.txt @@ -0,0 +1,14 @@ +error TS6059: File '/proj/SRC/b.ts' is not under 'rootDir' '/proj/src'. 'rootDir' is expected to contain all source files. + The file is in the program because: + Root file specified for compilation + + +!!! error TS6059: File '/proj/SRC/b.ts' is not under 'rootDir' '/proj/src'. 'rootDir' is expected to contain all source files. +!!! error TS6059: The file is in the program because: +!!! error TS6059: Root file specified for compilation +==== /proj/src/a.ts (0 errors) ==== + export const a = 1; + +==== /proj/SRC/b.ts (0 errors) ==== + export const b = 2; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.js b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.js new file mode 100644 index 0000000000000..2ad6330e8c6c6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts] //// + +//// [a.ts] +export const a = 1; + +//// [b.ts] +export const b = 2; + + +//// [a.js] +export const a = 1; +//// [b.js] +export const b = 2; diff --git a/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.symbols b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.symbols new file mode 100644 index 0000000000000..6ccf221069810 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts] //// + +=== /proj/src/a.ts === +export const a = 1; +>a : Symbol(a, Decl(a.ts, 0, 12)) + +=== /proj/SRC/b.ts === +export const b = 2; +>b : Symbol(b, Decl(b.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.types b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.types new file mode 100644 index 0000000000000..4070ac8ff662b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/rootDirWithCaseSensitiveFileNames.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts] //// + +=== /proj/src/a.ts === +export const a = 1; +>a : 1 +>1 : 1 + +=== /proj/SRC/b.ts === +export const b = 2; +>b : 2 +>2 : 2 + diff --git a/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.errors.txt b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.errors.txt new file mode 100644 index 0000000000000..e3a7362e4ca61 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.errors.txt @@ -0,0 +1,9 @@ +/a.ts(1,22): error TS1006: A file cannot have a reference to itself. + + +==== /a.ts (1 errors) ==== + /// + ~ +!!! error TS1006: A file cannot have a reference to itself. + export const a = 1; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.js b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.js new file mode 100644 index 0000000000000..affa00951d0eb --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.js @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/selfReferencingFileWithoutExtension.ts] //// + +//// [a.ts] +/// +export const a = 1; + + +//// [a.js] +/// +export const a = 1; diff --git a/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.symbols b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.symbols new file mode 100644 index 0000000000000..74cbcd239ceff --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.symbols @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/selfReferencingFileWithoutExtension.ts] //// + +=== /a.ts === +/// +export const a = 1; +>a : Symbol(a, Decl(a.ts, 1, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.types b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.types new file mode 100644 index 0000000000000..43fd0facacae6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/selfReferencingFileWithoutExtension.types @@ -0,0 +1,8 @@ +//// [tests/cases/compiler/selfReferencingFileWithoutExtension.ts] //// + +=== /a.ts === +/// +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.errors.txt b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.errors.txt new file mode 100644 index 0000000000000..461b7404d6d72 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.errors.txt @@ -0,0 +1,13 @@ +/a.ts(1,22): error TS6231: Could not resolve the path 'C:' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. +/a.ts(2,22): error TS6231: Could not resolve the path 'c:' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. + + +==== /a.ts (2 errors) ==== + /// + ~~ +!!! error TS6231: Could not resolve the path 'C:' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. + /// + ~~ +!!! error TS6231: Could not resolve the path 'c:' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. + export {}; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.js b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.js new file mode 100644 index 0000000000000..080ac73603bd1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.js @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/tripleSlashReferenceDriveRoot.ts] //// + +//// [a.ts] +/// +/// +export {}; + + +//// [a.js] +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.symbols b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.symbols new file mode 100644 index 0000000000000..9f5772e3d84a6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.symbols @@ -0,0 +1,8 @@ +//// [tests/cases/compiler/tripleSlashReferenceDriveRoot.ts] //// + +=== /a.ts === + +/// +/// +export {}; + diff --git a/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.types b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.types new file mode 100644 index 0000000000000..9f5772e3d84a6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tripleSlashReferenceDriveRoot.types @@ -0,0 +1,8 @@ +//// [tests/cases/compiler/tripleSlashReferenceDriveRoot.ts] //// + +=== /a.ts === + +/// +/// +export {}; + diff --git a/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.errors.txt b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.errors.txt new file mode 100644 index 0000000000000..d7b7e6e6fafd8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.errors.txt @@ -0,0 +1,22 @@ +/shared/a.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'. +/shared/sub/b.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== /proj/tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "noEmit": true + }, + "include": ["/shared/sub/.."] + } + +==== /shared/a.ts (1 errors) ==== + export const a: number = "s"; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + +==== /shared/sub/b.ts (1 errors) ==== + export const b: number = "s"; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.symbols b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.symbols new file mode 100644 index 0000000000000..b7c7871cda852 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/tsconfigIncludeAbsolutePathWithDotDot.ts] //// + +=== /shared/a.ts === +export const a: number = "s"; +>a : Symbol(a, Decl(a.ts, 0, 12)) + +=== /shared/sub/b.ts === +export const b: number = "s"; +>b : Symbol(b, Decl(b.ts, 0, 12)) + diff --git a/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.types b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.types new file mode 100644 index 0000000000000..3edd760fcdb3c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/tsconfigIncludeAbsolutePathWithDotDot.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/tsconfigIncludeAbsolutePathWithDotDot.ts] //// + +=== /shared/a.ts === +export const a: number = "s"; +>a : number +>"s" : "s" + +=== /shared/sub/b.ts === +export const b: number = "s"; +>b : number +>"s" : "s" + diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.errors.txt b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.errors.txt new file mode 100644 index 0000000000000..0c5987f014968 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.errors.txt @@ -0,0 +1,12 @@ +/a.ts(1,23): error TS2688: Cannot find type definition file for 'C:'. + + +==== /a.ts (1 errors) ==== + /// + ~~ +!!! error TS2688: Cannot find type definition file for 'C:'. + export {}; + +==== /types/README.md (0 errors) ==== + The type root. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.js b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.js new file mode 100644 index 0000000000000..4b690f73f126c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts] //// + +//// [README.md] +The type root. + +//// [a.ts] +/// +export {}; + + +//// [a.js] +export {}; diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.symbols b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.symbols new file mode 100644 index 0000000000000..c93eb9ee1f8c7 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.symbols @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts] //// + +=== /a.ts === + +/// +export {}; + diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.trace.json b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.trace.json new file mode 100644 index 0000000000000..b46ec72a58405 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.trace.json @@ -0,0 +1,6 @@ +======== Resolving type reference directive 'C:', containing file '/a.ts', root directory '/types'. ======== +Resolving with primary search path '/types'. +Looking up in 'node_modules' folder, initial location '/'. +Loading module as file / folder, candidate module location 'C:/', target file types: Declaration. +Directory 'C:/' does not exist, skipping all lookups in it. +======== Type reference directive 'C:' was not resolved. ======== diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.types b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.types new file mode 100644 index 0000000000000..c93eb9ee1f8c7 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveDriveRoot.types @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts] //// + +=== /a.ts === + +/// +export {}; + diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.errors.txt b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.errors.txt new file mode 100644 index 0000000000000..5f5a6d4953cf4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.errors.txt @@ -0,0 +1,22 @@ +/app/src/a.ts(3,1): error TS2304: Cannot find name 'fromFile'. + + +==== /app/src/a.ts (1 errors) ==== + /// + fromDirectory; + fromFile; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'fromFile'. + +==== /types/README.md (0 errors) ==== + The type root. + +==== /pkg.d.ts (0 errors) ==== + declare const fromFile: number; + +==== /pkg/.d.ts (0 errors) ==== + declare const fromFile: number; + +==== /pkg/index.d.ts (0 errors) ==== + declare const fromDirectory: number; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.js b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.js new file mode 100644 index 0000000000000..ed7a8405f9e3a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts] //// + +//// [README.md] +The type root. + +//// [pkg.d.ts] +declare const fromFile: number; + +//// [.d.ts] +declare const fromFile: number; + +//// [index.d.ts] +declare const fromDirectory: number; + +//// [a.ts] +/// +fromDirectory; +fromFile; + + +//// [a.js] +"use strict"; +/// +fromDirectory; +fromFile; diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.symbols b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.symbols new file mode 100644 index 0000000000000..163ac84a99140 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts] //// + +=== /app/src/a.ts === +/// +fromDirectory; +>fromDirectory : Symbol(fromDirectory, Decl(index.d.ts, 0, 13)) + +fromFile; + +=== /pkg/index.d.ts === +declare const fromDirectory: number; +>fromDirectory : Symbol(fromDirectory, Decl(index.d.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.trace.json b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.trace.json new file mode 100644 index 0000000000000..b792bbc186ec2 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.trace.json @@ -0,0 +1,6 @@ +======== Resolving type reference directive '../pkg/', containing file '/app/src/a.ts', root directory '/types'. ======== +Resolving with primary search path '/types'. +File '/pkg/package.json' does not exist. +File '/pkg/index.d.ts' exists - use it as a name resolution result. +Resolving real path for '/pkg/index.d.ts', result '/pkg/index.d.ts'. +======== Type reference directive '../pkg/' was successfully resolved to '/pkg/index.d.ts', primary: true. ======== diff --git a/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.types b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.types new file mode 100644 index 0000000000000..29536446acd7c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveTrailingSlashRelativeName.types @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts] //// + +=== /app/src/a.ts === +/// +fromDirectory; +>fromDirectory : number + +fromFile; +>fromFile : any + +=== /pkg/index.d.ts === +declare const fromDirectory: number; +>fromDirectory : number + diff --git a/tsc/testdata/baselines/reference/tsbuild/configFileErrors/reports-no-inputs-found.js b/tsc/testdata/baselines/reference/tsbuild/configFileErrors/reports-no-inputs-found.js new file mode 100644 index 0000000000000..db7eededc9bc8 --- /dev/null +++ b/tsc/testdata/baselines/reference/tsbuild/configFileErrors/reports-no-inputs-found.js @@ -0,0 +1,26 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ "include": ["missing.ts"] } + +tsc --b +ExitStatus:: DiagnosticsPresent_OutputsGenerated +Output:: +error TS18003: No inputs were found in config file '/home/src/workspaces/project/tsconfig.json'. Specified 'include' paths were '["missing.ts"]' and 'exclude' paths were '[]'. + +Found 1 error. + +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new* +{"version":"FakeTSVersion","errors":true,"root":[]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* +{ + "version": "FakeTSVersion", + "errors": true, + "root": [], + "size": 51 +} + +tsconfig.json:: +SemanticDiagnostics:: +Signatures:: diff --git a/tsc/testdata/baselines/reference/tsc/commandLine/Parse--p-with-path-to-subfolder-that-has-only-declaration-files-and-outDir.js b/tsc/testdata/baselines/reference/tsc/commandLine/Parse--p-with-path-to-subfolder-that-has-only-declaration-files-and-outDir.js new file mode 100644 index 0000000000000..408e327c78b2f --- /dev/null +++ b/tsc/testdata/baselines/reference/tsc/commandLine/Parse--p-with-path-to-subfolder-that-has-only-declaration-files-and-outDir.js @@ -0,0 +1,63 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/sub/a.d.ts] *new* +declare const x: number; +//// [/home/src/workspaces/project/sub/tsconfig.json] *new* +{ "compilerOptions": { "outDir": "../out" } } + +tsc -p sub +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; + + + +Edit [0]:: build with -b + +tsc -b sub +ExitStatus:: Success +Output:: +//// [/home/src/workspaces/project/out/tsconfig.tsbuildinfo] *new* +{"version":"FakeTSVersion","root":["../sub/a.d.ts"]} +//// [/home/src/workspaces/project/out/tsconfig.tsbuildinfo.readable.baseline.txt] *new* +{ + "version": "FakeTSVersion", + "root": [ + { + "files": [ + "../sub/a.d.ts" + ], + "original": "../sub/a.d.ts" + } + ], + "size": 52 +} + +sub/tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/sub/a.d.ts +Signatures:: diff --git a/tsc/testdata/baselines/reference/tsc/commandLine/rooted-file-names-in-tsconfig-do-not-exist.js b/tsc/testdata/baselines/reference/tsc/commandLine/rooted-file-names-in-tsconfig-do-not-exist.js new file mode 100644 index 0000000000000..3f11cb53227e3 --- /dev/null +++ b/tsc/testdata/baselines/reference/tsc/commandLine/rooted-file-names-in-tsconfig-do-not-exist.js @@ -0,0 +1,52 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "files": ["/x/", "C:"] + } + +tsc -p ./tsconfig.json +ExitStatus:: DiagnosticsPresent_OutputsGenerated +Output:: +error TS6231: Could not resolve the path '/x' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. + The file is in the program because: + Part of 'files' list in tsconfig.json + tsconfig.json:2:31 - File is matched by 'files' list specified here. + 2 "files": ["/x/", "C:"] +    ~~~~~ + +error TS6231: Could not resolve the path 'C:/' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'. + The file is in the program because: + Part of 'files' list in tsconfig.json + tsconfig.json:2:38 - File is matched by 'files' list specified here. + 2 "files": ["/x/", "C:"] +    ~~~~ + + +Found 2 errors. + +//// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; + diff --git a/tsc/testdata/baselines/reference/tsc/incremental/tsbuildinfo-has-tuple-of-wrong-length.js b/tsc/testdata/baselines/reference/tsc/incremental/tsbuildinfo-has-tuple-of-wrong-length.js new file mode 100644 index 0000000000000..23966601d10cc --- /dev/null +++ b/tsc/testdata/baselines/reference/tsc/incremental/tsbuildinfo-has-tuple-of-wrong-length.js @@ -0,0 +1,194 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/a.ts] *new* +import { b } from "./b"; export const a = b + 1; +//// [/home/src/workspaces/project/b.ts] *new* +export const b = 2; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{} + +tsc -i +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/a.js] *new* +import { b } from "./b"; +export const a = b + 1; + +//// [/home/src/workspaces/project/b.js] *new* +export const b = 2; + +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* +{ + "version": "FakeTSVersion", + "root": [ + { + "files": [ + "./b.ts", + "./a.ts" + ], + "original": [ + 2, + 3 + ] + } + ], + "fileNames": [ + "lib.es2026.full.d.ts", + "./b.ts", + "./a.ts" + ], + "fileInfos": [ + { + "fileName": "lib.es2026.full.d.ts", + "version": "8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", + "signature": "8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedNodeFormat": "CommonJS", + "original": { + "version": "8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedNodeFormat": 1 + } + }, + { + "fileName": "./b.ts", + "version": "a8da94c0a8fada72e123de05c6818d3a-export const b = 2;", + "signature": "a8da94c0a8fada72e123de05c6818d3a-export const b = 2;", + "impliedNodeFormat": "CommonJS" + }, + { + "fileName": "./a.ts", + "version": "0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;", + "signature": "0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;", + "impliedNodeFormat": "CommonJS" + } + ], + "fileIdsList": [ + [ + "./b.ts" + ] + ], + "referencedMap": { + "./a.ts": [ + "./b.ts" + ] + }, + "size": 1066 +} + +tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts +Signatures:: + + +Edit [0]:: referencedMap entry with one element +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3]]} + +tsc -i +ExitStatus:: Success +Output:: +//// [/home/src/workspaces/project/a.js] *rewrite with same content* +//// [/home/src/workspaces/project/b.js] *rewrite with same content* +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content* + +tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts +Signatures:: + + +Edit [1]:: referencedMap entry with three elements +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1,2]]} + +tsc -i +ExitStatus:: Success +Output:: +//// [/home/src/workspaces/project/a.js] *rewrite with same content* +//// [/home/src/workspaces/project/b.js] *rewrite with same content* +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content* + +tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts +Signatures:: + + +Edit [2]:: root entry with three elements +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[1,2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} + +tsc -i +ExitStatus:: Success +Output:: +//// [/home/src/workspaces/project/a.js] *rewrite with same content* +//// [/home/src/workspaces/project/b.js] *rewrite with same content* +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content* + +tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts +Signatures:: + + +Edit [3]:: root entry with no elements +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} + +tsc -i +ExitStatus:: Success +Output:: +//// [/home/src/workspaces/project/a.js] *rewrite with same content* +//// [/home/src/workspaces/project/b.js] *rewrite with same content* +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* +{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.es2026.full.d.ts","./b.ts","./a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"a8da94c0a8fada72e123de05c6818d3a-export const b = 2;","0d53a6017a0f7fb1b7cf6c2aaa5b04c7-import { b } from \"./b\"; export const a = b + 1;"],"fileIdsList":[[2]],"referencedMap":[[3,1]]} +//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content* + +tsconfig.json:: +SemanticDiagnostics:: +*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts +*refresh* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts +Signatures:: diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts b/tsc/testdata/tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts new file mode 100644 index 0000000000000..3167a3106a481 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/declarationEmitExportsPatternTargetTrailingSlash.ts @@ -0,0 +1,24 @@ +// @declaration: true +// @noImplicitReferences: true + +// The "exports" pattern target of "pkg" ends with "/", so it names +// directories. It does not match the file "/node_modules/pkg/dist/foo.d.ts". +// Declaration emit does not use "pkg/foo.js" to name the type of "v", and +// reports an error. + +// @filename: /node_modules/pkg/package.json +{ "name": "pkg", "exports": { "./*": "./dist/*/" } } + +// @filename: /node_modules/pkg/dist/foo.d.ts +export interface L { x: number } + +// @filename: /node_modules/dep/package.json +{ "name": "dep" } + +// @filename: /node_modules/dep/index.d.ts +import type { L } from "../pkg/dist/foo"; +export declare function make(): L; + +// @filename: /src/main.ts +import { make } from "dep"; +export const v = make(); diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts b/tsc/testdata/tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts new file mode 100644 index 0000000000000..de29baf01a7d0 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/declarationEmitExportsTargetTrailingSlash.ts @@ -0,0 +1,23 @@ +// @declaration: true +// @noImplicitReferences: true + +// The "exports" target of "pkg" ends with "/", so it names a directory. It +// does not match the file "/node_modules/pkg/index.d.ts". Declaration emit +// does not use "pkg" to name the type of "v", and reports an error. + +// @filename: /node_modules/pkg/package.json +{ "name": "pkg", "exports": { ".": "./index.js/" } } + +// @filename: /node_modules/pkg/index.d.ts +export interface L { x: number } + +// @filename: /node_modules/dep/package.json +{ "name": "dep" } + +// @filename: /node_modules/dep/index.d.ts +import type { L } from "../pkg/index"; +export declare function make(): L; + +// @filename: /src/main.ts +import { make } from "dep"; +export const v = make(); diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts b/tsc/testdata/tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts new file mode 100644 index 0000000000000..5112256c7e665 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/declarationEmitIndexDirectoryOutsideImportingDirectory.ts @@ -0,0 +1,28 @@ +// The type of "v" comes from "/project/shared/lib/index.ts". The file +// "/project/shared/lib.ts" is not in the program, but it is next to the "lib" +// directory. So the specifier "../../shared/lib" would name "lib.ts", not +// "lib/index.ts". Declaration emit keeps "/index" in the specifier, although +// the target is outside the directory of "a.ts". + +// @filename: /project/tsconfig.json +{ + "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true + }, + "include": ["app/src"] +} + +// @filename: /project/shared/lib/index.ts +export interface T { v: number } +export function make(): T { return { v: 1 }; } + +// @filename: /project/shared/lib.ts +export const other = 1; + +// @filename: /project/app/src/re.ts +export { make } from "../../shared/lib/index"; + +// @filename: /project/app/src/a.ts +import { make } from "./re"; +export const v = make(); diff --git a/tsc/testdata/tests/cases/compiler/mapRootRelativeCaret.ts b/tsc/testdata/tests/cases/compiler/mapRootRelativeCaret.ts new file mode 100644 index 0000000000000..f6dbfe2ae2f50 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/mapRootRelativeCaret.ts @@ -0,0 +1,12 @@ +// @sourceMap: true +// @mapRoot: ^ +// @currentDirectory: / + +// The "mapRoot" value "^" is a relative path, not a root. The compiler +// resolves it against the common source directory "/proj", not against the +// current directory "/". So the map directory is "/proj/^". The +// "sourceMappingURL" comment is "%5E/a.js.map", and the map lists the source +// as "../a.ts". + +// @filename: /proj/a.ts +export const a = 1; diff --git a/tsc/testdata/tests/cases/compiler/mapRootUrlWithDotDotSegment.ts b/tsc/testdata/tests/cases/compiler/mapRootUrlWithDotDotSegment.ts new file mode 100644 index 0000000000000..e18cca033f957 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/mapRootUrlWithDotDotSegment.ts @@ -0,0 +1,9 @@ +// @sourceMap: true +// @mapRoot: https://example.com/a/../m + +// The "mapRoot" value is a URL with a ".." segment. The compiler normalizes +// the value, so the "sourceMappingURL" comment is +// "https://example.com/m/a.js.map". + +// @filename: /a.ts +export const a = 1; diff --git a/tsc/testdata/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts b/tsc/testdata/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts new file mode 100644 index 0000000000000..7a784ecf1d873 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveTrailingSlash.ts @@ -0,0 +1,25 @@ +// @module: esnext +// @moduleResolution: bundler +// @noImplicitReferences: true +// @typeRoots: /types +// @traceResolution: true +// @currentDirectory: / + +// The module name "lib/" ends with a separator, so it names a directory. The +// lookup in "node_modules" fails, and the resolver then looks in the type root +// "/types". It skips the file lookup, so it does not use "/types/lib.d.ts" or +// "/types/lib/.d.ts". It uses "/types/lib/index.d.ts", so "fromFile" is an +// error. + +// @filename: /types/lib.d.ts +export declare const fromFile: number; + +// @filename: /types/lib/.d.ts +export declare const fromFile: number; + +// @filename: /types/lib/index.d.ts +export declare const fromDirectory: number; + +// @filename: /a.ts +import { fromDirectory, fromFile } from "lib/"; +export const values = [fromDirectory, fromFile]; diff --git a/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.ts b/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.ts new file mode 100644 index 0000000000000..2c7408b91730b --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirAtRoot.ts @@ -0,0 +1,19 @@ +// @module: nodenext +// @outDir: / +// @rootDir: / +// @noEmit: true +// @noImplicitReferences: true + +// The output directory and the root directory are both "/". The self-name +// import "me/lib" maps to "./lib.d.ts" in the output directory. The resolver +// maps this path back to the input file "/lib.ts", so the import has no error. + +// @filename: /package.json +{ "name": "me", "exports": { "./lib": "./lib.d.ts" } } + +// @filename: /lib.ts +export const w = 1; + +// @filename: /a.ts +import { w } from "me/lib"; +w; diff --git a/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.ts b/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.ts new file mode 100644 index 0000000000000..c76f005c1ba33 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirRootDirCaretDirectory.ts @@ -0,0 +1,20 @@ +// @module: nodenext +// @outDir: /dist +// @rootDir: /src +// @noEmit: true +// @noImplicitReferences: true + +// The self-name import "pkg/x" maps to "./dist/^/x.js" in the output +// directory. The resolver maps this path back to the input file +// "/src/^/x.ts". It reads "^" as a directory name, not as a root. The import +// resolves. "x" is a string, so assigning it to "n" (a number) is an error. + +// @filename: /package.json +{ "name": "pkg", "version": "1.0.0", "type": "module", "exports": { "./x": "./dist/^/x.js" } } + +// @filename: /src/^/x.ts +export const x = "s"; + +// @filename: /src/a.ts +import { x } from "pkg/x"; +const n: number = x; diff --git a/tsc/testdata/tests/cases/compiler/packageJsonImportsDirectoryOnlyTarget.ts b/tsc/testdata/tests/cases/compiler/packageJsonImportsDirectoryOnlyTarget.ts new file mode 100644 index 0000000000000..015ace41caf96 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/packageJsonImportsDirectoryOnlyTarget.ts @@ -0,0 +1,18 @@ +// @module: nodenext +// @noEmit: true +// @noImplicitReferences: true +// @traceResolution: true + +// The "imports" target "./dist.js/" ends with "/", so it names a directory. +// The resolver does not look up the file "/dist.ts" for it, and "#js/" does +// not resolve. + +// @filename: /package.json +{ "name": "pkg", "type": "module", "imports": { "#js/": "./dist.js/" } } + +// @filename: /dist.ts +export const k = 3; + +// @filename: /index.ts +import * as b from "#js/"; +export { b }; diff --git a/tsc/testdata/tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts b/tsc/testdata/tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts new file mode 100644 index 0000000000000..76a708e520685 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/rootDirWithCaseSensitiveFileNames.ts @@ -0,0 +1,13 @@ +// @useCaseSensitiveFileNames: true +// @rootDir: /proj/src +// @outDir: /proj/out + +// The file system is case sensitive, so "/proj/SRC" and "/proj/src" are +// different directories. "/proj/SRC/b.ts" is not under "rootDir", and the +// compiler reports an error for it. + +// @filename: /proj/src/a.ts +export const a = 1; + +// @filename: /proj/SRC/b.ts +export const b = 2; diff --git a/tsc/testdata/tests/cases/compiler/selfReferencingFileWithoutExtension.ts b/tsc/testdata/tests/cases/compiler/selfReferencingFileWithoutExtension.ts new file mode 100644 index 0000000000000..dde4726da2cc8 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/selfReferencingFileWithoutExtension.ts @@ -0,0 +1,7 @@ +// The reference path "a" has no extension. The file loader adds ".ts" and +// finds "/a.ts", the file that has the reference. So the file has a reference +// to itself. + +// @filename: /a.ts +/// +export const a = 1; diff --git a/tsc/testdata/tests/cases/compiler/tripleSlashReferenceDriveRoot.ts b/tsc/testdata/tests/cases/compiler/tripleSlashReferenceDriveRoot.ts new file mode 100644 index 0000000000000..d618d61efd9ae --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/tripleSlashReferenceDriveRoot.ts @@ -0,0 +1,8 @@ +// tsc treats the reference paths "C:" and "c:" as the drive roots "C:/" and +// "c:/". No file has these names, so the compiler reports that it cannot +// resolve the paths. + +// @filename: /a.ts +/// +/// +export {}; diff --git a/tsc/testdata/tests/cases/compiler/tsconfigIncludeAbsolutePathWithDotDot.ts b/tsc/testdata/tests/cases/compiler/tsconfigIncludeAbsolutePathWithDotDot.ts new file mode 100644 index 0000000000000..7fad74baca73b --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/tsconfigIncludeAbsolutePathWithDotDot.ts @@ -0,0 +1,20 @@ +// @currentDirectory: /proj + +// The "include" entry is an absolute path that ends with "..". The compiler +// normalizes the entry before it takes the base directory of the search. The +// search starts in "/shared", not in "/shared/sub", so the program has both +// files. + +// @filename: /proj/tsconfig.json +{ + "compilerOptions": { + "noEmit": true + }, + "include": ["/shared/sub/.."] +} + +// @filename: /shared/a.ts +export const a: number = "s"; + +// @filename: /shared/sub/b.ts +export const b: number = "s"; diff --git a/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts b/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts new file mode 100644 index 0000000000000..9a8fe58656b4c --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveDriveRoot.ts @@ -0,0 +1,14 @@ +// @noImplicitReferences: true +// @typeRoots: /types +// @traceResolution: true +// @currentDirectory: / + +// tsc treats the name "C:" as the drive root "C:/", so the candidate is "C:/". +// No file is under "C:/", so the name is an error. + +// @filename: /types/README.md +The type root. + +// @filename: /a.ts +/// +export {}; diff --git a/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts b/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts new file mode 100644 index 0000000000000..699dd5b9ac3d6 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/typeReferenceDirectiveTrailingSlashRelativeName.ts @@ -0,0 +1,27 @@ +// @noImplicitReferences: true +// @typeRoots: /types +// @traceResolution: true +// @currentDirectory: / + +// The relative name "../pkg/" ends with a separator, so it names a directory. +// The primary lookup resolves the name from the type root "/types", not from +// "/app/src", so the candidate is "/pkg/". The lookup skips the file lookup, so +// it does not use "/pkg.d.ts" or "/pkg/.d.ts". It uses "/pkg/index.d.ts", so +// "fromFile" is an error. + +// @filename: /types/README.md +The type root. + +// @filename: /pkg.d.ts +declare const fromFile: number; + +// @filename: /pkg/.d.ts +declare const fromFile: number; + +// @filename: /pkg/index.d.ts +declare const fromDirectory: number; + +// @filename: /app/src/a.ts +/// +fromDirectory; +fromFile;