diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 9be89da690..0e084ab482 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -9,23 +9,29 @@ Most of our development takes place in the `internal` directory, and most behavi Most development on the codebase is in Go. Standard Go commands and practices apply, but we primarily use a tool called `hereby` to build, run tests, and other tasks. -Feel free to install `hereby` globally (`npm install -g hereby`) if it is easier, and run `hereby --list` to see all available commands. +Run `npx hereby --list` to see all available commands. ```sh -hereby build # Build the project -hereby test # Run tests -hereby format # Format the code -hereby lint # Run linters +npx hereby build # Build the project +npx hereby test # Run tests +npx hereby format # Format the code +npx hereby lint # Run linters + +# To run a specific compiler test: +go test -run='TestSubmodule/' ./internal/testrunner # For submodule tests in _submodules/TypeScript +go test -run='TestLocal/' ./internal/testrunner # For local tests in testdata/tests/cases ``` -Always make sure code is formatted, linted, and tested before sending a pull request. - +Always make sure code is formatted, linted, and tested before sending a pull request. + ## Compiler Features, Fixes, and Tests When fixing a bug or implementing a new feature, at least one minimal test case should always be added in advance to verify the fix. This project primarily uses snapshot/baseline/golden tests rather than unit tests. New compiler tests are written in `.ts`/`.tsx` files in the directory `testdata/tests/cases/compiler/`, and are written in the following format: +**Note:** Issues with editor features cannot be tested with compiler tests in `testdata/tests/cases/`. Editor functionality requires integration testing with the language server. + ```ts // @target: esnext // @module: preserve @@ -79,6 +85,12 @@ It is ideal to implement features and fixes in the following order, and commit c It is fine to implement more and more of a feature across commits, but be sure to update baselines every time so that reviewers can measure progress. +## Code Porting Reference + +The code in `internal` is ported from the code in `_submodules/TypeScript`. +When implementing features or fixing bugs, those files should be searched for similar functions when code is either missing or potentially wrong. +The TypeScript submodule serves as the reference implementation for behavior and functionality. + # Other Instructions - Do not add or change existing dependencies unless asked to. diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 26759ed3f1..065e58c19f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -48,7 +48,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/init@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 with: config-file: ./.github/codeql/codeql-configuration.yml # Override language selection by uncommenting this and choosing your languages @@ -58,7 +58,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below). - name: Autobuild - uses: github/codeql-action/autobuild@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/autobuild@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -72,4 +72,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0 + uses: github/codeql-action/analyze@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1 diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 1aef70e6c2..222d1f5108 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -23,8 +23,13 @@ jobs: - uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable - uses: ./.github/actions/setup-go with: + # Updated to 1.25.0-rc.1 to improve compilation time + go-version: '>=1.25.0-rc.1' cache-name: copilot-setup-steps - run: npm i -g @playwright/mcp@0.0.28 - run: npm ci # pull dprint caches before network access is blocked - run: npx hereby check:format || true + # cache build and lint operations + - run: npx hereby build || true + - run: npx hereby lint || true diff --git a/cmd/tsgo/api.go b/cmd/tsgo/api.go index 702ce143a2..9438c39115 100644 --- a/cmd/tsgo/api.go +++ b/cmd/tsgo/api.go @@ -26,7 +26,6 @@ func runAPI(args []string) int { Out: os.Stdout, Err: os.Stderr, Cwd: *cwd, - NewLine: "\n", DefaultLibraryPath: defaultLibraryPath, }) diff --git a/cmd/tsgo/sys.go b/cmd/tsgo/sys.go index cb8ce52222..cfdafdd209 100644 --- a/cmd/tsgo/sys.go +++ b/cmd/tsgo/sys.go @@ -4,11 +4,9 @@ import ( "fmt" "io" "os" - "runtime" "time" "github.com/microsoft/typescript-go/internal/bundled" - "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/execute" "github.com/microsoft/typescript-go/internal/tspath" "github.com/microsoft/typescript-go/internal/vfs" @@ -19,7 +17,6 @@ type osSys struct { writer io.Writer fs vfs.FS defaultLibraryPath string - newLine string cwd string start time.Time } @@ -44,10 +41,6 @@ func (s *osSys) GetCurrentDirectory() string { return s.cwd } -func (s *osSys) NewLine() string { - return s.newLine -} - func (s *osSys) Writer() io.Writer { return s.writer } @@ -69,7 +62,6 @@ func newSystem() *osSys { fs: bundled.WrapFS(osvfs.FS()), defaultLibraryPath: bundled.LibPath(), writer: os.Stdout, - newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"), start: time.Now(), } } diff --git a/internal/api/api.go b/internal/api/api.go index b522371125..1c71476794 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -111,11 +111,6 @@ func (api *API) Trace(s string) { api.options.Logger.Info(s) } -// NewLine implements ProjectHost. -func (api *API) NewLine() string { - return api.host.NewLine() -} - // PositionEncoding implements ProjectHost. func (api *API) PositionEncoding() lsproto.PositionEncodingKind { return lsproto.PositionEncodingKindUTF8 diff --git a/internal/api/host.go b/internal/api/host.go index 83d45a8c60..21136ac5d9 100644 --- a/internal/api/host.go +++ b/internal/api/host.go @@ -6,5 +6,4 @@ type APIHost interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string } diff --git a/internal/api/server.go b/internal/api/server.go index e6c5a6d575..afc558bd56 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -61,7 +61,6 @@ type ServerOptions struct { Out io.Writer Err io.Writer Cwd string - NewLine string DefaultLibraryPath string } @@ -98,7 +97,6 @@ func NewServer(options *ServerOptions) *Server { w: bufio.NewWriter(options.Out), stderr: options.Err, cwd: options.Cwd, - newLine: options.NewLine, fs: bundled.WrapFS(osvfs.FS()), defaultLibraryPath: options.DefaultLibraryPath, } @@ -126,11 +124,6 @@ func (s *Server) GetCurrentDirectory() string { return s.cwd } -// NewLine implements APIHost. -func (s *Server) NewLine() string { - return s.newLine -} - func (s *Server) Run() error { for { messageType, method, payload, err := s.readRequest("") diff --git a/internal/checker/checker.go b/internal/checker/checker.go index ca4dd45f4a..82516538ec 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -17879,6 +17879,7 @@ func (c *Checker) pushTypeResolution(target TypeSystemEntity, propertyName TypeS func (c *Checker) popTypeResolution() bool { lastIndex := len(c.typeResolutions) - 1 result := c.typeResolutions[lastIndex].result + c.typeResolutions[lastIndex] = TypeResolution{} // Clear the last entry to avoid memory leaks c.typeResolutions = c.typeResolutions[:lastIndex] return result } @@ -21133,6 +21134,9 @@ func (c *Checker) getDefaultOrUnknownFromTypeParameter(t *Type) *Type { } func (c *Checker) getNamedMembers(members ast.SymbolTable) []*ast.Symbol { + if len(members) == 0 { + return nil + } result := make([]*ast.Symbol, 0, len(members)) for id, symbol := range members { if c.isNamedMember(symbol, id) { @@ -29351,7 +29355,9 @@ func (c *Checker) pushContextualType(node *ast.Node, t *Type, isCache bool) { } func (c *Checker) popContextualType() { - c.contextualInfos = c.contextualInfos[:len(c.contextualInfos)-1] + lastIndex := len(c.contextualInfos) - 1 + c.contextualInfos[lastIndex] = ContextualInfo{} + c.contextualInfos = c.contextualInfos[:lastIndex] } func (c *Checker) findContextualNode(node *ast.Node, includeCaches bool) int { @@ -29421,7 +29427,9 @@ func (c *Checker) pushInferenceContext(node *ast.Node, context *InferenceContext } func (c *Checker) popInferenceContext() { - c.inferenceContextInfos = c.inferenceContextInfos[:len(c.inferenceContextInfos)-1] + lastIndex := len(c.inferenceContextInfos) - 1 + c.inferenceContextInfos[lastIndex] = InferenceContextInfo{} + c.inferenceContextInfos = c.inferenceContextInfos[:lastIndex] } func (c *Checker) getInferenceContext(node *ast.Node) *InferenceContext { diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go index 161be261eb..3034d35b5d 100644 --- a/internal/checker/checker_test.go +++ b/internal/checker/checker_test.go @@ -36,7 +36,7 @@ foo.bar;` fs = bundled.WrapFS(fs) cd := "/" - host := compiler.NewCompilerHost(nil, cd, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(cd, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil) assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line") @@ -70,7 +70,7 @@ func TestCheckSrcCompiler(t *testing.T) { rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler") - host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil) assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line") p := compiler.NewProgram(compiler.ProgramOptions{ @@ -87,7 +87,7 @@ func BenchmarkNewChecker(b *testing.B) { rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler") - host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil) assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line") p := compiler.NewProgram(compiler.ProgramOptions{ diff --git a/internal/checker/types.go b/internal/checker/types.go index 02b4a3c233..9f97173880 100644 --- a/internal/checker/types.go +++ b/internal/checker/types.go @@ -297,34 +297,6 @@ const ( AccessFlagsPersistent = AccessFlagsIncludeUndefined ) -type AssignmentDeclarationKind = int32 - -const ( - AssignmentDeclarationKindNone = AssignmentDeclarationKind(iota) - /// exports.name = expr - /// module.exports.name = expr - AssignmentDeclarationKindExportsProperty - /// module.exports = expr - AssignmentDeclarationKindModuleExports - /// className.prototype.name = expr - AssignmentDeclarationKindPrototypeProperty - /// this.name = expr - AssignmentDeclarationKindThisProperty - // F.name = expr - AssignmentDeclarationKindProperty - // F.prototype = { ... } - AssignmentDeclarationKindPrototype - // Object.defineProperty(x, 'name', { value: any, writable?: boolean (false by default) }); - // Object.defineProperty(x, 'name', { get: Function, set: Function }); - // Object.defineProperty(x, 'name', { get: Function }); - // Object.defineProperty(x, 'name', { set: Function }); - AssignmentDeclarationKindObjectDefinePropertyValue - // Object.defineProperty(exports || module.exports, 'name', ...); - AssignmentDeclarationKindObjectDefinePropertyExports - // Object.defineProperty(Foo.prototype, 'name', ...); - AssignmentDeclarationKindObjectDefinePrototypeProperty -) - type NodeCheckFlags uint32 const ( diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go index 708307c455..431eb7b04a 100644 --- a/internal/compiler/fileloader.go +++ b/internal/compiler/fileloader.go @@ -54,6 +54,7 @@ type processedFiles struct { // List of present unsupported extensions unsupportedExtensions []string sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path] + fileLoadDiagnostics *ast.DiagnosticsCollection } type jsxRuntimeImportSpecifier struct { @@ -132,6 +133,7 @@ func processAllProgramFiles( var unsupportedExtensions []string var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path] var libFileSet collections.Set[tspath.Path] + fileLoadDiagnostics := &ast.DiagnosticsCollection{} loader.parseTasks.collect(&loader, loader.rootTasks, func(task *parseTask, _ []tspath.Path) { if task.isRedirected { @@ -159,6 +161,7 @@ func processAllProgramFiles( resolvedModules[path] = task.resolutionsInFile typeResolutionsInFile[path] = task.typeResolutionsInFile sourceFileMetaDatas[path] = task.metadata + if task.jsxRuntimeImportSpecifier != nil { if jsxRuntimeImportSpecifiers == nil { jsxRuntimeImportSpecifiers = make(map[tspath.Path]*jsxRuntimeImportSpecifier, totalFileCount) @@ -183,8 +186,28 @@ func processAllProgramFiles( allFiles := append(libFiles, files...) + for _, resolutions := range resolvedModules { + for _, resolvedModule := range resolutions { + for _, diag := range resolvedModule.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } + } + for _, typeResolutions := range typeResolutionsInFile { + for _, resolvedTypeRef := range typeResolutions { + for _, diag := range resolvedTypeRef.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } + } + loader.pathForLibFileResolutions.Range(func(key tspath.Path, value module.ModeAwareCache[*module.ResolvedModule]) bool { resolvedModules[key] = value + for _, resolvedModule := range value { + for _, diag := range resolvedModule.ResolutionDiagnostics { + fileLoadDiagnostics.Add(diag) + } + } return true }) @@ -201,6 +224,7 @@ func processAllProgramFiles( unsupportedExtensions: unsupportedExtensions, sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules, libFiles: libFileSet, + fileLoadDiagnostics: fileLoadDiagnostics, } } @@ -372,6 +396,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) { resolutionMode := getModeForTypeReferenceDirectiveInFile(ref, file, meta, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect)) resolved := p.resolver.ResolveTypeReferenceDirective(ref.FileName, file.FileName(), resolutionMode, redirect) typeResolutionsInFile[module.ModeAwareCacheKey{Name: ref.FileName, Mode: resolutionMode}] = resolved + if resolved.IsResolved() { t.addSubTask(resolvedRef{ fileName: resolved.ResolvedFileName, diff --git a/internal/compiler/host.go b/internal/compiler/host.go index 82c8c697a3..8c480e896a 100644 --- a/internal/compiler/host.go +++ b/internal/compiler/host.go @@ -2,7 +2,6 @@ package compiler import ( "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/collections" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/parser" "github.com/microsoft/typescript-go/internal/tsoptions" @@ -15,50 +14,36 @@ type CompilerHost interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string Trace(msg string) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine } -type FileInfo struct { - Name string - Size int64 -} - var _ CompilerHost = (*compilerHost)(nil) type compilerHost struct { - options *core.CompilerOptions - currentDirectory string - fs vfs.FS - defaultLibraryPath string - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry] + currentDirectory string + fs vfs.FS + defaultLibraryPath string } func NewCachedFSCompilerHost( - options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath string, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], ) CompilerHost { - return NewCompilerHost(options, currentDirectory, cachedvfs.From(fs), defaultLibraryPath, extendedConfigCache) + return NewCompilerHost(currentDirectory, cachedvfs.From(fs), defaultLibraryPath) } func NewCompilerHost( - options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath string, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], ) CompilerHost { return &compilerHost{ - options: options, - currentDirectory: currentDirectory, - fs: fs, - defaultLibraryPath: defaultLibraryPath, - extendedConfigCache: extendedConfigCache, + currentDirectory: currentDirectory, + fs: fs, + defaultLibraryPath: defaultLibraryPath, } } @@ -70,21 +55,10 @@ func (h *compilerHost) DefaultLibraryPath() string { return h.defaultLibraryPath } -func (h *compilerHost) SetOptions(options *core.CompilerOptions) { - h.options = options -} - func (h *compilerHost) GetCurrentDirectory() string { return h.currentDirectory } -func (h *compilerHost) NewLine() string { - if h.options == nil { - return "\n" - } - return h.options.NewLine.GetNewLineCharacter() -} - func (h *compilerHost) Trace(msg string) { //!!! TODO: implement } diff --git a/internal/compiler/parsetask.go b/internal/compiler/parsetask.go index ebb6fdcce3..9d7045bfc4 100644 --- a/internal/compiler/parsetask.go +++ b/internal/compiler/parsetask.go @@ -22,6 +22,7 @@ type parseTask struct { metadata ast.SourceFileMetaData resolutionsInFile module.ModeAwareCache[*module.ResolvedModule] typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective] + resolutionDiagnostics []*ast.Diagnostic importHelpersImportSpecifier *ast.Node jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier increaseDepth bool diff --git a/internal/compiler/program.go b/internal/compiler/program.go index fa2ac6e908..25607fdb62 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -330,6 +330,11 @@ func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast. return p.getDiagnosticsHelper(ctx, sourceFile, true /*ensureBound*/, true /*ensureChecked*/, p.getSuggestionDiagnosticsForFile) } +func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic { + // !!! + return SortAndDeduplicateDiagnostics(p.fileLoadDiagnostics.GetDiagnostics()) +} + func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic { var globalDiagnostics []*ast.Diagnostic checkers, done := p.checkerPool.GetAllCheckers(ctx) diff --git a/internal/compiler/program_test.go b/internal/compiler/program_test.go index 0043848cef..c723b234ab 100644 --- a/internal/compiler/program_test.go +++ b/internal/compiler/program_test.go @@ -240,7 +240,7 @@ func TestProgram(t *testing.T) { CompilerOptions: &opts, }, }, - Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil), + Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()), }) actualFiles := []string{} @@ -277,7 +277,7 @@ func BenchmarkNewProgram(b *testing.B) { CompilerOptions: &opts, }, }, - Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil), + Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()), } for b.Loop() { @@ -294,7 +294,7 @@ func BenchmarkNewProgram(b *testing.B) { fs := osvfs.FS() fs = bundled.WrapFS(fs) - host := NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil) + host := NewCompilerHost(rootPath, fs, bundled.LibPath()) parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, host, nil) assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line") diff --git a/internal/execute/outputs.go b/internal/execute/outputs.go index 9a1f73d4ca..3e2e9a7ddd 100644 --- a/internal/execute/outputs.go +++ b/internal/execute/outputs.go @@ -98,7 +98,7 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm } func printVersion(sys System) { - fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version())+sys.NewLine()) + fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Format(core.Version())) sys.EndWrite() } @@ -144,7 +144,7 @@ func getHeader(sys System, message string) []string { // header.push("".padStart(leftAlign) + tsIconSecondLine + sys.newLine); // } // else { - header = append(header, message+sys.NewLine(), sys.NewLine()) + header = append(header, message+"\n", "\n") // } return header } @@ -156,15 +156,15 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) { for _, example := range examples { // !!! colors // output.push(" " + colors.blue(example) + sys.newLine); - output = append(output, " ", example, sys.NewLine()) + output = append(output, " ", example, "\n") } - output = append(output, " ", desc.Format(), sys.NewLine(), sys.NewLine()) + output = append(output, " ", desc.Format(), "\n", "\n") } msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version()) output = append(output, getHeader(sys, msg)...) - output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, sys.NewLine(), sys.NewLine()) + output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, "\n", "\n") example([]string{"tsc"}, diagnostics.Compiles_the_current_project_tsconfig_json_in_the_working_directory) example([]string{"tsc app.ts util.ts"}, diagnostics.Ignoring_tsconfig_json_compiles_the_specified_files_with_default_compiler_options) @@ -206,15 +206,15 @@ func generateSectionOptionsOutput( afterOptionsDescription *string, ) (output []string) { // !!! color - output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, sys.NewLine(), sys.NewLine()) + output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, "\n", "\n") if beforeOptionsDescription != nil { - output = append(output, *beforeOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *beforeOptionsDescription, "\n", "\n") } if !subCategory { output = append(output, generateGroupOptionOutput(sys, options)...) if afterOptionsDescription != nil { - output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *afterOptionsDescription, "\n", "\n") } return output } @@ -227,11 +227,11 @@ func generateSectionOptionsOutput( categoryMap[curCategory] = append(categoryMap[curCategory], option) } for key, value := range categoryMap { - output = append(output, "### ", key, sys.NewLine(), sys.NewLine()) + output = append(output, "### ", key, "\n", "\n") output = append(output, generateGroupOptionOutput(sys, value)...) } if afterOptionsDescription != nil { - output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + output = append(output, *afterOptionsDescription, "\n", "\n") } return output @@ -258,8 +258,8 @@ func generateGroupOptionOutput(sys System, optionsList []*tsoptions.CommandLineO } // make sure always a blank line in the end. - if len(lines) < 2 || lines[len(lines)-2] != sys.NewLine() { - lines = append(lines, sys.NewLine()) + if len(lines) < 2 || lines[len(lines)-2] != "\n" { + lines = append(lines, "\n") } return lines @@ -312,25 +312,25 @@ func generateOptionOutput( // !!! } // !!! text.push(sys.newLine); } else { - text = append(text /* !!! colors.blue(name) */, name, sys.NewLine()) + text = append(text /* !!! colors.blue(name) */, name, "\n") if option.Description != nil { text = append(text, option.Description.Format()) } - text = append(text, sys.NewLine()) + text = append(text, "\n") if showAdditionalInfoOutput(valueCandidates, option) { if valueCandidates != nil { text = append(text, valueCandidates.valueType, " ", valueCandidates.possibleValues) } if defaultValueDescription != "" { if valueCandidates != nil { - text = append(text, sys.NewLine()) + text = append(text, "\n") } text = append(text, diagnostics.X_default_Colon.Format(), " ", defaultValueDescription) } - text = append(text, sys.NewLine()) + text = append(text, "\n") } - text = append(text, sys.NewLine()) + text = append(text, "\n") } return text diff --git a/internal/execute/system.go b/internal/execute/system.go index 3861a04392..a31101dd3c 100644 --- a/internal/execute/system.go +++ b/internal/execute/system.go @@ -13,7 +13,6 @@ type System interface { FS() vfs.FS DefaultLibraryPath() string GetCurrentDirectory() string - NewLine() string // #241 eventually we want to use "\n" Now() time.Time SinceStart() time.Duration diff --git a/internal/execute/testsys_test.go b/internal/execute/testsys_test.go index 92eda1f4ad..789dcec088 100644 --- a/internal/execute/testsys_test.go +++ b/internal/execute/testsys_test.go @@ -72,10 +72,6 @@ func (s *testSys) GetCurrentDirectory() string { return s.cwd } -func (s *testSys) NewLine() string { - return "\n" -} - func (s *testSys) Writer() io.Writer { return s.currentWrite } diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index f680ff880a..615247e19c 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -46,7 +46,7 @@ func CommandLine(sys System, cb cbType, commandLineArgs []string) ExitStatus { // !!! build mode switch strings.ToLower(commandLineArgs[0]) { case "-b", "--b", "-build", "--build": - fmt.Fprint(sys.Writer(), "Build mode is currently unsupported."+sys.NewLine()) + fmt.Fprintln(sys.Writer(), "Build mode is currently unsupported.") sys.EndWrite() return ExitStatusNotImplemented // case "-f": @@ -63,12 +63,12 @@ func CommandLine(sys System, cb cbType, commandLineArgs []string) ExitStatus { } func fmtMain(sys System, input, output string) ExitStatus { - ctx := format.WithFormatCodeSettings(context.Background(), format.GetDefaultFormatCodeSettings(sys.NewLine()), sys.NewLine()) + ctx := format.WithFormatCodeSettings(context.Background(), format.GetDefaultFormatCodeSettings("\n"), "\n") input = string(tspath.ToPath(input, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) output = string(tspath.ToPath(output, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames())) fileContent, ok := sys.FS().ReadFile(input) if !ok { - fmt.Fprint(sys.Writer(), "File not found: "+input+sys.NewLine()) + fmt.Fprintln(sys.Writer(), "File not found:", input) return ExitStatusNotImplemented } text := fileContent @@ -82,7 +82,7 @@ func fmtMain(sys System, input, output string) ExitStatus { newText := applyBulkEdits(text, edits) if err := sys.FS().WriteFile(output, newText, false); err != nil { - fmt.Fprint(sys.Writer(), err.Error()+sys.NewLine()) + fmt.Fprintln(sys.Writer(), err.Error()) return ExitStatusNotImplemented } return ExitStatusSuccess @@ -188,7 +188,6 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars cb, configParseResult, reportDiagnostic, - &extendedConfigCache, configTime, ), nil } else { @@ -208,7 +207,6 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars cb, commandLine, reportDiagnostic, - nil, 0, /*configTime*/ ), nil } @@ -232,10 +230,9 @@ func performCompilation( cb cbType, config *tsoptions.ParsedCommandLine, reportDiagnostic diagnosticReporter, - extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry], configTime time.Duration, ) ExitStatus { - host := compiler.NewCachedFSCompilerHost(config.CompilerOptions(), sys.GetCurrentDirectory(), sys.FS(), sys.DefaultLibraryPath(), extendedConfigCache) + host := compiler.NewCachedFSCompilerHost(sys.GetCurrentDirectory(), sys.FS(), sys.DefaultLibraryPath()) // todo: cache, statistics, tracing parseStart := sys.Now() program := compiler.NewProgram(compiler.ProgramOptions{ @@ -296,6 +293,7 @@ func emitFilesAndReportErrors(sys System, program *compiler.Program, reportDiagn configFileParsingDiagnosticsLength := len(allDiagnostics) allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, nil)...) + allDiagnostics = append(allDiagnostics, program.GetProgramDiagnostics()...) if len(allDiagnostics) == configFileParsingDiagnosticsLength { // Options diagnostics include global diagnostics (even though we collect them separately), @@ -373,7 +371,7 @@ func listFiles(sys System, program *compiler.Program) { // !!! explainFiles if options.ListFiles.IsTrue() || options.ListFilesOnly.IsTrue() { for _, file := range program.GetSourceFiles() { - fmt.Fprintf(sys.Writer(), "%s%s", file.FileName(), sys.NewLine()) + fmt.Fprintln(sys.Writer(), file.FileName()) } } } diff --git a/internal/execute/watch.go b/internal/execute/watch.go index 6d587951d1..e1b2b9dbb3 100644 --- a/internal/execute/watch.go +++ b/internal/execute/watch.go @@ -24,7 +24,7 @@ func start(w *watcher) ExitStatus { func (w *watcher) initialize() { // if this function is updated, make sure to update `StartForTest` in export_test.go as needed if w.configFileName == "" { - w.host = compiler.NewCompilerHost(w.options.CompilerOptions(), w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath(), nil) + w.host = compiler.NewCompilerHost(w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath()) } } @@ -42,12 +42,12 @@ func (w *watcher) doCycle() { JSDocParsingMode: ast.JSDocParsingModeParseForTypeErrors, }) if w.hasBeenModified(w.program) { - fmt.Fprint(w.sys.Writer(), "build starting at ", w.sys.Now(), w.sys.NewLine()) + fmt.Fprintln(w.sys.Writer(), "build starting at", w.sys.Now()) timeStart := w.sys.Now() w.compileAndEmit() - fmt.Fprint(w.sys.Writer(), "build finished in ", w.sys.Now().Sub(timeStart), w.sys.NewLine()) + fmt.Fprintln(w.sys.Writer(), "build finished in", w.sys.Now().Sub(timeStart)) } else { // print something??? - // fmt.Fprint(w.sys.Writer(), "no changes detected at ", w.sys.Now(), w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "no changes detected at", w.sys.Now()) } } diff --git a/internal/execute/watcher.go b/internal/execute/watcher.go index 5697c7525d..716a262460 100644 --- a/internal/execute/watcher.go +++ b/internal/execute/watcher.go @@ -56,11 +56,11 @@ func (w *watcher) hasErrorsInTsConfig() bool { } // CompilerOptions contain fields which should not be compared; clone to get a copy without those set. if !reflect.DeepEqual(w.options.CompilerOptions().Clone(), configParseResult.CompilerOptions().Clone()) { - // fmt.Fprint(w.sys.Writer(), "build triggered due to config change", w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "build triggered due to config change") w.configModified = true } w.options = configParseResult - w.host = compiler.NewCompilerHost(w.options.CompilerOptions(), w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath(), &extendedConfigCache) + w.host = compiler.NewCompilerHost(w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath()) } return false } @@ -80,7 +80,7 @@ func (w *watcher) hasBeenModified(program *compiler.Program) bool { currState[fileName] = s.ModTime() if !filesModified { if currState[fileName] != w.prevModified[fileName] { - // fmt.Fprint(w.sys.Writer(), "build triggered from ", fileName, ": ", w.prevModified[fileName], " -> ", currState[fileName], w.sys.NewLine()) + // fmt.Fprint(w.sys.Writer(), "build triggered from ", fileName, ": ", w.prevModified[fileName], " -> ", currState[fileName], "\n") filesModified = true } // catch cases where no files are modified, but some were deleted @@ -88,7 +88,7 @@ func (w *watcher) hasBeenModified(program *compiler.Program) bool { } } if !filesModified && len(w.prevModified) > 0 { - // fmt.Fprint(w.sys.Writer(), "build triggered due to deleted file", w.sys.NewLine()) + // fmt.Fprintln(w.sys.Writer(), "build triggered due to deleted file") filesModified = true } w.prevModified = currState diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index e099c59f0e..e68d0621a4 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -2,6 +2,7 @@ import * as cp from "child_process"; import * as fs from "fs"; import * as path from "path"; import * as ts from "typescript"; +import * as url from "url"; import which from "which"; const stradaFourslashPath = path.resolve(import.meta.dirname, "../", "../", "../", "_submodules", "TypeScript", "tests", "cases", "fourslash"); @@ -9,15 +10,18 @@ const stradaFourslashPath = path.resolve(import.meta.dirname, "../", "../", "../ let inputFileSet: Set | undefined; const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt"); -const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0); -const failingTests = new Set(failingTestsList); const helperFilePath = path.join(import.meta.dirname, "../", "tests", "util_test.go"); const outputDir = path.join(import.meta.dirname, "../", "tests", "gen"); const unparsedFiles: string[] = []; -function main() { +function getFailingTests(): Set { + const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0); + return new Set(failingTestsList); +} + +export function main() { const args = process.argv.slice(2); const inputFilesPath = args[0]; if (inputFilesPath) { @@ -28,18 +32,17 @@ function main() { inputFileSet = new Set(inputFiles); } - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); - } + fs.rmSync(outputDir, { recursive: true, force: true }); + fs.mkdirSync(outputDir, { recursive: true }); generateHelperFile(); - parseTypeScriptFiles(stradaFourslashPath); + parseTypeScriptFiles(getFailingTests(), stradaFourslashPath); console.log(unparsedFiles.join("\n")); const gofmt = which.sync("go"); cp.execFileSync(gofmt, ["tool", "mvdan.cc/gofumpt", "-lang=go1.24", "-w", outputDir]); } -function parseTypeScriptFiles(folder: string): void { +function parseTypeScriptFiles(failingTests: Set, folder: string): void { const files = fs.readdirSync(folder); files.forEach(file => { @@ -50,13 +53,13 @@ function parseTypeScriptFiles(folder: string): void { } if (stat.isDirectory()) { - parseTypeScriptFiles(filePath); + parseTypeScriptFiles(failingTests, filePath); } else if (file.endsWith(".ts")) { const content = fs.readFileSync(filePath, "utf-8"); const test = parseFileContent(file, content); if (test) { - const testContent = generateGoTest(test); + const testContent = generateGoTest(failingTests, test); const testPath = path.join(outputDir, `${test.name}_test.go`); fs.writeFileSync(testPath, testContent, "utf-8"); } @@ -142,9 +145,9 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined { if (namespace.text === "verify" && func.text === "completions") { return parseVerifyCompletionsArgs(callExpression.arguments); } - // `goTo.marker(...)` - if (namespace.text === "goTo" && func.text === "marker") { - return parseGoToMarkerArgs(callExpression.arguments); + // `goTo....` + if (namespace.text === "goTo") { + return parseGoToArgs(callExpression.arguments, func.text); } // `edit....` if (namespace.text === "edit") { @@ -208,20 +211,83 @@ function getGoStringLiteral(text: string): string { return `${JSON.stringify(text)}`; } -function parseGoToMarkerArgs(args: readonly ts.Expression[]): GoToMarkerCmd[] | undefined { - if (args.length !== 1) { - console.error(`Expected exactly one argument in goTo.marker, got ${args.length}`); - return undefined; - } - const arg = args[0]; - if (!ts.isStringLiteral(arg)) { - console.error(`Unrecognized argument in goTo.marker: ${arg.getText()}`); - return undefined; +function parseGoToArgs(args: readonly ts.Expression[], funcName: string): GoToCmd[] | undefined { + switch (funcName) { + case "marker": + const arg = args[0]; + if (arg === undefined) { + return [{ + kind: "goTo", + funcName: "marker", + args: [`""`], + }]; + } + if (!ts.isStringLiteral(arg)) { + console.error(`Unrecognized argument in goTo.marker: ${arg.getText()}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "marker", + args: [getGoStringLiteral(arg.text)], + }]; + case "file": + if (args.length !== 1) { + console.error(`Expected a single argument in goTo.file, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + if (ts.isStringLiteral(args[0])) { + return [{ + kind: "goTo", + funcName: "file", + args: [getGoStringLiteral(args[0].text)], + }]; + } + else if (ts.isNumericLiteral(args[0])) { + return [{ + kind: "goTo", + funcName: "fileNumber", + args: [args[0].text], + }]; + } + console.error(`Expected string or number literal argument in goTo.file, got ${args[0].getText()}`); + return undefined; + case "position": + if (args.length !== 1 || !ts.isNumericLiteral(args[0])) { + console.error(`Expected a single numeric literal argument in goTo.position, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "position", + args: [`${args[0].text}`], + }]; + case "eof": + return [{ + kind: "goTo", + funcName: "EOF", + args: [], + }]; + case "bof": + return [{ + kind: "goTo", + funcName: "BOF", + args: [], + }]; + case "select": + if (args.length !== 2 || !ts.isStringLiteral(args[0]) || !ts.isStringLiteral(args[1])) { + console.error(`Expected two string literal arguments in goTo.select, got ${args.map(arg => arg.getText()).join(", ")}`); + return undefined; + } + return [{ + kind: "goTo", + funcName: "select", + args: [getGoStringLiteral(args[0].text), getGoStringLiteral(args[1].text)], + }]; + default: + console.error(`Unrecognized goTo function: ${funcName}`); + return undefined; } - return [{ - kind: "goToMarker", - marker: getGoStringLiteral(arg.text), - }]; } function parseVerifyCompletionsArgs(args: readonly ts.Expression[]): VerifyCompletionsCmd[] | undefined { @@ -304,6 +370,7 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un break; case "exact": case "includes": + case "unsorted": if (init.getText() === "undefined") { return { kind: "verifyCompletions", @@ -385,9 +452,12 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un if (propName === "includes") { (goArgs ??= {}).includes = expected; } - else { + else if (propName === "exact") { (goArgs ??= {}).exact = expected; } + else { + (goArgs ??= {}).unsorted = expected; + } break; case "excludes": let excludes = "[]string{"; @@ -659,11 +729,14 @@ interface VerifyCompletionsArgs { includes?: string; excludes?: string; exact?: string; + unsorted?: string; } -interface GoToMarkerCmd { - kind: "goToMarker"; - marker: string; +interface GoToCmd { + kind: "goTo"; + // !!! `selectRange` and `rangeStart` require parsing variables and `test.ranges()[n]` + funcName: "marker" | "file" | "fileNumber" | "EOF" | "BOF" | "position" | "select"; + args: string[]; } interface EditCmd { @@ -671,7 +744,7 @@ interface EditCmd { goStatement: string; } -type Cmd = VerifyCompletionsCmd | GoToMarkerCmd | EditCmd; +type Cmd = VerifyCompletionsCmd | GoToCmd | EditCmd; function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: VerifyCompletionsCmd): string { let expectedList = "nil"; @@ -680,6 +753,7 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve if (args.includes) expected.push(`Includes: ${args.includes},`); if (args.excludes) expected.push(`Excludes: ${args.excludes},`); if (args.exact) expected.push(`Exact: ${args.exact},`); + if (args.unsorted) expected.push(`Unsorted: ${args.unsorted},`); // !!! isIncomplete const commitCharacters = isNewIdentifierLocation ? "[]string{}" : "defaultCommitCharacters"; expectedList = `&fourslash.CompletionsExpectedList{ @@ -696,16 +770,17 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve return `f.VerifyCompletions(t, ${marker}, ${expectedList})`; } -function generateGoToMarker({ marker }: GoToMarkerCmd): string { - return `f.GoToMarker(t, ${marker})`; +function generateGoToCommand({ funcName, args }: GoToCmd): string { + const funcNameCapitalized = funcName.charAt(0).toUpperCase() + funcName.slice(1); + return `f.GoTo${funcNameCapitalized}(t, ${args.join(", ")})`; } function generateCmd(cmd: Cmd): string { switch (cmd.kind) { case "verifyCompletions": return generateVerifyCompletions(cmd as VerifyCompletionsCmd); - case "goToMarker": - return generateGoToMarker(cmd as GoToMarkerCmd); + case "goTo": + return generateGoToCommand(cmd as GoToCmd); case "edit": return cmd.goStatement; default: @@ -719,7 +794,7 @@ interface GoTest { commands: Cmd[]; } -function generateGoTest(test: GoTest): string { +function generateGoTest(failingTests: Set, test: GoTest): string { const testName = test.name[0].toUpperCase() + test.name.substring(1); const content = test.content; const commands = test.commands.map(cmd => generateCmd(cmd)).join("\n"); @@ -755,4 +830,6 @@ function generateHelperFile() { fs.copyFileSync(helperFilePath, path.join(outputDir, "util_test.go")); } -main(); +if (url.fileURLToPath(import.meta.url) == process.argv[1]) { + main(); +} diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 58428835d0..2be75089f2 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -1,8 +1,6 @@ TestAutoImportsWithRootDirsAndRootedPath01 TestClosedCommentsInConstructor TestCodeCompletionEscaping -TestCompletionAfterNewline -TestCompletionAfterNewline2 TestCompletionCloneQuestionToken TestCompletionEntryForArgumentConstrainedToString TestCompletionEntryForArrayElementConstrainedToString @@ -44,6 +42,8 @@ TestCompletionForStringLiteral_quotePreference3 TestCompletionForStringLiteral_quotePreference4 TestCompletionForStringLiteral_quotePreference5 TestCompletionForStringLiteral_quotePreference6 +TestCompletionForStringLiteral_quotePreference7 +TestCompletionForStringLiteral_quotePreference8 TestCompletionImportMeta TestCompletionImportMetaWithGlobalDeclaration TestCompletionImportModuleSpecifierEndingDts @@ -62,10 +62,10 @@ TestCompletionListAndMemberListOnCommentedWhiteSpace TestCompletionListAtInvalidLocations TestCompletionListBuilderLocations_VariableDeclarations TestCompletionListCladule +TestCompletionListClassMembers TestCompletionListForExportEquals TestCompletionListForTransitivelyExportedMembers01 TestCompletionListForTransitivelyExportedMembers04 -TestCompletionListForUnicodeEscapeName TestCompletionListFunctionExpression TestCompletionListFunctionMembers TestCompletionListInArrowFunctionInUnclosedCallSite01 @@ -75,7 +75,6 @@ TestCompletionListInComments TestCompletionListInComments2 TestCompletionListInComments3 TestCompletionListInExtendsClause -TestCompletionListInFunctionDeclaration TestCompletionListInImportClause01 TestCompletionListInImportClause05 TestCompletionListInImportClause06 @@ -85,14 +84,16 @@ TestCompletionListInUnclosedCommaExpression01 TestCompletionListInUnclosedCommaExpression02 TestCompletionListInUnclosedFunction08 TestCompletionListInUnclosedFunction09 -TestCompletionListInUnclosedFunction10 -TestCompletionListInUnclosedFunction11 TestCompletionListInUnclosedTaggedTemplate01 TestCompletionListInUnclosedTaggedTemplate02 TestCompletionListInUnclosedTemplate01 TestCompletionListInUnclosedTemplate02 TestCompletionListInvalidMemberNames2 TestCompletionListInvalidMemberNames_withExistingIdentifier +TestCompletionListOnAliases2 +TestCompletionListPrivateNames +TestCompletionListPrivateNamesAccessors +TestCompletionListPrivateNamesMethods TestCompletionListStaticMembers TestCompletionListStaticProtectedMembers TestCompletionListStaticProtectedMembers2 @@ -108,9 +109,7 @@ TestCompletionWithConditionalOperatorMissingColon TestCompletionsAfterJSDoc TestCompletionsBeforeRestArg1 TestCompletionsECMAPrivateMemberTriggerCharacter -TestCompletionsImportDefaultExportCrash1 TestCompletionsImport_computedSymbolName -TestCompletionsImport_umdDefaultNoCrash2 TestCompletionsInRequire TestCompletionsInterfaceElement TestCompletionsJSDocImportTagAttributesEmptyModuleSpecifier1 @@ -128,7 +127,6 @@ TestCompletionsMergedDeclarations1 TestCompletionsNamespaceMergedWithClass TestCompletionsNamespaceName TestCompletionsNewTarget -TestCompletionsNonExistentImport TestCompletionsOptionalKindModifier TestCompletionsOptionalMethod TestCompletionsOverridingMethod1 @@ -176,6 +174,7 @@ TestGetJavaScriptCompletions8 TestGetJavaScriptCompletions9 TestGetJavaScriptGlobalCompletions1 TestGetJavaScriptQuickInfo8 +TestGlobalThisCompletion TestImportCompletionsPackageJsonExportsSpecifierEndsInTs TestImportCompletionsPackageJsonExportsTrailingSlash1 TestImportCompletionsPackageJsonImportsConditions1 @@ -198,8 +197,11 @@ TestImportStatementCompletions4 TestImportStatementCompletions_noPatternAmbient TestImportStatementCompletions_pnpmTransitive TestImportTypeMemberCompletions +TestJavaScriptClass4 TestJavaScriptModules12 +TestJavaScriptModules13 TestJavaScriptModules14 +TestJavaScriptModules19 TestJavascriptModules20 TestJavascriptModules21 TestJavascriptModulesTypeImport @@ -221,6 +223,7 @@ TestJsdocTypedefTag2 TestJsdocTypedefTagNamespace TestJsdocTypedefTagTypeExpressionCompletion TestJsxAriaLikeCompletions +TestJsxQualifiedTagCompletion TestMemberListErrorRecovery TestMemberListInWithBlock TestMemberListOnConstructorType @@ -274,7 +277,6 @@ TestPathCompletionsTypesVersionsWildcard3 TestPathCompletionsTypesVersionsWildcard4 TestPathCompletionsTypesVersionsWildcard5 TestPathCompletionsTypesVersionsWildcard6 -TestSatisfiesOperatorCompletion TestStringCompletionsImportOrExportSpecifier TestStringCompletionsVsEscaping TestStringLiteralTypeCompletionsInTypeArgForNonGeneric1 diff --git a/internal/fourslash/_scripts/tsconfig.json b/internal/fourslash/_scripts/tsconfig.json index 3337b2f1d7..2a320eaf55 100644 --- a/internal/fourslash/_scripts/tsconfig.json +++ b/internal/fourslash/_scripts/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "strict": true, "noEmit": true, - "module": "nodenext" + "module": "nodenext", + "allowImportingTsExtensions": true } } diff --git a/internal/fourslash/_scripts/updateFailing.mts b/internal/fourslash/_scripts/updateFailing.mts new file mode 100644 index 0000000000..f30e7462f2 --- /dev/null +++ b/internal/fourslash/_scripts/updateFailing.mts @@ -0,0 +1,32 @@ +import * as cp from "child_process"; +import * as fs from "fs"; +import path from "path"; +import which from "which"; +import { main as convertFourslash } from "./convertFourslash.mts"; + +const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt"); + +function main() { + fs.writeFileSync(failingTestsPath, "", "utf-8"); + convertFourslash(); + const go = which.sync("go"); + let testOutput: string; + try { + testOutput = cp.execFileSync(go, ["test", "./internal/fourslash/tests/gen"], { encoding: "utf-8" }); + } + catch (error) { + testOutput = (error as { stdout: string; }).stdout as string; + } + const regex = /--- FAIL: ([\S]+)/gm; + const failingTests: string[] = []; + let match; + + while ((match = regex.exec(testOutput)) !== null) { + failingTests.push(match[1]); + } + + fs.writeFileSync(failingTestsPath, failingTests.sort().join("\n") + "\n", "utf-8"); + convertFourslash(); +} + +main(); diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index d9c5b9b9ff..0c7044c5bc 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -3,6 +3,8 @@ package fourslash import ( "fmt" "io" + "maps" + "slices" "strings" "testing" "unicode" @@ -37,7 +39,7 @@ type FourslashTest struct { converters *ls.Converters currentCaretPosition lsproto.Position - lastKnownMarkerName string + lastKnownMarkerName *string activeFilename string selectionEnd *lsproto.Position } @@ -127,13 +129,14 @@ func (c *parsedFileCache) CacheFile(opts ast.SourceFileParseOptions, text string var _ project.ParsedFileCache = (*parsedFileCache)(nil) +const rootDir = "/" + func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, content string) *FourslashTest { if !bundled.Embedded { // Without embedding, we'd need to read all of the lib files out from disk into the MapFS. // Just skip this for now. t.Skip("bundled files are not embedded") } - rootDir := "/" fileName := getFileNameFromTest(t) testfs := make(map[string]string) scriptInfos := make(map[string]*scriptInfo) @@ -159,7 +162,6 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten Err: &err, Cwd: "/", - NewLine: core.NewLineKindLF, FS: fs, DefaultLibraryPath: bundled.LibPath(), @@ -296,8 +298,12 @@ func (f *FourslashTest) readMsg(t *testing.T) *lsproto.Message { func (f *FourslashTest) GoToMarker(t *testing.T, markerName string) { marker, ok := f.testData.MarkerPositions[markerName] if !ok { - t.Fatalf("Marker %s not found", markerName) + t.Fatalf("Marker '%s' not found", markerName) } + f.goToMarker(t, marker) +} + +func (f *FourslashTest) goToMarker(t *testing.T, marker *Marker) { f.ensureActiveFile(t, marker.FileName) f.goToPosition(t, marker.LSPosition) f.lastKnownMarkerName = marker.Name @@ -310,11 +316,89 @@ func (f *FourslashTest) GoToEOF(t *testing.T) { f.goToPosition(t, LSPPos) } +func (f *FourslashTest) GoToBOF(t *testing.T) { + f.goToPosition(t, lsproto.Position{Line: 0, Character: 0}) +} + +func (f *FourslashTest) GoToPosition(t *testing.T, position int) { + script := f.getScriptInfo(f.activeFilename) + LSPPos := f.converters.PositionToLineAndCharacter(script, core.TextPos(position)) + f.goToPosition(t, LSPPos) +} + func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { f.currentCaretPosition = position f.selectionEnd = nil } +func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(t *testing.T, marker *Marker, index int)) { + var markers []*Marker + if len(markers) == 0 { + markers = f.Markers() + } else { + markers = make([]*Marker, 0, len(markerNames)) + for _, name := range markerNames { + marker, ok := f.testData.MarkerPositions[name] + if !ok { + t.Fatalf("Marker '%s' not found", name) + } + markers = append(markers, marker) + } + } + for i, marker := range markers { + f.goToMarker(t, marker) + action(t, marker, i) + } +} + +func (f *FourslashTest) GoToEachRange(t *testing.T, action func(t *testing.T, rangeMarker *RangeMarker)) { + ranges := f.Ranges() + for _, rangeMarker := range ranges { + f.goToPosition(t, rangeMarker.LSRange.Start) + action(t, rangeMarker) + } +} + +func (f *FourslashTest) GoToRangeStart(t *testing.T, rangeMarker *RangeMarker) { + f.openFile(t, rangeMarker.FileName) + f.goToPosition(t, rangeMarker.LSRange.Start) +} + +func (f *FourslashTest) GoToSelect(t *testing.T, startMarkerName string, endMarkerName string) { + startMarker := f.testData.MarkerPositions[startMarkerName] + if startMarker == nil { + t.Fatalf("Start marker '%s' not found", startMarkerName) + } + endMarker := f.testData.MarkerPositions[endMarkerName] + if endMarker == nil { + t.Fatalf("End marker '%s' not found", endMarkerName) + } + if startMarker.FileName != endMarker.FileName { + t.Fatalf("Markers '%s' and '%s' are in different files", startMarkerName, endMarkerName) + } + f.ensureActiveFile(t, startMarker.FileName) + f.goToPosition(t, startMarker.LSPosition) + f.selectionEnd = &endMarker.LSPosition +} + +func (f *FourslashTest) GoToSelectRange(t *testing.T, rangeMarker *RangeMarker) { + f.GoToRangeStart(t, rangeMarker) + f.selectionEnd = &rangeMarker.LSRange.End +} + +func (f *FourslashTest) GoToFile(t *testing.T, filename string) { + filename = tspath.GetNormalizedAbsolutePath(filename, rootDir) + f.openFile(t, filename) +} + +func (f *FourslashTest) GoToFileNumber(t *testing.T, index int) { + if index < 0 || index >= len(f.testData.Files) { + t.Fatalf("File index %d out of range (0-%d)", index, len(f.testData.Files)-1) + } + filename := f.testData.Files[index].fileName + f.openFile(t, filename) +} + func (f *FourslashTest) Markers() []*Marker { return f.testData.Markers } @@ -392,11 +476,11 @@ type CompletionsExpectedItemDefaults struct { // *lsproto.CompletionItem | string type CompletionsExpectedItem = any -// !!! unsorted completions type CompletionsExpectedItems struct { Includes []CompletionsExpectedItem Excludes []string Exact []CompletionsExpectedItem + Unsorted []CompletionsExpectedItem } // string | *Marker | []string | []*Marker @@ -404,20 +488,23 @@ type MarkerInput = any // !!! user preferences param // !!! completion context param -// !!! go to marker: use current marker if none specified/support nil marker input func (f *FourslashTest) VerifyCompletions(t *testing.T, markerInput MarkerInput, expected *CompletionsExpectedList) { switch marker := markerInput.(type) { case string: - f.verifyCompletionsAtMarker(t, marker, expected) + f.GoToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) case *Marker: - f.verifyCompletionsAtMarker(t, marker.Name, expected) + f.goToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) case []string: for _, markerName := range marker { - f.verifyCompletionsAtMarker(t, markerName, expected) + f.GoToMarker(t, markerName) + f.verifyCompletionsWorker(t, expected) } case []*Marker: for _, marker := range marker { - f.verifyCompletionsAtMarker(t, marker.Name, expected) + f.goToMarker(t, marker) + f.verifyCompletionsWorker(t, expected) } case nil: f.verifyCompletionsWorker(t, expected) @@ -426,12 +513,13 @@ func (f *FourslashTest) VerifyCompletions(t *testing.T, markerInput MarkerInput, } } -func (f *FourslashTest) verifyCompletionsAtMarker(t *testing.T, markerName string, expected *CompletionsExpectedList) { - f.GoToMarker(t, markerName) - f.verifyCompletionsWorker(t, expected) -} - func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *CompletionsExpectedList) { + var prefix string + if f.lastKnownMarkerName != nil { + prefix = fmt.Sprintf("At marker '%s': ", *f.lastKnownMarkerName) + } else { + prefix = fmt.Sprintf("At position (Ln %d, Col %d): ", f.currentCaretPosition.Line, f.currentCaretPosition.Character) + } params := &lsproto.CompletionParams{ TextDocumentPositionParams: lsproto.TextDocumentPositionParams{ TextDocument: lsproto.TextDocumentIdentifier{ @@ -443,19 +531,24 @@ func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *Completi } resMsg := f.sendRequest(t, lsproto.MethodTextDocumentCompletion, params) if resMsg == nil { - t.Fatalf("Nil response received for completion request at marker %s", f.lastKnownMarkerName) + t.Fatalf(prefix+"Nil response received for completion request", f.lastKnownMarkerName) } result := resMsg.AsResponse().Result switch result := result.(type) { case *lsproto.CompletionList: - verifyCompletionsResult(t, f.lastKnownMarkerName, result, expected) + f.verifyCompletionsResult(t, f.currentCaretPosition, result, expected, prefix) default: - t.Fatalf("Unexpected response type for completion request at marker %s: %v", f.lastKnownMarkerName, result) + t.Fatalf(prefix+"Unexpected response type for completion request: %v", result) } } -func verifyCompletionsResult(t *testing.T, markerName string, actual *lsproto.CompletionList, expected *CompletionsExpectedList) { - prefix := fmt.Sprintf("At marker '%s': ", markerName) +func (f *FourslashTest) verifyCompletionsResult( + t *testing.T, + position lsproto.Position, + actual *lsproto.CompletionList, + expected *CompletionsExpectedList, + prefix string, +) { if actual == nil { if !isEmptyExpectedList(expected) { t.Fatal(prefix + "Expected completion list but got nil.") @@ -520,6 +613,9 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl if expected.Excludes != nil { t.Fatal(prefix + "Expected exact completion list but also specified 'excludes'.") } + if expected.Unsorted != nil { + t.Fatal(prefix + "Expected exact completion list but also specified 'unsorted'.") + } if len(actual) != len(expected.Exact) { t.Fatalf(prefix+"Expected %d exact completion items but got %d: %s", len(expected.Exact), len(actual), cmp.Diff(actual, expected.Exact)) } @@ -532,6 +628,38 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl for _, item := range actual { nameToActualItem[item.Label] = item } + if expected.Unsorted != nil { + if expected.Includes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'includes'.") + } + if expected.Excludes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'excludes'.") + } + for _, item := range expected.Unsorted { + switch item := item.(type) { + case string: + _, ok := nameToActualItem[item] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item) + case *lsproto.CompletionItem: + actualItem, ok := nameToActualItem[item.Label] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item.Label, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item.Label) + verifyCompletionItem(t, prefix+"Includes completion item mismatch for label "+item.Label, actualItem, item) + default: + t.Fatalf("%sExpected completion item to be a string or *lsproto.CompletionItem, got %T", prefix, item) + } + } + if len(expected.Unsorted) != len(actual) { + unmatched := slices.Collect(maps.Keys(nameToActualItem)) + t.Fatalf("%sAdditional completions found but not included in 'unsorted': %s", prefix, strings.Join(unmatched, "\n")) + } + return + } if expected.Includes != nil { for _, item := range expected.Includes { switch item := item.(type) { diff --git a/internal/fourslash/test_parser.go b/internal/fourslash/test_parser.go index 1b84be0181..cfd39fb180 100644 --- a/internal/fourslash/test_parser.go +++ b/internal/fourslash/test_parser.go @@ -31,7 +31,7 @@ type Marker struct { FileName string Position int LSPosition lsproto.Position - Name string + Name *string // `nil` for anonymous markers such as `{| "foo": "bar" |}` Data map[string]interface{} } @@ -75,10 +75,13 @@ func ParseTestData(t *testing.T, contents string, fileName string) TestData { markers = append(markers, file.markers...) ranges = append(ranges, file.ranges...) for _, marker := range file.markers { - if _, ok := markerPositions[marker.Name]; ok { - t.Fatalf("Duplicate marker name: %s", marker.Name) + if marker.Name == nil { + continue } - markerPositions[marker.Name] = marker + if _, ok := markerPositions[*marker.Name]; ok { + t.Fatalf("Duplicate marker name: '%s'", *marker.Name) + } + markerPositions[*marker.Name] = marker } } @@ -271,7 +274,7 @@ func parseFileContent(fileName string, content string, fileOptions map[string]st marker := &Marker{ FileName: fileName, Position: openMarker.position, - Name: markerNameText, + Name: &markerNameText, } if len(openRanges) > 0 { openRanges[len(openRanges)-1].marker = marker @@ -380,7 +383,7 @@ func getObjectMarker(fileName string, location *locationInformation, text string // Object markers can be anonymous if markerValue["name"] != nil { if name, ok := markerValue["name"].(string); ok && name != "" { - marker.Name = name + marker.Name = &name } } diff --git a/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go new file mode 100644 index 0000000000..c728bd7434 --- /dev/null +++ b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "strings" + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInUnclosedTypeArguments(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let x = 10; +type Type = void; +declare function f(): void; +declare function f2(): void; +f +f +f(); + +f2 +f2 +f2(); + +f2/*4x*/T/*5x*/y/*6x*/ +f2<() =>/*1y*/T/*2y*/y/*3y*/, () =>/*4y*/T/*5y*/y/*6y*/ +f2/*1z*/T/*2z*/y/*3z*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEachMarker(t, nil, func(t *testing.T, marker *fourslash.Marker, index int) { + markerName := marker.Name + valueOnly := markerName != nil && strings.HasSuffix(*markerName, "ValueOnly") + commitCharacters := &defaultCommitCharacters + if marker.Data != nil { + newId := marker.Data["newId"] + typeOnly := marker.Data["typeOnly"] + if newId != nil && newId.(bool) && !(typeOnly != nil && typeOnly.(bool)) { + commitCharacters = &[]string{".", ";"} + } + } + var includes []fourslash.CompletionsExpectedItem + var excludes []string + if valueOnly { + includes = []fourslash.CompletionsExpectedItem{ + "x", + } + excludes = []string{ + "Type", + } + } else { + includes = []fourslash.CompletionsExpectedItem{ + "Type", + } + excludes = []string{ + "x", + } + } + f.VerifyCompletions(t, marker, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: commitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: includes, + Excludes: excludes, + }, + }) + }) +} diff --git a/internal/fourslash/tests/gen/addDuplicateSetter_test.go b/internal/fourslash/tests/gen/addDuplicateSetter_test.go new file mode 100644 index 0000000000..8bb94a2008 --- /dev/null +++ b/internal/fourslash/tests/gen/addDuplicateSetter_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddDuplicateSetter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + set foo(value) { } + /**/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "set foo(value) { }") +} diff --git a/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_test.go b/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_test.go new file mode 100644 index 0000000000..d6d47126f9 --- /dev/null +++ b/internal/fourslash/tests/gen/addFunctionAboveMultiLineLambdaExpression_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddFunctionAboveMultiLineLambdaExpression(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +() => + // do something +0;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "function Foo() { }") +} diff --git a/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_test.go b/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_test.go new file mode 100644 index 0000000000..3fcf0ddd7e --- /dev/null +++ b/internal/fourslash/tests/gen/addInterfaceToNotSatisfyConstraint_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAddInterfaceToNotSatisfyConstraint(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + a: number; +} +/**/ +interface C { + x: T; +} + +var v2: C; // should not work` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "interface B { b: string; }") +} diff --git a/internal/fourslash/tests/gen/aliasToVarUsedAsType_test.go b/internal/fourslash/tests/gen/aliasToVarUsedAsType_test.go new file mode 100644 index 0000000000..bf5faeb5e9 --- /dev/null +++ b/internal/fourslash/tests/gen/aliasToVarUsedAsType_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestAliasToVarUsedAsType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +module A { +export var X; +import Z = A.X; +var v: Z; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/basicClassMembers_test.go b/internal/fourslash/tests/gen/basicClassMembers_test.go new file mode 100644 index 0000000000..d160527da4 --- /dev/null +++ b/internal/fourslash/tests/gen/basicClassMembers_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestBasicClassMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class n { + constructor (public x: number, public y: number, private z: string) { } +} +var t = new n(0, 1, '');` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEOF(t) + f.Insert(t, "t.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"x", "y"}, + Excludes: []string{"z"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionAfterNewline2_test.go b/internal/fourslash/tests/gen/completionAfterNewline2_test.go index 0a0ccd2120..05873a7df0 100644 --- a/internal/fourslash/tests/gen/completionAfterNewline2_test.go +++ b/internal/fourslash/tests/gen/completionAfterNewline2_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionAfterNewline2(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let foo = 5 as const /*1*/ /*2*/` diff --git a/internal/fourslash/tests/gen/completionAfterNewline_test.go b/internal/fourslash/tests/gen/completionAfterNewline_test.go index c64f858811..69832aa4f5 100644 --- a/internal/fourslash/tests/gen/completionAfterNewline_test.go +++ b/internal/fourslash/tests/gen/completionAfterNewline_test.go @@ -10,7 +10,7 @@ import ( func TestCompletionAfterNewline(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `let foo /*1*/ /*2*/ diff --git a/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go new file mode 100644 index 0000000000..0d84561e68 --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go @@ -0,0 +1,64 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteralRelativeImport5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @rootDirs: /repo/src1,/repo/src2/,/repo/generated1,/repo/generated2/ +// @Filename: /dir/secret_file.ts +/*secret_file*/ +// @Filename: /repo/src1/dir/test1.ts +import * as foo1 from ".//*import_as1*/ +import foo2 = require(".//*import_equals1*/ +var foo3 = require(".//*require1*/ +// @Filename: /repo/src2/dir/test2.ts +import * as foo1 from "..//*import_as2*/ +import foo2 = require("..//*import_equals2*/ +var foo3 = require("..//*require2*/ +// @Filename: /repo/src2/index.ts +import * as foo1 from ".//*import_as3*/ +import foo2 = require(".//*import_equals3*/ +var foo3 = require(".//*require3*/ +// @Filename: /repo/generated1/dir/f1.ts +/*f1*/ +// @Filename: /repo/generated2/dir/f2.ts +/*f2*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"import_as1", "import_equals1", "require1"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"f1", "f2", "test2"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as2", "import_equals2", "require2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir", "index"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as3", "import_equals3", "require3"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go new file mode 100644 index 0000000000..9835af9244 --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference7_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteral_quotePreference7(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +export const a = null; +// @filename: /b.ts +import { a } from './a'; + +const foo = { '#': null }; +foo[|./**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/b.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Label: "#", InsertText: ptrTo("['#']")}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go new file mode 100644 index 0000000000..122a3ec06a --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteral_quotePreference8_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteral_quotePreference8(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +export const a = null; +// @filename: /b.ts +import { a } from './a'; + +const foo = { '"a name\'s all good but it\'s better with more"': null }; +foo[|./**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/b.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Label: "\"a name's all good but it's better with more\"", InsertText: ptrTo("['\"a name\\'s all good but it\\'s better with more\"']")}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAtEOF1_test.go b/internal/fourslash/tests/gen/completionListAtEOF1_test.go new file mode 100644 index 0000000000..4fb15e54a1 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAtEOF1_test.go @@ -0,0 +1,27 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAtEOF1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `if(0 === ''.` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToEOF(t) + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"charAt"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAtEOF2_test.go b/internal/fourslash/tests/gen/completionListAtEOF2_test.go new file mode 100644 index 0000000000..8ddc7009ae --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAtEOF2_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAtEOF2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Shapes { + export class Point { + constructor(public x: number, public y: number) { } + } +} +var p = { + /**/ + var q = n; +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "it") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"items"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go index f7d4ca6ea0..3daf1f08ed 100644 --- a/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go +++ b/internal/fourslash/tests/gen/completionListInFunctionDeclaration_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInFunctionDeclaration(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `var a = 0; function foo(/**/` diff --git a/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go new file mode 100644 index 0000000000..a92f598b99 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go @@ -0,0 +1,70 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInObjectBindingPattern15(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + private xxx1 = 1; + protected xxx2 = 2; + public xxx3 = 3; + private static xxx4 = 4; + protected static xxx5 = 5; + public static xxx6 = 6; + foo() { + const { /*1*/ } = this; + const { /*2*/ } = Foo; + } +} + +const { /*3*/ } = new Foo(); +const { /*4*/ } = Foo;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx1", "xxx2", "xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx4", "xxx5", "xxx6"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx6"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go new file mode 100644 index 0000000000..66ced94e46 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInTypeLiteralInTypeParameter1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Foo { + one: string; + two: number; + 333: symbol; + '4four': boolean; + '5 five': object; + number: string; + Object: number; +} + +interface Bar { + foo: T; +} + +var foobar: Bar<{/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"one", "two", "\"333\"", "\"4four\"", "\"5 five\"", "number", "Object"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go b/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go index 9ceb4be3b3..e273ca809d 100644 --- a/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go +++ b/internal/fourslash/tests/gen/completionListInUnclosedFunction10_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInUnclosedFunction10(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface MyType { } diff --git a/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go b/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go index 1136bb85da..eb8e376e90 100644 --- a/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go +++ b/internal/fourslash/tests/gen/completionListInUnclosedFunction11_test.go @@ -9,7 +9,7 @@ import ( func TestCompletionListInUnclosedFunction11(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `interface MyType { } diff --git a/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go new file mode 100644 index 0000000000..afe0a1e5bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInstanceProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + private privateMethod() { } + private privateProperty; + + protected protectedMethod() { } + protected protectedProperty; + + public publicMethod() { } + public publicProperty; + + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; + + test() { + this./*1*/; + + var b: Base; + var c: C1; + + b./*2*/; + c./*3*/; + } +} + +class C1 extends Base { + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "protectedOverriddenMethod", "protectedOverriddenProperty", "test"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "test"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListModuleMembers_test.go b/internal/fourslash/tests/gen/completionListModuleMembers_test.go new file mode 100644 index 0000000000..616665fce4 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListModuleMembers_test.go @@ -0,0 +1,55 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListModuleMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` module Module { + var innerVariable = 1; + function innerFunction() { } + class innerClass { } + module innerModule { } + interface innerInterface {} + export var exportedVariable = 1; + export function exportedFunction() { } + export class exportedClass { } + export module exportedModule { export var exportedInnerModuleVariable = 1; } + export interface exportedInterface {} + } + +Module./*ValueReference*/; + +var x : Module./*TypeReference*/ + +class TestClass extends Module./*TypeReferenceInExtendsList*/ { } + +interface TestInterface implements Module./*TypeReferenceInImplementsList*/ { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"ValueReference", "TypeReferenceInExtendsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedFunction", "exportedVariable", "exportedClass", "exportedModule"}, + }, + }) + f.VerifyCompletions(t, []string{"TypeReference", "TypeReferenceInImplementsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedClass", "exportedInterface"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go new file mode 100644 index 0000000000..0c5dd0d3bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go @@ -0,0 +1,66 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListOfSplitInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + a: number; +} +interface I extends A { + i1: number; +} +interface I1 extends A { + i11: number; +} +interface B { + b: number; +} +interface B1 { + b1: number; +} +interface I extends B { + i2: number; +} +interface I1 extends B, B1 { + i12: number; +} +interface C { + c: number; +} +interface I extends C { + i3: number; +} +var ci: I; +ci./*1*/b; +var ci1: I1; +ci1./*2*/b;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"i1", "i2", "i3", "a", "b", "c"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"i11", "i12", "a", "b", "b1"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOnAliases2_test.go b/internal/fourslash/tests/gen/completionListOnAliases2_test.go new file mode 100644 index 0000000000..f3938d9391 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOnAliases2_test.go @@ -0,0 +1,120 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListOnAliases2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export interface I { } + export class C { + static property; + } + export enum E { + value = 0 + } + export module N { + export var v; + } + export var V = 0; + export function F() { } + export import A = M; +} + +import m = M; +import c = M.C; +import e = M.E; +import n = M.N; +import v = M.V; +import f = M.F; +import a = M.A; + +m./*1*/; +var tmp: m./*1Type*/; +c./*2*/; +e./*3*/; +n./*4*/; +v./*5*/; +f./*6*/; +a./*7*/; +var tmp2: a./*7Type*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "7"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"F", "C", "E", "N", "V", "A"}, + }, + }) + f.VerifyCompletions(t, []string{"1Type", "7Type"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"I", "C", "E", "A"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus([]fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "property"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}}), + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"value"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"v"}, + }, + }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"toFixed"}, + }, + }) + f.VerifyCompletions(t, "6", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"call"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go new file mode 100644 index 0000000000..104f295b76 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go @@ -0,0 +1,83 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesAccessors(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + get #x() { return 1 }; + set #x(value: number) { }; + y() {}; + } + class Bar extends Foo { + get #z() { return 1 }; + set #z(value: number) { }; + t() {}; + l; + constructor() { + this./*1*/ + class Baz { + get #z() { return 1 }; + set #z(value: number) { }; + get #u() { return 1 }; + set #u(value: number) { }; + v() {}; + k; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v", "k"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go new file mode 100644 index 0000000000..a52f1bec69 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesMethods(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + #x() {}; + y() {}; + } + class Bar extends Foo { + #z() {}; + t() {}; + constructor() { + this./*1*/ + class Baz { + #z() {}; + #u() {}; + v() {}; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNames_test.go b/internal/fourslash/tests/gen/completionListPrivateNames_test.go new file mode 100644 index 0000000000..0f23424e47 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNames_test.go @@ -0,0 +1,78 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNames(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + #x; + y; +} + +class Bar extends Foo { + #z; + t; + constructor() { + this./*1*/ + class Baz { + #z; + #u; + v; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } +} + +new Foo()./*4*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go new file mode 100644 index 0000000000..be5d12d598 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go @@ -0,0 +1,73 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + protected y; + constructor(protected x) {} + method() { this./*1*/; } +} +class D1 extends Base { + protected z; + method1() { this./*2*/; } +} +class D2 extends Base { + method2() { this./*3*/; } +} +class D3 extends D1 { + method2() { this./*4*/; } +} +var b: Base; +f./*5*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "5", nil) +} diff --git a/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go b/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go new file mode 100644 index 0000000000..ffd1a9a75c --- /dev/null +++ b/internal/fourslash/tests/gen/completionsAfterLessThanToken_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsAfterLessThanToken(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function f() { + const k: Record { + foo(): T; +} +function foo(/**/): string { return null; } +function foo(x: T): T { return null; }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "x: string") +} diff --git a/internal/fourslash/tests/gen/exportEqualNamespaceClassESModuleInterop_test.go b/internal/fourslash/tests/gen/exportEqualNamespaceClassESModuleInterop_test.go new file mode 100644 index 0000000000..70828dd486 --- /dev/null +++ b/internal/fourslash/tests/gen/exportEqualNamespaceClassESModuleInterop_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExportEqualNamespaceClassESModuleInterop(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @esModuleInterop: true +// @moduleResolution: node +// @target: es2015 +// @module: esnext +// @Filename: /node_modules/@bar/foo/index.d.ts +export = Foo; +declare class Foo {} +declare namespace Foo {} // class/namespace declaration causes the issue +// @Filename: /node_modules/foo/index.d.ts +import * as Foo from "@bar/foo"; +export = Foo; +// @Filename: /index.ts +import Foo from "foo"; +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/index.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"Foo"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/exportEqualsInterfaceA_test.go b/internal/fourslash/tests/gen/exportEqualsInterfaceA_test.go new file mode 100644 index 0000000000..996c3d9693 --- /dev/null +++ b/internal/fourslash/tests/gen/exportEqualsInterfaceA_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestExportEqualsInterfaceA(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: exportEqualsInterface_A.ts +interface A { + p1: number; +} +export = A; +/**/ +var i: I1; +var n: number = i.p1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "import I1 = require(\"exportEqualsInterface_A\");") +} diff --git a/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go new file mode 100644 index 0000000000..b4bd0a0136 --- /dev/null +++ b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go @@ -0,0 +1,52 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericTypeAliasIntersectionCompletions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` type MixinCtor = new () => A & B & { constructor: MixinCtor }; + function merge(a: { prototype: A }, b: { prototype: B }): MixinCtor { + let merged = function() { } + Object.assign(merged.prototype, a.prototype, b.prototype); + return >merged; + } + + class TreeNode { + value: any; + } + + abstract class LeftSideNode extends TreeNode { + abstract right(): TreeNode; + left(): TreeNode { + return null; + } + } + + abstract class RightSideNode extends TreeNode { + abstract left(): TreeNode; + right(): TreeNode { + return null; + }; + } + + var obj = new (merge(LeftSideNode, RightSideNode))(); + obj./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"right", "left", "value", "constructor"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/globalThisCompletion_test.go b/internal/fourslash/tests/gen/globalThisCompletion_test.go new file mode 100644 index 0000000000..d85580f9a8 --- /dev/null +++ b/internal/fourslash/tests/gen/globalThisCompletion_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGlobalThisCompletion(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @target: esnext +// @Filename: test.js +(typeof foo !== "undefined" + ? foo + : {} +)./**/; +// @Filename: someLib.d.ts +declare var foo: typeof globalThis;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", nil) +} diff --git a/internal/fourslash/tests/gen/importTypeCompletions2_test.go b/internal/fourslash/tests/gen/importTypeCompletions2_test.go new file mode 100644 index 0000000000..7992f2ad65 --- /dev/null +++ b/internal/fourslash/tests/gen/importTypeCompletions2_test.go @@ -0,0 +1,31 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportTypeCompletions2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @target: esnext +// @filename: /foo.ts +export const Foo = {}; +// @filename: /bar.ts +[|import type F/**/|]` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/bar.ts") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/importValueUsedAsType_test.go b/internal/fourslash/tests/gen/importValueUsedAsType_test.go new file mode 100644 index 0000000000..a77de577a6 --- /dev/null +++ b/internal/fourslash/tests/gen/importValueUsedAsType_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestImportValueUsedAsType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +module A { + export var X; + import Z = A.X; + var v: Z; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_test.go b/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_test.go new file mode 100644 index 0000000000..fc55d4ba7a --- /dev/null +++ b/internal/fourslash/tests/gen/indexSignatureWithoutAnnotation_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestIndexSignatureWithoutAnnotation(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface B { + 1: any; +} +interface C { + [s]: any; +} +interface D extends B, C /**/ { +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_test.go b/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_test.go new file mode 100644 index 0000000000..12d656ce7b --- /dev/null +++ b/internal/fourslash/tests/gen/insertArgumentBeforeOverloadedConstructor_test.go @@ -0,0 +1,23 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertArgumentBeforeOverloadedConstructor(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `alert(/**/100); + +class OverloadedMonster { + constructor(); + constructor(name) { } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "'1', ") +} diff --git a/internal/fourslash/tests/gen/insertMethodCallAboveOthers_test.go b/internal/fourslash/tests/gen/insertMethodCallAboveOthers_test.go new file mode 100644 index 0000000000..06c77c0f3b --- /dev/null +++ b/internal/fourslash/tests/gen/insertMethodCallAboveOthers_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertMethodCallAboveOthers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/ +paired.reduce(); +paired.map(() => undefined);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "paired.reduce();") +} diff --git a/internal/fourslash/tests/gen/insertPublicBeforeSetter_test.go b/internal/fourslash/tests/gen/insertPublicBeforeSetter_test.go new file mode 100644 index 0000000000..2248f8e775 --- /dev/null +++ b/internal/fourslash/tests/gen/insertPublicBeforeSetter_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertPublicBeforeSetter(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class C { + /**/set Bar(bar:string) {} +} +var o2 = { set Foo(val:number) { } };` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "public ") +} diff --git a/internal/fourslash/tests/gen/insertSecondTryCatchBlock_test.go b/internal/fourslash/tests/gen/insertSecondTryCatchBlock_test.go new file mode 100644 index 0000000000..6ba6bc8d36 --- /dev/null +++ b/internal/fourslash/tests/gen/insertSecondTryCatchBlock_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertSecondTryCatchBlock(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `try {} catch(e) { } +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "try {} catch(e) { }") +} diff --git a/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_test.go b/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_test.go new file mode 100644 index 0000000000..776aa62b14 --- /dev/null +++ b/internal/fourslash/tests/gen/insertVarAfterEmptyTypeParamList_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestInsertVarAfterEmptyTypeParamList(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Dictionary<> { } +var x; +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "var y;\n") +} diff --git a/internal/fourslash/tests/gen/javaScriptClass4_test.go b/internal/fourslash/tests/gen/javaScriptClass4_test.go new file mode 100644 index 0000000000..b3f93f2d4b --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptClass4_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptClass4(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js +class Foo { + constructor() { + /** + * @type {string} + */ + this.baz = null; + } +} +var x = new Foo(); +x/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ".baz.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "substring"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModules13_test.go b/internal/fourslash/tests/gen/javaScriptModules13_test.go new file mode 100644 index 0000000000..b15e73f9e3 --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModules13_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptModules13(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: myMod.js +if (true) { + module.exports = { a: 10 }; +} +var invisible = true; +// @Filename: isGlobal.js +var y = 10; +// @Filename: consumer.js +var x = require('./myMod'); +/**/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "consumer.js") + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextGlobalsOrKeywords)), Label: "y"}}, + Excludes: []string{"invisible"}, + }, + }) + f.Insert(t, "x.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindField), Label: "a"}}, + }, + }) + f.Insert(t, "a.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModules19_test.go b/internal/fourslash/tests/gen/javaScriptModules19_test.go new file mode 100644 index 0000000000..69f5842ead --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModules19_test.go @@ -0,0 +1,61 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptModules19(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @Filename: myMod.js +var x = { a: 10 }; +module.exports = x; +// @Filename: isGlobal.js +var y = 10; +// @Filename: consumer.js +var x = require('./myMod'); +/**/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "consumer.js") + f.GoToMarker(t, "") + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextGlobalsOrKeywords)), Label: "y"}}, + Excludes: []string{"invisible"}, + }, + }) + f.Insert(t, "x.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindField), Label: "a"}}, + }, + }) + f.Insert(t, "a.") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{Kind: ptrTo(lsproto.CompletionItemKindMethod), Label: "toFixed"}}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/javaScriptModulesError1_test.go b/internal/fourslash/tests/gen/javaScriptModulesError1_test.go new file mode 100644 index 0000000000..e37b7d41be --- /dev/null +++ b/internal/fourslash/tests/gen/javaScriptModulesError1_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJavaScriptModulesError1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowNonTsExtensions: true +// @Filename: Foo.js +define('mod1', ['a'], /**/function(a, b) { + +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") +} diff --git a/internal/fourslash/tests/gen/jsxQualifiedTagCompletion_test.go b/internal/fourslash/tests/gen/jsxQualifiedTagCompletion_test.go new file mode 100644 index 0000000000..632f3ed8df --- /dev/null +++ b/internal/fourslash/tests/gen/jsxQualifiedTagCompletion_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestJsxQualifiedTagCompletion(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `//@Filename: file.tsx + declare var React: any; + namespace NS { + export var Foo: any = null; + } + const j = Hello!/**/ +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ""}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/memberCompletionFromFunctionCall_test.go b/internal/fourslash/tests/gen/memberCompletionFromFunctionCall_test.go new file mode 100644 index 0000000000..04714210f9 --- /dev/null +++ b/internal/fourslash/tests/gen/memberCompletionFromFunctionCall_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMemberCompletionFromFunctionCall(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare interface ifoo { + text: (value: any) => ifoo; +} +declare var foo: ifoo; +foo.text(function() { })/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"text"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/memberListInFunctionCall_test.go b/internal/fourslash/tests/gen/memberListInFunctionCall_test.go new file mode 100644 index 0000000000..cb37ffac13 --- /dev/null +++ b/internal/fourslash/tests/gen/memberListInFunctionCall_test.go @@ -0,0 +1,34 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMemberListInFunctionCall(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `function aa(x: any) {} +aa({ + "1": function () { + var b = ""; + b/**/; + } +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"charAt"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/memberlistOnDDot_test.go b/internal/fourslash/tests/gen/memberlistOnDDot_test.go new file mode 100644 index 0000000000..2fb321565b --- /dev/null +++ b/internal/fourslash/tests/gen/memberlistOnDDot_test.go @@ -0,0 +1,21 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestMemberlistOnDDot(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `var q = ''; +q/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, ".") + f.Insert(t, ".") + f.VerifyCompletions(t, nil, nil) +} diff --git a/internal/fourslash/tests/gen/packageJsonImportsFailedLookups_test.go b/internal/fourslash/tests/gen/packageJsonImportsFailedLookups_test.go new file mode 100644 index 0000000000..365843622a --- /dev/null +++ b/internal/fourslash/tests/gen/packageJsonImportsFailedLookups_test.go @@ -0,0 +1,29 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPackageJsonImportsFailedLookups(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a/b/c/d/e/tsconfig.json +{ "compilerOptions": { "module": "nodenext" } } +// @Filename: /a/b/c/d/e/package.json +{ + "name": "app", + "imports": { + "#utils": "lodash" + } +} +// @Filename: /a/b/node_modules/lodash/index.d.ts +export function add(a: number, b: number): number; +// @Filename: /a/b/c/d/e/index.ts +import { add } from "#utils";` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToFile(t, "/a/b/c/d/e/index.ts") +} diff --git a/internal/fourslash/tests/gen/publicBreak_test.go b/internal/fourslash/tests/gen/publicBreak_test.go new file mode 100644 index 0000000000..f2098b76b9 --- /dev/null +++ b/internal/fourslash/tests/gen/publicBreak_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestPublicBreak(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `public break; +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, " ") +} diff --git a/internal/fourslash/tests/gen/recursiveGenerics2_test.go b/internal/fourslash/tests/gen/recursiveGenerics2_test.go new file mode 100644 index 0000000000..1d38fe1297 --- /dev/null +++ b/internal/fourslash/tests/gen/recursiveGenerics2_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestRecursiveGenerics2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class S18 extends S18 { } +/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "(new S18()).S18 = 0;") +} diff --git a/internal/fourslash/tests/gen/satisfiesOperatorCompletion_test.go b/internal/fourslash/tests/gen/satisfiesOperatorCompletion_test.go index 94e8d7b800..0029a69683 100644 --- a/internal/fourslash/tests/gen/satisfiesOperatorCompletion_test.go +++ b/internal/fourslash/tests/gen/satisfiesOperatorCompletion_test.go @@ -9,7 +9,7 @@ import ( func TestSatisfiesOperatorCompletion(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type T = number; var x; diff --git a/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go b/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go new file mode 100644 index 0000000000..816d2af6cb --- /dev/null +++ b/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go @@ -0,0 +1,78 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestThisPredicateFunctionCompletions03(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class RoyalGuard { + isLeader(): this is LeadGuard { + return this instanceof LeadGuard; + } + isFollower(): this is FollowerGuard { + return this instanceof FollowerGuard; + } + } + + class LeadGuard extends RoyalGuard { + lead(): void {}; + } + + class FollowerGuard extends RoyalGuard { + follow(): void {}; + } + + let a: RoyalGuard = new FollowerGuard(); + if (a.is/*1*/Leader()) { + a./*2*/; + } + else if (a.is/*3*/Follower()) { + a./*4*/; + } + + interface GuardInterface { + isLeader(): this is LeadGuard; + isFollower(): this is FollowerGuard; + } + + let b: GuardInterface; + if (b.is/*5*/Leader()) { + b./*6*/; + } + else if (b.is/*7*/Follower()) { + b./*8*/; + } + + let leader/*13*/Status = a.isLeader(); + function isLeaderGuard(g: RoyalGuard) { + return g.isLeader(); + } + let checked/*14*/LeaderStatus = isLeader/*15*/Guard(a);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"2", "6"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"lead", "isLeader", "isFollower"}, + }, + }) + f.VerifyCompletions(t, []string{"4", "8"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"follow", "isLeader", "isFollower"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/tsxIncrementalServer_test.go b/internal/fourslash/tests/gen/tsxIncrementalServer_test.go new file mode 100644 index 0000000000..30ef797b14 --- /dev/null +++ b/internal/fourslash/tests/gen/tsxIncrementalServer_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTsxIncrementalServer(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "<") + f.Insert(t, "div") + f.Insert(t, " ") + f.Insert(t, " id") + f.Insert(t, "=") + f.Insert(t, "\"foo") + f.Insert(t, "\"") + f.Insert(t, ">") +} diff --git a/internal/fourslash/tests/gen/tsxIncremental_test.go b/internal/fourslash/tests/gen/tsxIncremental_test.go new file mode 100644 index 0000000000..14bbd3c5e4 --- /dev/null +++ b/internal/fourslash/tests/gen/tsxIncremental_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTsxIncremental(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "<") + f.Insert(t, "div") + f.Insert(t, " ") + f.Insert(t, " id") + f.Insert(t, "=") + f.Insert(t, "\"foo") + f.Insert(t, "\"") + f.Insert(t, ">") +} diff --git a/internal/fourslash/tests/gen/typeAboveNumberLiteralExpressionStatement_test.go b/internal/fourslash/tests/gen/typeAboveNumberLiteralExpressionStatement_test.go new file mode 100644 index 0000000000..64b4c8000f --- /dev/null +++ b/internal/fourslash/tests/gen/typeAboveNumberLiteralExpressionStatement_test.go @@ -0,0 +1,20 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTypeAboveNumberLiteralExpressionStatement(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +// foo +1;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToBOF(t) + f.Insert(t, "var x;\n") +} diff --git a/internal/fourslash/tests/gen/typeCheckObjectInArrayLiteral_test.go b/internal/fourslash/tests/gen/typeCheckObjectInArrayLiteral_test.go new file mode 100644 index 0000000000..769bbbfd8f --- /dev/null +++ b/internal/fourslash/tests/gen/typeCheckObjectInArrayLiteral_test.go @@ -0,0 +1,19 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestTypeCheckObjectInArrayLiteral(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `declare function create(initialValues); +create([{}]);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToPosition(t, 0) + f.Insert(t, "") +} diff --git a/internal/fourslash/tests/gen/updateToClassStatics_test.go b/internal/fourslash/tests/gen/updateToClassStatics_test.go new file mode 100644 index 0000000000..1a89962fa0 --- /dev/null +++ b/internal/fourslash/tests/gen/updateToClassStatics_test.go @@ -0,0 +1,33 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestUpdateToClassStatics(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module TypeScript { + export class PullSymbol {} + export class Diagnostic {} + export class SymbolAndDiagnostics { + constructor(public symbol: TSymbol, + public diagnostics: Diagnostic) { + } + /**/ + public static create(symbol: TSymbol, diagnostics: Diagnostic): SymbolAndDiagnostics { + return new SymbolAndDiagnostics(symbol, diagnostics); + } + } +} +module TypeScript { + var x : TypeScript.SymbolAndDiagnostics; +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.GoToMarker(t, "") + f.Insert(t, "someNewProperty = 0;") +} diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 1e47beeaf2..32864058ac 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2182,6 +2182,22 @@ func getLineOfPosition(file *ast.SourceFile, pos int) int { return line } +func getLineEndOfPosition(file *ast.SourceFile, pos int) int { + line := getLineOfPosition(file, pos) + lineStarts := scanner.GetLineStarts(file) + var lastCharPos int + if line+1 >= len(lineStarts) { + lastCharPos = file.End() + } else { + lastCharPos = int(lineStarts[line+1]) - 1 + } + fullText := file.Text() + if lastCharPos > 0 && lastCharPos < len(fullText) && fullText[lastCharPos] == '\n' && fullText[lastCharPos-1] == '\r' { + return lastCharPos - 1 + } + return lastCharPos +} + func isClassLikeMemberCompletion(symbol *ast.Symbol, location *ast.Node, file *ast.SourceFile) bool { // !!! class member completions return false @@ -2723,7 +2739,7 @@ func getClosestSymbolDeclaration(contextToken *ast.Node, location *ast.Node) *as }) if closestDeclaration == nil { - closestDeclaration = ast.FindAncestorOrQuit(contextToken, func(node *ast.Node) ast.FindAncestorResult { + closestDeclaration = ast.FindAncestorOrQuit(location, func(node *ast.Node) ast.FindAncestorResult { if ast.IsFunctionBlock(node) || isArrowFunctionBody(node) || ast.IsBindingPattern(node) { return ast.FindAncestorQuit } @@ -4338,7 +4354,7 @@ func isSolelyIdentifierDefinitionLocation( return false } ancestorVariableDeclaration := ast.FindAncestor(parent, ast.IsVariableDeclaration) - if ancestorVariableDeclaration != nil && getLineOfPosition(file, contextToken.End()) < position { + if ancestorVariableDeclaration != nil && getLineEndOfPosition(file, contextToken.End()) < position { // let a // | return false diff --git a/internal/ls/completions_test.go b/internal/ls/completions_test.go index 58edd4b59b..2b294e1087 100644 --- a/internal/ls/completions_test.go +++ b/internal/ls/completions_test.go @@ -2051,7 +2051,7 @@ func runTest(t *testing.T, files map[string]string, expected map[string]*testCas if mainFileName == "" { mainFileName = defaultMainFileName } - parsedFiles := make(map[string]any) + parsedFiles := make(map[string]string) parsedFiles[defaultTsconfigFileName] = `{}` var markerPositions map[string]*fourslash.Marker for fileName, content := range files { @@ -2126,9 +2126,9 @@ func assertIncludesItem(t *testing.T, actual *lsproto.CompletionList, expected * return false } -func createLanguageService(ctx context.Context, fileName string, files map[string]any) (*ls.LanguageService, func()) { +func createLanguageService(ctx context.Context, fileName string, files map[string]string) (*ls.LanguageService, func()) { projectService, _ := projecttestutil.Setup(files, nil) - projectService.OpenFile(fileName, files[fileName].(string), core.GetScriptKindFromFileName(fileName), "") + projectService.OpenFile(fileName, files[fileName], core.GetScriptKindFromFileName(fileName), "") project := projectService.Projects()[0] return project.GetLanguageServiceForRequest(ctx) } diff --git a/internal/ls/definition_test.go b/internal/ls/definition_test.go index a932e3eed9..29cc6aa134 100644 --- a/internal/ls/definition_test.go +++ b/internal/ls/definition_test.go @@ -54,7 +54,7 @@ func runDefinitionTest(t *testing.T, input string, expected map[string]lsproto.D file := testData.Files[0].FileName() markerPositions := testData.MarkerPositions ctx := projecttestutil.WithRequestID(t.Context()) - languageService, done := createLanguageService(ctx, file, map[string]any{ + languageService, done := createLanguageService(ctx, file, map[string]string{ file: testData.Files[0].Content, }) defer done() diff --git a/internal/ls/findallreferences_test.go b/internal/ls/findallreferences_test.go index 7030fd85c7..df9c521cf8 100644 --- a/internal/ls/findallreferences_test.go +++ b/internal/ls/findallreferences_test.go @@ -15,7 +15,7 @@ func runFindReferencesTest(t *testing.T, input string, expectedLocations map[str testData := fourslash.ParseTestData(t, input, "/file1.ts") markerPositions := testData.MarkerPositions ctx := projecttestutil.WithRequestID(t.Context()) - service, done := createLanguageService(ctx, testData.Files[0].FileName(), map[string]any{ + service, done := createLanguageService(ctx, testData.Files[0].FileName(), map[string]string{ testData.Files[0].FileName(): testData.Files[0].Content, }) defer done() @@ -23,7 +23,7 @@ func runFindReferencesTest(t *testing.T, input string, expectedLocations map[str // for each marker location, calculate the expected ref location ahead of time so we don't have to re-calculate each location for every reference call allExpectedLocations := map[lsproto.Location]string{} for _, expectedRange := range testData.Ranges { - allExpectedLocations[*service.GetExpectedReferenceFromMarker(expectedRange.FileName, expectedRange.Position)] = expectedRange.Name + allExpectedLocations[*service.GetExpectedReferenceFromMarker(expectedRange.FileName, expectedRange.Position)] = *expectedRange.Name } for requestMarkerName, expectedSet := range expectedLocations { diff --git a/internal/ls/signaturehelp.go b/internal/ls/signaturehelp.go index 40f2aecf3d..8ad8567e21 100644 --- a/internal/ls/signaturehelp.go +++ b/internal/ls/signaturehelp.go @@ -908,24 +908,10 @@ func getArgumentOrParameterListAndIndex(node *ast.Node, sourceFile *ast.SourceFi // - Between the type arguments and the arguments (greater than token) // - On the target of the call (parent.func) // - On the 'new' keyword in a 'new' expression - var arguments *ast.NodeList - switch node.Parent.Kind { - case ast.KindCallExpression: - arguments = node.Parent.AsCallExpression().Arguments - case ast.KindNewExpression: - arguments = node.Parent.AsNewExpression().Arguments - case ast.KindParenthesizedExpression: - arguments = node.Parent.AsParenthesizedExpression().ExpressionBase.NodeBase.Node.ArgumentList() // !!! - case ast.KindMethodDeclaration: - arguments = node.Parent.AsMethodDeclaration().FunctionLikeWithBodyBase.Parameters - case ast.KindFunctionExpression: - arguments = node.Parent.AsFunctionExpression().FunctionLikeWithBodyBase.Parameters - case ast.KindArrowFunction: - arguments = node.Parent.AsArrowFunction().FunctionLikeWithBodyBase.Parameters - } + list := findContainingList(node, sourceFile) // Find the index of the argument that contains the node. - argumentIndex := getArgumentIndex(node, arguments, sourceFile, c) - return arguments, argumentIndex + argumentIndex := getArgumentIndex(node, list, sourceFile, c) + return list, argumentIndex } } diff --git a/internal/ls/signaturehelp_test.go b/internal/ls/signaturehelp_test.go index 4b5eeff285..36be7655de 100644 --- a/internal/ls/signaturehelp_test.go +++ b/internal/ls/signaturehelp_test.go @@ -1021,7 +1021,7 @@ func runSignatureHelpTest(t *testing.T, input string, expected map[string]verify file := testData.Files[0].FileName() markerPositions := testData.MarkerPositions ctx := projecttestutil.WithRequestID(t.Context()) - languageService, done := createLanguageService(ctx, file, map[string]any{ + languageService, done := createLanguageService(ctx, file, map[string]string{ file: testData.Files[0].Content, }) defer done() diff --git a/internal/ls/symbols.go b/internal/ls/symbols.go index 59079aa113..c227ca1a29 100644 --- a/internal/ls/symbols.go +++ b/internal/ls/symbols.go @@ -12,10 +12,181 @@ import ( "github.com/microsoft/typescript-go/internal/compiler" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/stringutil" ) +func (l *LanguageService) ProvideDocumentSymbols(ctx context.Context, documentURI lsproto.DocumentUri) ([]*lsproto.DocumentSymbol, error) { + _, file := l.getProgramAndFile(documentURI) + symbols := l.getDocumentSymbolsForChildren(ctx, file.AsNode()) + return symbols, nil +} + +func (l *LanguageService) getDocumentSymbolsForChildren(ctx context.Context, node *ast.Node) []*lsproto.DocumentSymbol { + var symbols []*lsproto.DocumentSymbol + addSymbolForNode := func(node *ast.Node, children []*lsproto.DocumentSymbol) { + symbol := l.newDocumentSymbol(node, children) + if symbol != nil { + symbols = append(symbols, symbol) + } + } + var visit func(*ast.Node) bool + getSymbolsForChildren := func(node *ast.Node) []*lsproto.DocumentSymbol { + var result []*lsproto.DocumentSymbol + if node != nil { + saveSymbols := symbols + symbols = nil + node.ForEachChild(visit) + result = symbols + symbols = saveSymbols + } + return result + } + visit = func(node *ast.Node) bool { + if ctx != nil && ctx.Err() != nil { + return true + } + switch node.Kind { + case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration, ast.KindEnumDeclaration: + addSymbolForNode(node, getSymbolsForChildren(node)) + case ast.KindModuleDeclaration: + addSymbolForNode(node, getSymbolsForChildren(getInteriorModule(node))) + case ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindMethodDeclaration, ast.KindGetAccessor, + ast.KindSetAccessor, ast.KindConstructor: + addSymbolForNode(node, getSymbolsForChildren(node.Body())) + case ast.KindVariableDeclaration, ast.KindBindingElement, ast.KindPropertyAssignment, ast.KindPropertyDeclaration: + name := node.Name() + if name != nil { + if ast.IsBindingPattern(name) { + visit(name) + } else { + addSymbolForNode(node, getSymbolsForChildren(node.Initializer())) + } + } + case ast.KindMethodSignature, ast.KindPropertySignature, ast.KindCallSignature, ast.KindConstructSignature, ast.KindIndexSignature, + ast.KindEnumMember, ast.KindShorthandPropertyAssignment, ast.KindTypeAliasDeclaration: + addSymbolForNode(node, nil) + default: + node.ForEachChild(visit) + } + return false + } + node.ForEachChild(visit) + return symbols +} + +func (l *LanguageService) newDocumentSymbol(node *ast.Node, children []*lsproto.DocumentSymbol) *lsproto.DocumentSymbol { + result := new(lsproto.DocumentSymbol) + file := ast.GetSourceFileOfNode(node) + nodeStartPos := scanner.SkipTrivia(file.Text(), node.Pos()) + name := ast.GetNameOfDeclaration(node) + var text string + var nameStartPos, nameEndPos int + if ast.IsModuleDeclaration(node) && !ast.IsAmbientModule(node) { + text = getModuleName(node) + nameStartPos = scanner.SkipTrivia(file.Text(), name.Pos()) + nameEndPos = getInteriorModule(node).Name().End() + } else if name != nil { + text = getTextOfName(name) + nameStartPos = max(scanner.SkipTrivia(file.Text(), name.Pos()), nodeStartPos) + nameEndPos = max(name.End(), nodeStartPos) + } else { + text = getUnnamedNodeLabel(node) + nameStartPos = nodeStartPos + nameEndPos = nodeStartPos + } + if text == "" { + return nil + } + result.Name = text + result.Kind = getSymbolKindFromNode(node) + result.Range = lsproto.Range{ + Start: l.converters.PositionToLineAndCharacter(file, core.TextPos(nodeStartPos)), + End: l.converters.PositionToLineAndCharacter(file, core.TextPos(node.End())), + } + result.SelectionRange = lsproto.Range{ + Start: l.converters.PositionToLineAndCharacter(file, core.TextPos(nameStartPos)), + End: l.converters.PositionToLineAndCharacter(file, core.TextPos(nameEndPos)), + } + if children == nil { + children = []*lsproto.DocumentSymbol{} + } + result.Children = &children + return result +} + +func getTextOfName(node *ast.Node) string { + switch node.Kind { + case ast.KindIdentifier, ast.KindPrivateIdentifier, ast.KindNumericLiteral: + return node.Text() + case ast.KindStringLiteral: + return "\"" + printer.EscapeString(node.Text(), '"') + "\"" + case ast.KindNoSubstitutionTemplateLiteral: + return "`" + printer.EscapeString(node.Text(), '`') + "`" + case ast.KindComputedPropertyName: + if ast.IsStringOrNumericLiteralLike(node.Expression()) { + return getTextOfName(node.Expression()) + } + } + return scanner.GetTextOfNode(node) +} + +func getUnnamedNodeLabel(node *ast.Node) string { + switch node.Kind { + case ast.KindFunctionExpression, ast.KindArrowFunction: + if ast.IsCallExpression(node.Parent) { + name := getCallExpressionName(node.Parent.Expression()) + if name != "" { + return name + "() callback" + } + } + return "" + case ast.KindClassExpression: + return "" + case ast.KindConstructor: + return "constructor" + case ast.KindCallSignature: + return "()" + case ast.KindConstructSignature: + return "new()" + case ast.KindIndexSignature: + return "[]" + } + return "" +} + +func getCallExpressionName(node *ast.Node) string { + switch node.Kind { + case ast.KindIdentifier, ast.KindPrivateIdentifier: + return node.Text() + case ast.KindPropertyAccessExpression: + left := getCallExpressionName(node.Expression()) + right := getCallExpressionName(node.Name()) + if left != "" { + return left + "." + right + } + return right + } + return "" +} + +func getInteriorModule(node *ast.Node) *ast.Node { + for node.Body() != nil && ast.IsModuleDeclaration(node.Body()) { + node = node.Body() + } + return node +} + +func getModuleName(node *ast.Node) string { + result := node.Name().Text() + for node.Body() != nil && ast.IsModuleDeclaration(node.Body()) { + node = node.Body() + result = result + "." + node.Name().Text() + } + return result +} + type DeclarationInfo struct { name string declaration *ast.Node diff --git a/internal/ls/utilities.go b/internal/ls/utilities.go index 716aea5eea..9f82ce42f9 100644 --- a/internal/ls/utilities.go +++ b/internal/ls/utilities.go @@ -1600,3 +1600,31 @@ func findPrecedingMatchingToken(token *ast.Node, matchingTokenKind ast.Kind, sou } } } + +func findContainingList(node *ast.Node, file *ast.SourceFile) *ast.NodeList { + // The node might be a list element (nonsynthetic) or a comma (synthetic). Either way, it will + // be parented by the container of the SyntaxList, not the SyntaxList itself. + var list *ast.NodeList + visitNode := func(n *ast.Node, visitor *ast.NodeVisitor) *ast.Node { + return n + } + visitNodes := func(nodes *ast.NodeList, visitor *ast.NodeVisitor) *ast.NodeList { + if nodes != nil && RangeContainsRange(nodes.Loc, node.Loc) { + list = nodes + } + return nodes + } + nodeVisitor := ast.NewNodeVisitor(core.Identity, nil, ast.NodeVisitorHooks{ + VisitNode: visitNode, + VisitToken: visitNode, + VisitNodes: visitNodes, + VisitModifiers: func(modifiers *ast.ModifierList, visitor *ast.NodeVisitor) *ast.ModifierList { + if modifiers != nil { + visitNodes(&modifiers.NodeList, visitor) + } + return modifiers + }, + }) + astnav.VisitEachChildAndJSDoc(node.Parent, file, nodeVisitor) + return list +} diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 234d58f504..5143728de7 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -29,7 +29,6 @@ type ServerOptions struct { Err io.Writer Cwd string - NewLine core.NewLineKind FS vfs.FS DefaultLibraryPath string TypingsLocation string @@ -50,7 +49,6 @@ func NewServer(opts *ServerOptions) *Server { pendingClientRequests: make(map[lsproto.ID]pendingClientRequest), pendingServerRequests: make(map[lsproto.ID]chan *lsproto.ResponseMessage), cwd: opts.Cwd, - newLine: opts.NewLine, fs: opts.FS, defaultLibraryPath: opts.DefaultLibraryPath, typingsLocation: opts.TypingsLocation, @@ -134,7 +132,6 @@ type Server struct { pendingServerRequestsMu sync.Mutex cwd string - newLine core.NewLineKind fs vfs.FS defaultLibraryPath string typingsLocation string @@ -176,11 +173,6 @@ func (s *Server) GetCurrentDirectory() string { return s.cwd } -// NewLine implements project.ServiceHost. -func (s *Server) NewLine() string { - return s.newLine.GetNewLineCharacter() -} - // Trace implements project.ServiceHost. func (s *Server) Trace(msg string) { s.Log(msg) @@ -498,6 +490,8 @@ func (s *Server) handleRequestOrNotification(ctx context.Context, req *lsproto.R return s.handleDocumentOnTypeFormat(ctx, req) case *lsproto.WorkspaceSymbolParams: return s.handleWorkspaceSymbol(ctx, req) + case *lsproto.DocumentSymbolParams: + return s.handleDocumentSymbol(ctx, req) default: switch req.Method { case lsproto.MethodShutdown: @@ -578,6 +572,9 @@ func (s *Server) handleInitialize(req *lsproto.RequestMessage) { WorkspaceSymbolProvider: &lsproto.BooleanOrWorkspaceSymbolOptions{ Boolean: ptrTo(true), }, + DocumentSymbolProvider: &lsproto.BooleanOrDocumentSymbolOptions{ + Boolean: ptrTo(true), + }, }, }) } @@ -786,6 +783,19 @@ func (s *Server) handleWorkspaceSymbol(ctx context.Context, req *lsproto.Request return nil } +func (s *Server) handleDocumentSymbol(ctx context.Context, req *lsproto.RequestMessage) error { + params := req.Params.(*lsproto.DocumentSymbolParams) + project := s.projectService.EnsureDefaultProjectForURI(params.TextDocument.Uri) + languageService, done := project.GetLanguageServiceForRequest(ctx) + defer done() + hover, err := languageService.ProvideDocumentSymbols(ctx, params.TextDocument.Uri) + if err != nil { + return err + } + s.sendResult(req.ID, hover) + return nil +} + func (s *Server) Log(msg ...any) { fmt.Fprintln(s.stderr, msg...) } diff --git a/internal/module/resolver.go b/internal/module/resolver.go index d054c1846d..6071d8535a 100644 --- a/internal/module/resolver.go +++ b/internal/module/resolver.go @@ -34,6 +34,10 @@ func continueSearching() *resolved { return nil } +func unresolved() *resolved { + return &resolved{} +} + type resolutionKindSpecificLoader = func(extensions extensions, candidate string, onlyRecordFailures bool) *resolved type resolutionState struct { @@ -54,7 +58,7 @@ type resolutionState struct { resolvedPackageDirectory bool failedLookupLocations []string affectingLocations []string - diagnostics []ast.Diagnostic + diagnostics []*ast.Diagnostic } func newResolutionState( @@ -748,10 +752,104 @@ func (r *resolutionState) loadModuleFromTargetExportOrImport(extensions extensio } func (r *resolutionState) tryLoadInputFileForPath(finalPath string, entry string, packagePath string, isImports bool) *resolved { - // !!! + // Replace any references to outputs for files in the program with the input files to support package self-names used with outDir + if !r.isConfigLookup && + (r.compilerOptions.DeclarationDir != "" || r.compilerOptions.OutDir != "") && + !strings.Contains(finalPath, "/node_modules/") && + (r.compilerOptions.ConfigFilePath == "" || tspath.ContainsPath( + tspath.GetDirectoryPath(packagePath), + r.compilerOptions.ConfigFilePath, + tspath.ComparePathsOptions{ + UseCaseSensitiveFileNames: r.resolver.host.FS().UseCaseSensitiveFileNames(), + CurrentDirectory: r.resolver.host.GetCurrentDirectory(), + }, + )) { + + // Note: this differs from Strada's tryLoadInputFileForPath in that it + // does not attempt to perform "guesses", instead requring a clear root indicator. + + var rootDir string + if r.compilerOptions.RootDir != "" { + // A `rootDir` compiler option strongly indicates the root location + rootDir = r.compilerOptions.RootDir + } else if r.compilerOptions.Composite.IsTrue() && r.compilerOptions.ConfigFilePath != "" { + // A `composite` project is using project references and has it's common src dir set to `.`, so it shouldn't need to check any other locations + rootDir = r.compilerOptions.ConfigFilePath + } else { + diagnostic := ast.NewDiagnostic( + nil, + core.TextRange{}, + core.IfElse(isImports, + diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate, + diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate, + ), + core.IfElse(entry == "", ".", entry), // replace empty string with `.` - the reverse of the operation done when entries are built - so main entrypoint errors don't look weird + packagePath, + ) + r.diagnostics = append(r.diagnostics, diagnostic) + return unresolved() + } + + candidateDirectories := r.getOutputDirectoriesForBaseDirectory(rootDir) + for _, candidateDir := range candidateDirectories { + if tspath.ContainsPath(candidateDir, finalPath, tspath.ComparePathsOptions{ + UseCaseSensitiveFileNames: r.resolver.host.FS().UseCaseSensitiveFileNames(), + CurrentDirectory: r.resolver.host.GetCurrentDirectory(), + }) { + // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension + pathFragment := finalPath[len(candidateDir)+1:] // +1 to also remove directory separator + possibleInputBase := tspath.CombinePaths(rootDir, pathFragment) + jsAndDtsExtensions := []string{tspath.ExtensionMjs, tspath.ExtensionCjs, tspath.ExtensionJs, tspath.ExtensionJson, tspath.ExtensionDmts, tspath.ExtensionDcts, tspath.ExtensionDts} + for _, ext := range jsAndDtsExtensions { + if tspath.FileExtensionIs(possibleInputBase, ext) { + inputExts := r.getPossibleOriginalInputExtensionForExtension(possibleInputBase) + for _, possibleExt := range inputExts { + if !extensionIsOk(r.extensions, possibleExt) { + continue + } + possibleInputWithInputExtension := tspath.ChangeExtension(possibleInputBase, possibleExt) + if r.resolver.host.FS().FileExists(possibleInputWithInputExtension) { + resolved := r.loadFileNameFromPackageJSONField(r.extensions, possibleInputWithInputExtension, "", false) + if !resolved.shouldContinueSearching() { + return resolved + } + } + } + } + } + } + } + } return continueSearching() } +func (r *resolutionState) getOutputDirectoriesForBaseDirectory(commonSourceDirGuess string) []string { + // Config file output paths are processed to be relative to the host's current directory, while + // otherwise the paths are resolved relative to the common source dir the compiler puts together + currentDir := core.IfElse(r.compilerOptions.ConfigFilePath != "", r.resolver.host.GetCurrentDirectory(), commonSourceDirGuess) + var candidateDirectories []string + if r.compilerOptions.DeclarationDir != "" { + candidateDirectories = append(candidateDirectories, tspath.GetNormalizedAbsolutePath(tspath.CombinePaths(currentDir, r.compilerOptions.DeclarationDir), r.resolver.host.GetCurrentDirectory())) + } + if r.compilerOptions.OutDir != "" && r.compilerOptions.OutDir != r.compilerOptions.DeclarationDir { + candidateDirectories = append(candidateDirectories, tspath.GetNormalizedAbsolutePath(tspath.CombinePaths(currentDir, r.compilerOptions.OutDir), r.resolver.host.GetCurrentDirectory())) + } + return candidateDirectories +} + +func (r *resolutionState) getPossibleOriginalInputExtensionForExtension(path string) []string { + if tspath.FileExtensionIsOneOf(path, []string{tspath.ExtensionDmts, tspath.ExtensionMjs, tspath.ExtensionMts}) { + return []string{tspath.ExtensionMts, tspath.ExtensionMjs} + } + if tspath.FileExtensionIsOneOf(path, []string{tspath.ExtensionDcts, tspath.ExtensionCjs, tspath.ExtensionCts}) { + return []string{tspath.ExtensionCts, tspath.ExtensionCjs} + } + if tspath.FileExtensionIs(path, ".d.json.ts") { + return []string{tspath.ExtensionJson} + } + return []string{tspath.ExtensionTsx, tspath.ExtensionTs, tspath.ExtensionJsx, tspath.ExtensionJs} +} + func (r *resolutionState) loadModuleFromNearestNodeModulesDirectory(typesScopeOnly bool) *resolved { mode := core.ResolutionModeCommonJS if r.esmMode || r.conditionMatches("import") { @@ -1377,7 +1475,7 @@ func (r *resolutionState) loadFileNameFromPackageJSONField(extensions extensions return &resolved{ path: path, extension: extension, - resolvedUsingTsExtension: !strings.HasSuffix(packageJSONValue, extension), + resolvedUsingTsExtension: packageJSONValue != "" && !strings.HasSuffix(packageJSONValue, extension), } } return continueSearching() diff --git a/internal/module/resolver_test.go b/internal/module/resolver_test.go index b7375b18f5..bc106e6cb2 100644 --- a/internal/module/resolver_test.go +++ b/internal/module/resolver_test.go @@ -74,15 +74,21 @@ var skip = []string{ "moduleResolutionWithSymlinks_referenceTypes.ts", "moduleResolutionWithSymlinks_withOutDir.ts", "moduleResolutionWithSymlinks.ts", + "nodeAllowJsPackageSelfName(module=node16).ts", + "nodeAllowJsPackageSelfName(module=nodenext).ts", "nodeAllowJsPackageSelfName2.ts", "nodeModulesAllowJsConditionalPackageExports(module=node16).ts", "nodeModulesAllowJsConditionalPackageExports(module=nodenext).ts", "nodeModulesAllowJsPackageExports(module=node16).ts", "nodeModulesAllowJsPackageExports(module=nodenext).ts", + "nodeModulesAllowJsPackageImports(module=node16).ts", + "nodeModulesAllowJsPackageImports(module=nodenext).ts", "nodeModulesAllowJsPackagePatternExports(module=node16).ts", "nodeModulesAllowJsPackagePatternExports(module=nodenext).ts", "nodeModulesAllowJsPackagePatternExportsTrailers(module=node16).ts", "nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).ts", + "nodeModulesConditionalPackageExports(module=node16).ts", + "nodeModulesConditionalPackageExports(module=nodenext).ts", "nodeModulesDeclarationEmitWithPackageExports(module=node16).ts", "nodeModulesDeclarationEmitWithPackageExports(module=nodenext).ts", "nodeModulesExportsBlocksTypesVersions(module=node16).ts", diff --git a/internal/module/types.go b/internal/module/types.go index d0acc036da..f3c78cc715 100644 --- a/internal/module/types.go +++ b/internal/module/types.go @@ -63,7 +63,7 @@ func (p *PackageId) PackageName() string { type LookupLocations struct { FailedLookupLocations []string AffectingLocations []string - ResolutionDiagnostics []ast.Diagnostic + ResolutionDiagnostics []*ast.Diagnostic } type ResolvedModule struct { diff --git a/internal/project/ata_test.go b/internal/project/ata_test.go index cced33e9f6..e7c392faa9 100644 --- a/internal/project/ata_test.go +++ b/internal/project/ata_test.go @@ -21,7 +21,7 @@ func TestAta(t *testing.T) { t.Run("local module should not be picked up", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": `const c = require('./config');`, "/user/username/projects/project/config.js": `export let x = 1`, "/user/username/projects/project/jsconfig.json": `{ @@ -34,7 +34,7 @@ func TestAta(t *testing.T) { TypesRegistry: []string{"config"}, }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") assert.Equal(t, p.Kind(), project.KindConfigured) @@ -50,7 +50,7 @@ func TestAta(t *testing.T) { t.Run("configured projects", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ``, "/user/username/projects/project/tsconfig.json": `{ "compilerOptions": { "allowJs": true }, @@ -70,7 +70,7 @@ func TestAta(t *testing.T) { }, }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") assert.Equal(t, p.Kind(), project.KindConfigured) @@ -92,7 +92,7 @@ func TestAta(t *testing.T) { t.Run("inferred projects", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ``, "/user/username/projects/project/package.json": `{ "name": "test", @@ -108,7 +108,7 @@ func TestAta(t *testing.T) { }, }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") assert.Equal(t, p.Kind(), project.KindInferred) @@ -130,7 +130,7 @@ func TestAta(t *testing.T) { t.Run("type acquisition with disableFilenameBasedTypeAcquisition:true", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/jquery.js": ``, "/user/username/projects/project/tsconfig.json": `{ "compilerOptions": { "allowJs": true }, @@ -142,7 +142,7 @@ func TestAta(t *testing.T) { TypesRegistry: []string{"jquery"}, }, }) - service.OpenFile("/user/username/projects/project/jquery.js", files["/user/username/projects/project/jquery.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/jquery.js", files["/user/username/projects/project/jquery.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/jquery.js") assert.Equal(t, p.Kind(), project.KindConfigured) @@ -158,7 +158,7 @@ func TestAta(t *testing.T) { t.Run("deduplicate from local @types packages", func(t *testing.T) { t.Skip("Todo - implement removing local @types from include list") t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/node_modules/@types/node/index.d.ts": "declare var node;", "/user/username/projects/project/jsconfig.json": `{ @@ -170,7 +170,7 @@ func TestAta(t *testing.T) { TypesRegistry: []string{"node"}, }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") assert.Equal(t, p.Kind(), project.KindConfigured) @@ -185,7 +185,7 @@ func TestAta(t *testing.T) { t.Run("Throttle - scheduled run install requests without reaching limit", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project1/app.js": "", "/user/username/projects/project1/file3.d.ts": "", "/user/username/projects/project1/jsconfig.json": `{ @@ -210,8 +210,8 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project1/app.js", files["/user/username/projects/project1/app.js"].(string), core.ScriptKindJS, "") - service.OpenFile("/user/username/projects/project2/app.js", files["/user/username/projects/project2/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project1/app.js", files["/user/username/projects/project1/app.js"], core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project2/app.js", files["/user/username/projects/project2/app.js"], core.ScriptKindJS, "") _, p1 := service.EnsureDefaultProjectForFile("/user/username/projects/project1/app.js") _, p2 := service.EnsureDefaultProjectForFile("/user/username/projects/project2/app.js") var installStatuses []project.TypingsInstallerStatus @@ -227,7 +227,7 @@ func TestAta(t *testing.T) { t.Run("Throttle - scheduled run install requests reaching limit", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project1/app.js": "", "/user/username/projects/project1/file3.d.ts": "", "/user/username/projects/project1/jsconfig.json": `{ @@ -271,8 +271,8 @@ func TestAta(t *testing.T) { } } - service.OpenFile("/user/username/projects/project1/app.js", files["/user/username/projects/project1/app.js"].(string), core.ScriptKindJS, "") - service.OpenFile("/user/username/projects/project2/app.js", files["/user/username/projects/project2/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project1/app.js", files["/user/username/projects/project1/app.js"], core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project2/app.js", files["/user/username/projects/project2/app.js"], core.ScriptKindJS, "") _, p1 := service.EnsureDefaultProjectForFile("/user/username/projects/project1/app.js") _, p2 := service.EnsureDefaultProjectForFile("/user/username/projects/project2/app.js") // Order is determinate since second install will run only after completing first one @@ -286,7 +286,7 @@ func TestAta(t *testing.T) { t.Run("discover from node_modules", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { @@ -309,7 +309,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ @@ -322,7 +322,7 @@ func TestAta(t *testing.T) { // Explicit types prevent automatic inclusion from package.json listing t.Run("discover from node_modules empty types", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { @@ -349,7 +349,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ @@ -362,7 +362,7 @@ func TestAta(t *testing.T) { // A type reference directive will not resolve to the global typings cache t.Run("discover from node_modules explicit types", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { @@ -389,7 +389,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ @@ -402,7 +402,7 @@ func TestAta(t *testing.T) { // However, explicit types will not prevent unresolved imports from pulling in typings t.Run("discover from node_modules empty types has import", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": `import "jquery";`, "/user/username/projects/project/package.json": `{ "dependencies": { @@ -429,7 +429,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ @@ -441,7 +441,7 @@ func TestAta(t *testing.T) { t.Run("discover from bower_components", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ``, "/user/username/projects/project/jsconfig.json": `{}`, "/user/username/projects/project/bower_components/jquery/index.js": "", @@ -455,7 +455,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -470,7 +470,7 @@ func TestAta(t *testing.T) { t.Run("discover from bower.json", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ``, "/user/username/projects/project/jsconfig.json": `{}`, "/user/username/projects/project/bower.json": `{ @@ -487,7 +487,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -502,7 +502,7 @@ func TestAta(t *testing.T) { t.Run("Malformed package.json should be watched", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ``, "/user/username/projects/project/package.json": `{ "dependencies": { "co } }`, } @@ -514,7 +514,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -546,7 +546,7 @@ func TestAta(t *testing.T) { t.Run("should install typings for unresolved imports", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ` import * as fs from "fs"; import * as commander from "commander"; @@ -563,7 +563,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -580,7 +580,7 @@ func TestAta(t *testing.T) { t.Run("should redo resolution that resolved to '.js' file after typings are installed", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": ` import * as commander from "commander"; `, @@ -594,7 +594,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -610,7 +610,7 @@ func TestAta(t *testing.T) { t.Run("expired cache entry (inferred project, should install typings)", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "name": "test", @@ -643,7 +643,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -658,7 +658,7 @@ func TestAta(t *testing.T) { t.Run("non-expired cache entry (inferred project, should not install typings)", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "name": "test", @@ -689,7 +689,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -704,7 +704,7 @@ func TestAta(t *testing.T) { t.Run("expired cache entry (inferred project, should install typings) lockfile3", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "name": "test", @@ -737,7 +737,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus @@ -752,7 +752,7 @@ func TestAta(t *testing.T) { t.Run("non-expired cache entry (inferred project, should not install typings) lockfile3", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "name": "test", @@ -783,7 +783,7 @@ func TestAta(t *testing.T) { }, }) - service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"], core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus diff --git a/internal/project/host.go b/internal/project/host.go index 94c4618e47..8fb664b1f1 100644 --- a/internal/project/host.go +++ b/internal/project/host.go @@ -20,7 +20,6 @@ type ServiceHost interface { DefaultLibraryPath() string TypingsLocation() string GetCurrentDirectory() string - NewLine() string Client() Client } diff --git a/internal/project/project.go b/internal/project/project.go index d23850af30..745d43c203 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -42,6 +42,7 @@ type snapshot struct { project *Project positionEncoding lsproto.PositionEncodingKind program *compiler.Program + lineMaps collections.SyncMap[*ast.SourceFile, *ls.LineMap] } // GetLineMap implements ls.Host. @@ -51,7 +52,13 @@ func (s *snapshot) GetLineMap(fileName string) *ls.LineMap { if s.project.getFileVersion(file) == scriptInfo.Version() { return scriptInfo.LineMap() } - return ls.ComputeLineStarts(file.Text()) + // The version changed; recompute the line map. + // !!! This shouldn't happen so often, but does. Probably removable once snapshotting is finished. + if cached, ok := s.lineMaps.Load(file); ok { + return cached + } + lineMap, _ := s.lineMaps.LoadOrStore(file, ls.ComputeLineStarts(file.Text())) + return lineMap } // GetPositionEncoding implements ls.Host. @@ -77,7 +84,6 @@ const ( type ProjectHost interface { tsoptions.ParseConfigHost module.ResolutionHost - NewLine() string DefaultLibraryPath() string TypingsInstaller() *TypingsInstaller DocumentStore() *DocumentStore @@ -294,11 +300,6 @@ func (p *Project) GetProgram() *compiler.Program { return program } -// NewLine implements compiler.CompilerHost. -func (p *Project) NewLine() string { - return p.host.NewLine() -} - // Trace implements compiler.CompilerHost. func (p *Project) Trace(msg string) { p.host.Log(msg) diff --git a/internal/project/service.go b/internal/project/service.go index a3802f6c71..a6b6c70e47 100644 --- a/internal/project/service.go +++ b/internal/project/service.go @@ -119,11 +119,6 @@ func (s *Service) HasLevel(level LogLevel) bool { return s.options.Logger.HasLevel(level) } -// NewLine implements ProjectHost. -func (s *Service) NewLine() string { - return s.host.NewLine() -} - // DefaultLibraryPath implements ProjectHost. func (s *Service) DefaultLibraryPath() string { return s.host.DefaultLibraryPath() diff --git a/internal/project/service_test.go b/internal/project/service_test.go index 3e39e14096..be56f6c930 100644 --- a/internal/project/service_test.go +++ b/internal/project/service_test.go @@ -19,7 +19,7 @@ func TestService(t *testing.T) { t.Skip("bundled files are not embedded") } - defaultFiles := map[string]any{ + defaultFiles := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true, @@ -39,7 +39,7 @@ func TestService(t *testing.T) { t.Parallel() service, _ := projecttestutil.Setup(defaultFiles, nil) assert.Equal(t, len(service.Projects()), 0) - service.OpenFile("/home/projects/TS/p1/src/index.ts", defaultFiles["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", defaultFiles["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) @@ -51,7 +51,7 @@ func TestService(t *testing.T) { t.Run("create inferred project", func(t *testing.T) { t.Parallel() service, _ := projecttestutil.Setup(defaultFiles, nil) - service.OpenFile("/home/projects/TS/p1/config.ts", defaultFiles["/home/projects/TS/p1/config.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/config.ts", defaultFiles["/home/projects/TS/p1/config.ts"], core.ScriptKindTS, "") // Find tsconfig, load, notice config.ts is not included, create inferred project assert.Equal(t, len(service.Projects()), 2) _, proj := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/config.ts") @@ -61,7 +61,7 @@ func TestService(t *testing.T) { t.Run("inferred project for in-memory files", func(t *testing.T) { t.Parallel() service, _ := projecttestutil.Setup(defaultFiles, nil) - service.OpenFile("/home/projects/TS/p1/config.ts", defaultFiles["/home/projects/TS/p1/config.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/config.ts", defaultFiles["/home/projects/TS/p1/config.ts"], core.ScriptKindTS, "") service.OpenFile("^/untitled/ts-nul-authority/Untitled-1", "x", core.ScriptKindTS, "") service.OpenFile("^/untitled/ts-nul-authority/Untitled-2", "y", core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 2) @@ -74,11 +74,11 @@ func TestService(t *testing.T) { t.Run("inferred project JS file", func(t *testing.T) { t.Parallel() - jsFiles := map[string]any{ + jsFiles := map[string]string{ "/home/projects/TS/p1/index.js": `import { x } from "./x";`, } service, _ := projecttestutil.Setup(jsFiles, nil) - service.OpenFile("/home/projects/TS/p1/index.js", jsFiles["/home/projects/TS/p1/index.js"].(string), core.ScriptKindJS, "") + service.OpenFile("/home/projects/TS/p1/index.js", jsFiles["/home/projects/TS/p1/index.js"], core.ScriptKindJS, "") assert.Equal(t, len(service.Projects()), 1) project := service.Projects()[0] assert.Assert(t, project.GetProgram().GetSourceFile("/home/projects/TS/p1/index.js") != nil) @@ -90,7 +90,7 @@ func TestService(t *testing.T) { t.Run("update script info eagerly and program lazily", func(t *testing.T) { t.Parallel() service, _ := projecttestutil.Setup(defaultFiles, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", defaultFiles["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", defaultFiles["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") info, proj := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/x.ts") programBefore := proj.GetProgram() err := service.ChangeFile( @@ -128,7 +128,7 @@ func TestService(t *testing.T) { t.Run("unchanged source files are reused", func(t *testing.T) { t.Parallel() service, _ := projecttestutil.Setup(defaultFiles, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", defaultFiles["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", defaultFiles["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") _, proj := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/x.ts") programBefore := proj.GetProgram() indexFileBefore := programBefore.GetSourceFile("/home/projects/TS/p1/src/index.ts") @@ -166,7 +166,7 @@ func TestService(t *testing.T) { files := maps.Clone(defaultFiles) files["/home/projects/TS/p1/y.ts"] = `export const y = 2;` service, _ := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") assert.Check(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/y.ts")) == nil) // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -212,7 +212,7 @@ func TestService(t *testing.T) { "include": ["src/index.ts"] }` service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") programBefore := project.GetProgram() assert.Equal(t, len(programBefore.GetSourceFiles()), 2) @@ -277,8 +277,8 @@ func TestService(t *testing.T) { t.Parallel() files := maps.Clone(defaultFiles) service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") assert.Equal(t, service.DocumentStore().SourceFileCount(), 2) // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -307,8 +307,8 @@ func TestService(t *testing.T) { files := maps.Clone(defaultFiles) delete(files, "/home/projects/TS/p1/tsconfig.json") service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -345,8 +345,8 @@ func TestService(t *testing.T) { }` files["/home/projects/TS/p2/src/index.ts"] = `import { x } from "../../p1/src/x";` service, _ := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") - service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"], core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 2) // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -370,8 +370,8 @@ func TestService(t *testing.T) { }` files["/home/projects/TS/p2/src/index.ts"] = `import { x } from "../../p1/src/x";` service, _ := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") - service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"], core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 2) // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -391,8 +391,8 @@ func TestService(t *testing.T) { t.Parallel() files := maps.Clone(defaultFiles) service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") programBefore := project.GetProgram() // Avoid using initial file set after this point @@ -415,7 +415,7 @@ func TestService(t *testing.T) { t.Parallel() files := maps.Clone(defaultFiles) service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") programBefore := project.GetProgram() // Avoid using initial file set after this point @@ -436,7 +436,7 @@ func TestService(t *testing.T) { t.Run("change config file", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true, @@ -450,7 +450,7 @@ func TestService(t *testing.T) { } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") program := project.GetProgram() assert.Equal(t, len(program.GetSemanticDiagnostics(projecttestutil.WithRequestID(t.Context()), program.GetSourceFile("/home/projects/TS/p1/src/index.ts"))), 0) @@ -476,7 +476,7 @@ func TestService(t *testing.T) { t.Run("delete explicitly included file", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true, @@ -487,7 +487,7 @@ func TestService(t *testing.T) { "/home/projects/TS/p1/src/index.ts": `import { x } from "./x";`, } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") program := project.GetProgram() assert.Equal(t, len(program.GetSemanticDiagnostics(projecttestutil.WithRequestID(t.Context()), program.GetSourceFile("/home/projects/TS/p1/src/index.ts"))), 0) @@ -509,7 +509,7 @@ func TestService(t *testing.T) { t.Run("delete wildcard included file", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true @@ -520,7 +520,7 @@ func TestService(t *testing.T) { "/home/projects/TS/p1/src/x.ts": `let y = x;`, } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/x.ts") program := project.GetProgram() assert.Equal(t, len(program.GetSemanticDiagnostics(projecttestutil.WithRequestID(t.Context()), program.GetSourceFile("/home/projects/TS/p1/src/x.ts"))), 0) @@ -541,7 +541,7 @@ func TestService(t *testing.T) { t.Run("create explicitly included file", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true @@ -551,7 +551,7 @@ func TestService(t *testing.T) { "/home/projects/TS/p1/src/index.ts": `import { y } from "./y";`, } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") program := project.GetProgram() @@ -599,7 +599,7 @@ func TestService(t *testing.T) { t.Run("create failed lookup location", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true @@ -609,7 +609,7 @@ func TestService(t *testing.T) { "/home/projects/TS/p1/src/index.ts": `import { z } from "./z";`, } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") program := project.GetProgram() @@ -640,7 +640,7 @@ func TestService(t *testing.T) { t.Run("create wildcard included file", func(t *testing.T) { t.Parallel() - files := map[string]any{ + files := map[string]string{ "/home/projects/TS/p1/tsconfig.json": `{ "compilerOptions": { "noLib": true @@ -650,7 +650,7 @@ func TestService(t *testing.T) { "/home/projects/TS/p1/src/index.ts": `a;`, } service, host := projecttestutil.Setup(files, nil) - service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") + service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"], core.ScriptKindTS, "") _, project := service.EnsureDefaultProjectForFile("/home/projects/TS/p1/src/index.ts") program := project.GetProgram() diff --git a/internal/testutil/harnessutil/harnessutil.go b/internal/testutil/harnessutil/harnessutil.go index 9c2c324ef7..ac3f1658b6 100644 --- a/internal/testutil/harnessutil/harnessutil.go +++ b/internal/testutil/harnessutil/harnessutil.go @@ -209,7 +209,7 @@ func CompileFilesEx( fs = bundled.WrapFS(fs) fs = NewOutputRecorderFS(fs) - host := createCompilerHost(fs, bundled.LibPath(), compilerOptions, currentDirectory) + host := createCompilerHost(fs, bundled.LibPath(), currentDirectory) var configFile *tsoptions.TsConfigSourceFile var errors []*ast.Diagnostic if tsconfig != nil { @@ -506,9 +506,9 @@ func (h *cachedCompilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast return result } -func createCompilerHost(fs vfs.FS, defaultLibraryPath string, options *core.CompilerOptions, currentDirectory string) compiler.CompilerHost { +func createCompilerHost(fs vfs.FS, defaultLibraryPath string, currentDirectory string) compiler.CompilerHost { return &cachedCompilerHost{ - CompilerHost: compiler.NewCompilerHost(options, currentDirectory, fs, defaultLibraryPath, nil), + CompilerHost: compiler.NewCompilerHost(currentDirectory, fs, defaultLibraryPath), } } @@ -575,6 +575,7 @@ func compileFilesWithHost( ctx := context.Background() program := createProgram(host, config) var diagnostics []*ast.Diagnostic + diagnostics = append(diagnostics, program.GetProgramDiagnostics()...) diagnostics = append(diagnostics, program.GetSyntacticDiagnostics(ctx, nil)...) diagnostics = append(diagnostics, program.GetSemanticDiagnostics(ctx, nil)...) diagnostics = append(diagnostics, program.GetGlobalDiagnostics(ctx)...) diff --git a/internal/testutil/projecttestutil/projecttestutil.go b/internal/testutil/projecttestutil/projecttestutil.go index 204dee8d9e..5acbcbe062 100644 --- a/internal/testutil/projecttestutil/projecttestutil.go +++ b/internal/testutil/projecttestutil/projecttestutil.go @@ -74,11 +74,6 @@ func (p *ProjectServiceHost) Log(msg ...any) { fmt.Fprintln(&p.output, msg...) } -// NewLine implements project.ProjectServiceHost. -func (p *ProjectServiceHost) NewLine() string { - return "\n" -} - // Client implements project.ProjectServiceHost. func (p *ProjectServiceHost) Client() project.Client { return p.ClientMock @@ -86,7 +81,7 @@ func (p *ProjectServiceHost) Client() project.Client { var _ project.ServiceHost = (*ProjectServiceHost)(nil) -func Setup(files map[string]any, testOptions *TestTypingsInstaller) (*project.Service, *ProjectServiceHost) { +func Setup[FileContents any](files map[string]FileContents, testOptions *TestTypingsInstaller) (*project.Service, *ProjectServiceHost) { host := newProjectServiceHost(files) if testOptions != nil { host.TestOptions = &testOptions.TestTypingsInstallerOptions @@ -212,7 +207,7 @@ func appendTypesRegistryConfig(builder *strings.Builder, index int, entry string builder.WriteString(fmt.Sprintf("\n \"%s\": {%s\n }", entry, TypesRegistryConfigText())) } -func newProjectServiceHost(files map[string]any) *ProjectServiceHost { +func newProjectServiceHost[FileContents any](files map[string]FileContents) *ProjectServiceHost { fs := bundled.WrapFS(vfstest.FromMap(files, false /*useCaseSensitiveFileNames*/)) host := &ProjectServiceHost{ fs: fs, diff --git a/package.json b/package.json index e220fba82b..7fdd9fcaca 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "extension:build": "npm run -w _extension build", "extension:watch": "npm run -w _extension watch", "node": "node --no-warnings --conditions @typescript/source", - "convertfourslash": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/convertFourslash.mts" + "convertfourslash": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/convertFourslash.mts", + "updatefailing": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/updateFailing.mts" }, "workspaces": [ "./_extension", diff --git a/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.symbols b/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.symbols new file mode 100644 index 0000000000..8b47e8ef22 --- /dev/null +++ b/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.symbols @@ -0,0 +1,105 @@ +//// [tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts] //// + +=== circularControlFlowNarrowingWithCurrentElement01.ts === +class A { +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) + + next: A | null = null; +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) + + constructor(readonly children: (A | null)[]) {} +>children : Symbol(children, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 3, 14)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) +} + +function getNodes(): A[] { +>getNodes : Symbol(getNodes, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 4, 1)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) + + const out: A[] = []; +>out : Symbol(out, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 7, 7)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) + + let current: A | null = new A([]); +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) +>A : Symbol(A, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 0)) + + while (current !== null) { +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) + + let firstChild = null; +>firstChild : Symbol(firstChild, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 12, 7)) + + if (out.length) { +>out.length : Symbol(length, Decl(lib.es5.d.ts, --, --)) +>out : Symbol(out, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 7, 7)) +>length : Symbol(length, Decl(lib.es5.d.ts, --, --)) + + current = current.next; +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>current.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) + + continue; + } + + for (let i = 0; i < current.children.length; i++) { +>i : Symbol(i, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 19, 12)) +>i : Symbol(i, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 19, 12)) +>current.children.length : Symbol(length, Decl(lib.es5.d.ts, --, --)) +>current.children : Symbol(children, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 3, 14)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>children : Symbol(children, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 3, 14)) +>length : Symbol(length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 19, 12)) + + const child = current.children[i]; +>child : Symbol(child, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 20, 11)) +>current.children : Symbol(children, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 3, 14)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>children : Symbol(children, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 3, 14)) +>i : Symbol(i, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 19, 12)) + + if (child) { +>child : Symbol(child, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 20, 11)) + + if (!firstChild) { +>firstChild : Symbol(firstChild, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 12, 7)) + + firstChild = child; +>firstChild : Symbol(firstChild, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 12, 7)) +>child : Symbol(child, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 20, 11)) + + firstChild.next = current.next; +>firstChild.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>firstChild : Symbol(firstChild, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 12, 7)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) + } + + child.next = current.next; +>child.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>child : Symbol(child, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 20, 11)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) + } + } + + current = firstChild || current.next; +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>firstChild : Symbol(firstChild, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 12, 7)) +>current.next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) +>current : Symbol(current, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 9, 5)) +>next : Symbol(next, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 0, 9)) + } + + return out; +>out : Symbol(out, Decl(circularControlFlowNarrowingWithCurrentElement01.ts, 7, 7)) +} diff --git a/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.types b/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.types new file mode 100644 index 0000000000..09a5ecd958 --- /dev/null +++ b/testdata/baselines/reference/compiler/circularControlFlowNarrowingWithCurrentElement01.types @@ -0,0 +1,115 @@ +//// [tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts] //// + +=== circularControlFlowNarrowingWithCurrentElement01.ts === +class A { +>A : A + + next: A | null = null; +>next : A | null + + constructor(readonly children: (A | null)[]) {} +>children : (A | null)[] +} + +function getNodes(): A[] { +>getNodes : () => A[] + + const out: A[] = []; +>out : A[] +>[] : never[] + + let current: A | null = new A([]); +>current : A | null +>new A([]) : A +>A : typeof A +>[] : never[] + + while (current !== null) { +>current !== null : boolean +>current : A | null + + let firstChild = null; +>firstChild : any + + if (out.length) { +>out.length : number +>out : A[] +>length : number + + current = current.next; +>current = current.next : A | null +>current : A | null +>current.next : A | null +>current : A +>next : A | null + + continue; + } + + for (let i = 0; i < current.children.length; i++) { +>i : number +>0 : 0 +>i < current.children.length : boolean +>i : number +>current.children.length : number +>current.children : (A | null)[] +>current : A +>children : (A | null)[] +>length : number +>i++ : number +>i : number + + const child = current.children[i]; +>child : A | null +>current.children[i] : A | null +>current.children : (A | null)[] +>current : A +>children : (A | null)[] +>i : number + + if (child) { +>child : A | null + + if (!firstChild) { +>!firstChild : boolean +>firstChild : A | null + + firstChild = child; +>firstChild = child : A +>firstChild : any +>child : A + + firstChild.next = current.next; +>firstChild.next = current.next : A | null +>firstChild.next : A | null +>firstChild : A +>next : A | null +>current.next : A | null +>current : A +>next : A | null + } + + child.next = current.next; +>child.next = current.next : A | null +>child.next : A | null +>child : A +>next : A | null +>current.next : A | null +>current : A +>next : A | null + } + } + + current = firstChild || current.next; +>current = firstChild || current.next : A | null +>current : A | null +>firstChild || current.next : A | null +>firstChild : A | null +>current.next : A | null +>current : A +>next : A | null + } + + return out; +>out : A[] +} diff --git a/testdata/baselines/reference/compiler/subpathImportsJS.js b/testdata/baselines/reference/compiler/subpathImportsJS.js new file mode 100644 index 0000000000..8fb7c1666f --- /dev/null +++ b/testdata/baselines/reference/compiler/subpathImportsJS.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/subpathImportsJS.ts] //// + +//// [package.json] +{ + "name": "pkg", + "type": "module", + "imports": { + "#subpath": "./dist/subpath.js" + } +} + +//// [subpath.ts] +export const foo = "foo"; + +//// [index.ts] +import { foo } from "#subpath"; +foo; + + +//// [subpath.js] +export const foo = "foo"; +//// [index.js] +import { foo } from "#subpath"; +foo; + + +//// [subpath.d.ts] +export declare const foo = "foo"; +//// [index.d.ts] +export {}; diff --git a/testdata/baselines/reference/compiler/subpathImportsJS.symbols b/testdata/baselines/reference/compiler/subpathImportsJS.symbols new file mode 100644 index 0000000000..93f0870b6c --- /dev/null +++ b/testdata/baselines/reference/compiler/subpathImportsJS.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/subpathImportsJS.ts] //// + +=== /src/subpath.ts === +export const foo = "foo"; +>foo : Symbol(foo, Decl(subpath.ts, 0, 12)) + +=== /src/index.ts === +import { foo } from "#subpath"; +>foo : Symbol(foo, Decl(index.ts, 0, 8)) + +foo; +>foo : Symbol(foo, Decl(index.ts, 0, 8)) + diff --git a/testdata/baselines/reference/compiler/subpathImportsJS.types b/testdata/baselines/reference/compiler/subpathImportsJS.types new file mode 100644 index 0000000000..5bf435248e --- /dev/null +++ b/testdata/baselines/reference/compiler/subpathImportsJS.types @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/subpathImportsJS.ts] //// + +=== /src/subpath.ts === +export const foo = "foo"; +>foo : "foo" +>"foo" : "foo" + +=== /src/index.ts === +import { foo } from "#subpath"; +>foo : "foo" + +foo; +>foo : "foo" + diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt deleted file mode 100644 index 6bb8c026ab..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -index.ts(1,21): error TS2307: Cannot find module '#dep' or its corresponding type declarations. - - -==== package.json (0 errors) ==== - { - "name": "@this/package", - "type": "module", - "exports": { - ".": "./dist/index.js" - }, - "imports": { - "#dep": "./dist/index.js" - } - } -==== index.ts (1 errors) ==== - import * as me from "#dep"; - ~~~~~~ -!!! error TS2307: Cannot find module '#dep' or its corresponding type declarations. - - me.thing(); - - export function thing(): void {} - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt.diff deleted file mode 100644 index b42c3c0180..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.errors.txt.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- old.nodeNextPackageImportMapRootDir.errors.txt -+++ new.nodeNextPackageImportMapRootDir.errors.txt -@@= skipped -0, +0 lines =@@ -- -+index.ts(1,21): error TS2307: Cannot find module '#dep' or its corresponding type declarations. -+ -+ -+==== package.json (0 errors) ==== -+ { -+ "name": "@this/package", -+ "type": "module", -+ "exports": { -+ ".": "./dist/index.js" -+ }, -+ "imports": { -+ "#dep": "./dist/index.js" -+ } -+ } -+==== index.ts (1 errors) ==== -+ import * as me from "#dep"; -+ ~~~~~~ -+!!! error TS2307: Cannot find module '#dep' or its corresponding type declarations. -+ -+ me.thing(); -+ -+ export function thing(): void {} -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols index ea09e721ee..5d268641a1 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols @@ -5,7 +5,9 @@ import * as me from "#dep"; >me : Symbol(me, Decl(index.ts, 0, 6)) me.thing(); +>me.thing : Symbol(thing, Decl(index.ts, 2, 11)) >me : Symbol(me, Decl(index.ts, 0, 6)) +>thing : Symbol(thing, Decl(index.ts, 2, 11)) export function thing(): void {} >thing : Symbol(thing, Decl(index.ts, 2, 11)) diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols.diff deleted file mode 100644 index d23bac478d..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.symbols.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- old.nodeNextPackageImportMapRootDir.symbols -+++ new.nodeNextPackageImportMapRootDir.symbols -@@= skipped -4, +4 lines =@@ - >me : Symbol(me, Decl(index.ts, 0, 6)) - - me.thing(); -->me.thing : Symbol(thing, Decl(index.ts, 2, 11)) - >me : Symbol(me, Decl(index.ts, 0, 6)) -->thing : Symbol(thing, Decl(index.ts, 2, 11)) - - export function thing(): void {} - >thing : Symbol(thing, Decl(index.ts, 2, 11)) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types index b68e652012..12c154766e 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types @@ -2,13 +2,13 @@ === index.ts === import * as me from "#dep"; ->me : any +>me : typeof me me.thing(); ->me.thing() : any ->me.thing : any ->me : any ->thing : any +>me.thing() : void +>me.thing : () => void +>me : typeof me +>thing : () => void export function thing(): void {} >thing : () => void diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types.diff deleted file mode 100644 index 900c137968..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageImportMapRootDir.types.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.nodeNextPackageImportMapRootDir.types -+++ new.nodeNextPackageImportMapRootDir.types -@@= skipped -1, +1 lines =@@ - - === index.ts === - import * as me from "#dep"; -->me : typeof me -+>me : any - - me.thing(); -->me.thing() : void -->me.thing : () => void -->me : typeof me -->thing : () => void -+>me.thing() : any -+>me.thing : any -+>me : any -+>thing : any - - export function thing(): void {} - >thing : () => void \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt index 67aff83133..d26c2693e1 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt @@ -1,6 +1,8 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ==== package.json (0 errors) ==== { "name": "@this/package", diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt.diff index cc3c7951f6..e4db2adb78 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDir.errors.txt.diff @@ -1,17 +1,12 @@ --- old.nodeNextPackageSelfNameWithOutDir.errors.txt +++ new.nodeNextPackageSelfNameWithOutDir.errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ - ==== package.json (0 errors) ==== - { - "name": "@this/package", -@@= skipped -9, +8 lines =@@ + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +@@= skipped -9, +10 lines =@@ ".": "./dist/index.js" } } diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt index c717ff4c92..30c150c783 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt @@ -1,6 +1,8 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ==== package.json (0 errors) ==== { "name": "@this/package", diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt.diff index 6d0833fe41..65d0b7ee4b 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt.diff @@ -1,17 +1,12 @@ --- old.nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt +++ new.nodeNextPackageSelfNameWithOutDirDeclDir.errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ - ==== package.json (0 errors) ==== - { - "name": "@this/package", -@@= skipped -12, +11 lines =@@ + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +@@= skipped -12, +13 lines =@@ } } } diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt index d253a0fa23..c69d272c9d 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt @@ -1,6 +1,8 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. src/thing.ts(8,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ==== tsconfig.json (0 errors) ==== { "compilerOptions": { diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt.diff index 331017e8ed..ab5efeb973 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt.diff @@ -1,17 +1,12 @@ --- old.nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt +++ new.nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +src/thing.ts(8,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ - ==== tsconfig.json (0 errors) ==== - { - "compilerOptions": { -@@= skipped -12, +11 lines =@@ + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +@@= skipped -12, +13 lines =@@ } ==== index.ts (0 errors) ==== export {srcthing as thing} from "./src/thing.js"; diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt deleted file mode 100644 index b061751a7d..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -/pkg/src/index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. - - -==== /pkg/package.json (0 errors) ==== - { - "name": "@this/package", - "type": "module", - "exports": { - ".": { - "default": "./dist/index.js", - "types": "./types/index.d.ts" - } - } - } -==== /pkg/src/index.ts (1 errors) ==== - import * as me from "@this/package"; - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module '@this/package' or its corresponding type declarations. - - me.thing(); - - export function thing(): void {} - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt.diff deleted file mode 100644 index 4fc7bb5161..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt -+++ new.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.errors.txt -@@= skipped -0, +0 lines =@@ -- -+/pkg/src/index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ -+==== /pkg/package.json (0 errors) ==== -+ { -+ "name": "@this/package", -+ "type": "module", -+ "exports": { -+ ".": { -+ "default": "./dist/index.js", -+ "types": "./types/index.d.ts" -+ } -+ } -+ } -+==== /pkg/src/index.ts (1 errors) ==== -+ import * as me from "@this/package"; -+ ~~~~~~~~~~~~~~~ -+!!! error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ me.thing(); -+ -+ export function thing(): void {} -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols index aa0693e551..e39890387d 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols @@ -5,7 +5,9 @@ import * as me from "@this/package"; >me : Symbol(me, Decl(index.ts, 0, 6)) me.thing(); +>me.thing : Symbol(thing, Decl(index.ts, 2, 11)) >me : Symbol(me, Decl(index.ts, 0, 6)) +>thing : Symbol(thing, Decl(index.ts, 2, 11)) export function thing(): void {} >thing : Symbol(thing, Decl(index.ts, 2, 11)) diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols.diff deleted file mode 100644 index a45d9af058..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols -+++ new.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.symbols -@@= skipped -4, +4 lines =@@ - >me : Symbol(me, Decl(index.ts, 0, 6)) - - me.thing(); -->me.thing : Symbol(thing, Decl(index.ts, 2, 11)) - >me : Symbol(me, Decl(index.ts, 0, 6)) -->thing : Symbol(thing, Decl(index.ts, 2, 11)) - - export function thing(): void {} - >thing : Symbol(thing, Decl(index.ts, 2, 11)) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types index 23598d5833..08aab042b7 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types @@ -2,13 +2,13 @@ === /pkg/src/index.ts === import * as me from "@this/package"; ->me : any +>me : typeof me me.thing(); ->me.thing() : any ->me.thing : any ->me : any ->thing : any +>me.thing() : void +>me.thing : () => void +>me : typeof me +>thing : () => void export function thing(): void {} >thing : () => void diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types.diff deleted file mode 100644 index 3aeeb74b2d..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types -+++ new.nodeNextPackageSelfNameWithOutDirDeclDirRootDir.types -@@= skipped -1, +1 lines =@@ - - === /pkg/src/index.ts === - import * as me from "@this/package"; -->me : typeof me -+>me : any - - me.thing(); -->me.thing() : void -->me.thing : () => void -->me : typeof me -->thing : () => void -+>me.thing() : any -+>me.thing : any -+>me : any -+>thing : any - - export function thing(): void {} - >thing : () => void \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt deleted file mode 100644 index 67aff83133..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. - - -==== package.json (0 errors) ==== - { - "name": "@this/package", - "type": "module", - "exports": { - ".": "./dist/index.js" - } - } -==== index.ts (1 errors) ==== - import * as me from "@this/package"; - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module '@this/package' or its corresponding type declarations. - - me.thing(); - - export function thing(): void {} - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt.diff deleted file mode 100644 index e291447b20..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.errors.txt.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirRootDir.errors.txt -+++ new.nodeNextPackageSelfNameWithOutDirRootDir.errors.txt -@@= skipped -0, +0 lines =@@ -- -+index.ts(1,21): error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ -+==== package.json (0 errors) ==== -+ { -+ "name": "@this/package", -+ "type": "module", -+ "exports": { -+ ".": "./dist/index.js" -+ } -+ } -+==== index.ts (1 errors) ==== -+ import * as me from "@this/package"; -+ ~~~~~~~~~~~~~~~ -+!!! error TS2307: Cannot find module '@this/package' or its corresponding type declarations. -+ -+ me.thing(); -+ -+ export function thing(): void {} -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols index 92e460ce36..8374eeed78 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols @@ -5,7 +5,9 @@ import * as me from "@this/package"; >me : Symbol(me, Decl(index.ts, 0, 6)) me.thing(); +>me.thing : Symbol(thing, Decl(index.ts, 2, 11)) >me : Symbol(me, Decl(index.ts, 0, 6)) +>thing : Symbol(thing, Decl(index.ts, 2, 11)) export function thing(): void {} >thing : Symbol(thing, Decl(index.ts, 2, 11)) diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols.diff deleted file mode 100644 index 7f60766aaf..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.symbols.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirRootDir.symbols -+++ new.nodeNextPackageSelfNameWithOutDirRootDir.symbols -@@= skipped -4, +4 lines =@@ - >me : Symbol(me, Decl(index.ts, 0, 6)) - - me.thing(); -->me.thing : Symbol(thing, Decl(index.ts, 2, 11)) - >me : Symbol(me, Decl(index.ts, 0, 6)) -->thing : Symbol(thing, Decl(index.ts, 2, 11)) - - export function thing(): void {} - >thing : Symbol(thing, Decl(index.ts, 2, 11)) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types index 68b55b6266..22d6d440c5 100644 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types +++ b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types @@ -2,13 +2,13 @@ === index.ts === import * as me from "@this/package"; ->me : any +>me : typeof me me.thing(); ->me.thing() : any ->me.thing : any ->me : any ->thing : any +>me.thing() : void +>me.thing : () => void +>me : typeof me +>thing : () => void export function thing(): void {} >thing : () => void diff --git a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types.diff b/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types.diff deleted file mode 100644 index 72dfaaad3a..0000000000 --- a/testdata/baselines/reference/submodule/compiler/nodeNextPackageSelfNameWithOutDirRootDir.types.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.nodeNextPackageSelfNameWithOutDirRootDir.types -+++ new.nodeNextPackageSelfNameWithOutDirRootDir.types -@@= skipped -1, +1 lines =@@ - - === index.ts === - import * as me from "@this/package"; -->me : typeof me -+>me : any - - me.thing(); -->me.thing() : void -->me.thing : () => void -->me : typeof me -->thing : () => void -+>me.thing() : any -+>me.thing : any -+>me : any -+>thing : any - - export function thing(): void {} - >thing : () => void \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt b/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt deleted file mode 100644 index 988844a868..0000000000 --- a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt +++ /dev/null @@ -1,38 +0,0 @@ -/src/main.ts(2,27): error TS2307: Cannot find module 'pkg/indirect2.js' or its corresponding type declarations. - - -==== /tsconfig.json (0 errors) ==== - { - "compilerOptions": { - "module": "nodenext", - "outDir": "dist", - "rootDir": "src", - }, - "files": ["src/main.ts"] - } - -==== /src/main.ts (1 errors) ==== - import { indirect1 } from "#indirect1"; - import { indirect2 } from "pkg/indirect2.js"; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'pkg/indirect2.js' or its corresponding type declarations. - console.log(indirect1, indirect2); - -==== /package.json (0 errors) ==== - { - "name": "pkg", - "type": "module", - "imports": { - "#indirect1": "./src/indirect1.ts" - }, - "exports": { - "./*": "./dist/*" - } - } - -==== /src/indirect1.ts (0 errors) ==== - export const indirect1 = 0; - -==== /src/indirect2.ts (0 errors) ==== - export const indirect2 = 0; - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt.diff deleted file mode 100644 index bc3a93722f..0000000000 --- a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.errors.txt.diff +++ /dev/null @@ -1,42 +0,0 @@ ---- old.selfNameAndImportsEmitInclusion.errors.txt -+++ new.selfNameAndImportsEmitInclusion.errors.txt -@@= skipped -0, +0 lines =@@ -- -+/src/main.ts(2,27): error TS2307: Cannot find module 'pkg/indirect2.js' or its corresponding type declarations. -+ -+ -+==== /tsconfig.json (0 errors) ==== -+ { -+ "compilerOptions": { -+ "module": "nodenext", -+ "outDir": "dist", -+ "rootDir": "src", -+ }, -+ "files": ["src/main.ts"] -+ } -+ -+==== /src/main.ts (1 errors) ==== -+ import { indirect1 } from "#indirect1"; -+ import { indirect2 } from "pkg/indirect2.js"; -+ ~~~~~~~~~~~~~~~~~~ -+!!! error TS2307: Cannot find module 'pkg/indirect2.js' or its corresponding type declarations. -+ console.log(indirect1, indirect2); -+ -+==== /package.json (0 errors) ==== -+ { -+ "name": "pkg", -+ "type": "module", -+ "imports": { -+ "#indirect1": "./src/indirect1.ts" -+ }, -+ "exports": { -+ "./*": "./dist/*" -+ } -+ } -+ -+==== /src/indirect1.ts (0 errors) ==== -+ export const indirect1 = 0; -+ -+==== /src/indirect2.ts (0 errors) ==== -+ export const indirect2 = 0; -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js b/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js index 15f62d8d28..e8e1e014ab 100644 --- a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js +++ b/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js @@ -26,6 +26,8 @@ console.log(indirect1, indirect2); //// [indirect1.js] export const indirect1 = 0; +//// [indirect2.js] +export const indirect2 = 0; //// [main.js] import { indirect1 } from "#indirect1"; import { indirect2 } from "pkg/indirect2.js"; diff --git a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js.diff b/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js.diff deleted file mode 100644 index 94915b9bc2..0000000000 --- a/testdata/baselines/reference/submodule/compiler/selfNameAndImportsEmitInclusion.js.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- old.selfNameAndImportsEmitInclusion.js -+++ new.selfNameAndImportsEmitInclusion.js -@@= skipped -25, +25 lines =@@ - - //// [indirect1.js] - export const indirect1 = 0; --//// [indirect2.js] --export const indirect2 = 0; - //// [main.js] - import { indirect1 } from "#indirect1"; - import { indirect2 } from "pkg/indirect2.js"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt index 8192673cec..4454c8d1b0 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt @@ -1,19 +1,27 @@ -index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (1 errors) ==== // esm format file import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; -==== index.mjs (0 errors) ==== +==== index.mjs (1 errors) ==== // esm format file import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; ==== index.cjs (1 errors) ==== // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; ==== package.json (0 errors) ==== { diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).types index c1291c3042..e91f9692a5 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node16).types @@ -3,24 +3,24 @@ === index.js === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.mjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.cjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt index 8192673cec..4454c8d1b0 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt @@ -1,19 +1,27 @@ -index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (1 errors) ==== // esm format file import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; -==== index.mjs (0 errors) ==== +==== index.mjs (1 errors) ==== // esm format file import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; ==== index.cjs (1 errors) ==== // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. self; ==== package.json (0 errors) ==== { diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).types index c1291c3042..e91f9692a5 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=node18).types @@ -3,24 +3,24 @@ === index.js === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.mjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.cjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt new file mode 100644 index 0000000000..4454c8d1b0 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt @@ -0,0 +1,32 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; +==== index.mjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; +==== index.cjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).types index c1291c3042..e91f9692a5 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName(module=nodenext).types @@ -3,24 +3,24 @@ === index.js === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.mjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any === index.cjs === // esm format file import * as self from "package"; ->self : typeof self +>self : any self; ->self : typeof self +>self : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols index 236a605968..cf553ecca4 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols @@ -8,7 +8,3 @@ export const foo = 1; import { foo } from "js-self-name-import/foo.js"; >foo : Symbol(foo, Decl(foo.js, 0, 8)) -=== /types/src/foo.d.ts === -export const foo: 1; ->foo : Symbol(foo, Decl(foo.d.ts, 0, 12)) - diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols.diff b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols.diff deleted file mode 100644 index d78f58e9f7..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.symbols.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- old.nodeAllowJsPackageSelfName2.symbols -+++ new.nodeAllowJsPackageSelfName2.symbols -@@= skipped -7, +7 lines =@@ - import { foo } from "js-self-name-import/foo.js"; - >foo : Symbol(foo, Decl(foo.js, 0, 8)) - -+=== /types/src/foo.d.ts === -+export const foo: 1; -+>foo : Symbol(foo, Decl(foo.d.ts, 0, 12)) -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.types b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.types index bc6fa3d56b..b5d4bfc7cf 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.types +++ b/testdata/baselines/reference/submodule/conformance/nodeAllowJsPackageSelfName2.types @@ -9,7 +9,3 @@ export const foo = 1; import { foo } from "js-self-name-import/foo.js"; >foo : 1 -=== /types/src/foo.d.ts === -export const foo: 1; ->foo : 1 - diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt index 98529e67ed..0e7496180a 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt @@ -1,12 +1,27 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -18,11 +33,17 @@ index.cjs(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -34,15 +55,17 @@ index.cjs(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.cjs (2 errors) ==== +==== index.cjs (3 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js index 62fb2abec9..2f99e51c4c 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -190,27 +206,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js.diff new file mode 100644 index 0000000000..6fd54f278d --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).js.diff @@ -0,0 +1,57 @@ +--- old.nodeModulesAllowJsConditionalPackageExports(module=node16).js ++++ new.nodeModulesAllowJsConditionalPackageExports(module=node16).js +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -67, +83 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types index 77f1ff9641..296335f7dc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt index 98529e67ed..0e7496180a 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt @@ -1,12 +1,27 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -18,11 +33,17 @@ index.cjs(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -34,15 +55,17 @@ index.cjs(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.cjs (2 errors) ==== +==== index.cjs (3 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js index 2e7a6a871b..63608c6079 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -157,27 +173,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js.diff index b2a38682a1..9d4af863a7 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).js.diff @@ -1,6 +1,29 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=node18).js +++ new.nodeModulesAllowJsConditionalPackageExports(module=node18).js -@@= skipped -140, +140 lines =@@ +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -18, +34 lines =@@ ts.mjsSource; //// [index.cjs] "use strict"; @@ -58,4 +81,33 @@ +const ts = require("inner/types"); cjsi.cjsSource; mjsi.cjsSource; - typei.implicitCjsSource; \ No newline at end of file + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types index 77f1ff9641..296335f7dc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000..0e7496180a --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt @@ -0,0 +1,153 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.mjsSource; + mjsi.mjsSource; + typei.mjsSource; + ts.mjsSource; +==== index.mjs (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.mjsSource; + mjsi.mjsSource; + typei.mjsSource; + ts.mjsSource; +==== index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.cjsSource; + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const implicitCjsSource = true; +==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const mjsSource = true; +==== node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const cjsSource = true; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./a": { + "require": "./index.cjs", + "node": "./index.mjs" + }, + "./b": { + "import": "./index.mjs", + "node": "./index.cjs" + }, + ".": { + "import": "./index.mjs", + "node": "./index.js" + }, + "./types": { + "types": { + "import": "./index.d.mts", + "require": "./index.d.cts" + }, + "node": { + "import": "./index.mjs", + "require": "./index.cjs" + } + } + } + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js index 62fb2abec9..2f99e51c4c 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -190,27 +206,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js.diff new file mode 100644 index 0000000000..321270cbcb --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js.diff @@ -0,0 +1,57 @@ +--- old.nodeModulesAllowJsConditionalPackageExports(module=nodenext).js ++++ new.nodeModulesAllowJsConditionalPackageExports(module=nodenext).js +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -67, +83 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types index 77f1ff9641..296335f7dc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt index a443d0e020..0543bf37ed 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt @@ -1,15 +1,30 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cjs(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -19,11 +34,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -33,15 +54,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.cjs (3 errors) ==== +==== index.cjs (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js index 208b7a1a36..817ed97973 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -151,25 +165,11 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js.diff new file mode 100644 index 0000000000..4b82b99738 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).js.diff @@ -0,0 +1,53 @@ +--- old.nodeModulesAllowJsPackageExports(module=node16).js ++++ new.nodeModulesAllowJsPackageExports(module=node16).js +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -63, +77 lines =@@ + cjsi; + mjsi; + typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).types index 53d6637e86..794aab4871 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node16).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt index a443d0e020..0543bf37ed 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt @@ -1,15 +1,30 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cjs(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -==== index.js (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -19,11 +34,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -33,15 +54,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.cjs (3 errors) ==== +==== index.cjs (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js index acd2fda96f..71df78c720 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -118,25 +132,11 @@ const typei = require("inner"); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js.diff index d1e301cc9d..26dc4e113f 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).js.diff @@ -1,6 +1,27 @@ --- old.nodeModulesAllowJsPackageExports(module=node18).js +++ new.nodeModulesAllowJsPackageExports(module=node18).js -@@= skipped -103, +103 lines =@@ +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -16, +30 lines =@@ typei; //// [index.cjs] "use strict"; @@ -42,18 +63,50 @@ -const cjs = __importStar(require("package/cjs")); -const mjs = __importStar(require("package/mjs")); -const type = __importStar(require("package")); -+const cjs = require("package/cjs"); -+const mjs = require("package/mjs"); -+const type = require("package"); - cjs; - mjs; - type; +-cjs; +-mjs; +-type; -const cjsi = __importStar(require("inner/cjs")); -const mjsi = __importStar(require("inner/mjs")); -const typei = __importStar(require("inner")); +-cjsi; +-mjsi; +-typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++const cjs = require("package/cjs"); ++const mjs = require("package/mjs"); ++const type = require("package"); ++cjs; ++mjs; ++type; +const cjsi = require("inner/cjs"); +const mjsi = require("inner/mjs"); +const typei = require("inner"); - cjsi; - mjsi; - typei; \ No newline at end of file ++cjsi; ++mjsi; ++typei; ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).types index 53d6637e86..794aab4871 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=node18).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000..4297bbb071 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt @@ -0,0 +1,118 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== index.mjs (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js index 208b7a1a36..817ed97973 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -151,25 +165,11 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js.diff new file mode 100644 index 0000000000..66c28515a1 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).js.diff @@ -0,0 +1,53 @@ +--- old.nodeModulesAllowJsPackageExports(module=nodenext).js ++++ new.nodeModulesAllowJsPackageExports(module=nodenext).js +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -63, +77 lines =@@ + cjsi; + mjsi; + typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types index 53d6637e86..794aab4871 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types @@ -3,22 +3,22 @@ === index.js === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mjs === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cjs === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt index cda549c5c6..6aecf9a590 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt @@ -1,32 +1,55 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. +error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; -==== index.cjs (2 errors) ==== +==== index.cjs (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; ~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js index 510e6b7128..ca3aa0ac43 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js @@ -37,6 +37,14 @@ type; } } +//// [index.js] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; //// [index.mjs] // esm format file import * as cjs from "#cjs"; @@ -88,19 +96,11 @@ const type = __importStar(require("#type")); cjs; mjs; type; -//// [index.js] -// esm format file -import * as cjs from "#cjs"; -import * as mjs from "#mjs"; -import * as type from "#type"; -cjs; -mjs; -type; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js.diff new file mode 100644 index 0000000000..0f2802e9b2 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).js.diff @@ -0,0 +1,41 @@ +--- old.nodeModulesAllowJsPackageImports(module=node16).js ++++ new.nodeModulesAllowJsPackageImports(module=node16).js +@@= skipped -36, +36 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "#cjs"; ++import * as mjs from "#mjs"; ++import * as type from "#type"; ++cjs; ++mjs; ++type; + //// [index.mjs] + // esm format file + import * as cjs from "#cjs"; +@@= skipped -51, +59 lines =@@ + cjs; + mjs; + type; +-//// [index.js] +-// esm format file +-import * as cjs from "#cjs"; +-import * as mjs from "#mjs"; +-import * as type from "#type"; +-cjs; +-mjs; +-type; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).types index b3f59ab58a..12122d2613 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node16).types @@ -3,60 +3,60 @@ === index.js === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.mjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.cjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt index cda549c5c6..6aecf9a590 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt @@ -1,32 +1,55 @@ -index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. -index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. +error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. -==== index.js (0 errors) ==== +!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; -==== index.mjs (0 errors) ==== +==== index.mjs (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; -==== index.cjs (2 errors) ==== +==== index.cjs (3 errors) ==== // esm format file import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. import * as type from "#type"; ~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js index 85adfd4979..f6dffbaa4d 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js @@ -37,6 +37,14 @@ type; } } +//// [index.js] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; //// [index.mjs] // esm format file import * as cjs from "#cjs"; @@ -55,19 +63,11 @@ const type = require("#type"); cjs; mjs; type; -//// [index.js] -// esm format file -import * as cjs from "#cjs"; -import * as mjs from "#mjs"; -import * as type from "#type"; -cjs; -mjs; -type; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js.diff index ee6583bebc..2b0d5022be 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).js.diff @@ -1,6 +1,21 @@ --- old.nodeModulesAllowJsPackageImports(module=node18).js +++ new.nodeModulesAllowJsPackageImports(module=node18).js -@@= skipped -46, +46 lines =@@ +@@= skipped -36, +36 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "#cjs"; ++import * as mjs from "#mjs"; ++import * as type from "#type"; ++cjs; ++mjs; ++type; + //// [index.mjs] + // esm format file + import * as cjs from "#cjs"; +@@= skipped -10, +18 lines =@@ type; //// [index.cjs] "use strict"; @@ -42,9 +57,32 @@ -const cjs = __importStar(require("#cjs")); -const mjs = __importStar(require("#mjs")); -const type = __importStar(require("#type")); +-cjs; +-mjs; +-type; +-//// [index.js] +-// esm format file +-import * as cjs from "#cjs"; +-import * as mjs from "#mjs"; +-import * as type from "#type"; +-cjs; +-mjs; +-type; +- +- +const cjs = require("#cjs"); +const mjs = require("#mjs"); +const type = require("#type"); - cjs; - mjs; - type; \ No newline at end of file ++cjs; ++mjs; ++type; ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).types index b3f59ab58a..12122d2613 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=node18).types @@ -3,60 +3,60 @@ === index.js === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.mjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.cjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt new file mode 100644 index 0000000000..6aecf9a590 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt @@ -0,0 +1,67 @@ +error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. +index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. +index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. + + +!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.js (3 errors) ==== + // esm format file + import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; +==== index.mjs (3 errors) ==== + // esm format file + import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; +==== index.cjs (3 errors) ==== + // esm format file + import * as cjs from "#cjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js", + "imports": { + "#cjs": "./index.cjs", + "#mjs": "./index.mjs", + "#type": "./index.js" + } + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js index 510e6b7128..ca3aa0ac43 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js @@ -37,6 +37,14 @@ type; } } +//// [index.js] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; //// [index.mjs] // esm format file import * as cjs from "#cjs"; @@ -88,19 +96,11 @@ const type = __importStar(require("#type")); cjs; mjs; type; -//// [index.js] -// esm format file -import * as cjs from "#cjs"; -import * as mjs from "#mjs"; -import * as type from "#type"; -cjs; -mjs; -type; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js.diff new file mode 100644 index 0000000000..8b77fd6aeb --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).js.diff @@ -0,0 +1,41 @@ +--- old.nodeModulesAllowJsPackageImports(module=nodenext).js ++++ new.nodeModulesAllowJsPackageImports(module=nodenext).js +@@= skipped -36, +36 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "#cjs"; ++import * as mjs from "#mjs"; ++import * as type from "#type"; ++cjs; ++mjs; ++type; + //// [index.mjs] + // esm format file + import * as cjs from "#cjs"; +@@= skipped -51, +59 lines =@@ + cjs; + mjs; + type; +-//// [index.js] +-// esm format file +-import * as cjs from "#cjs"; +-import * as mjs from "#mjs"; +-import * as type from "#type"; +-cjs; +-mjs; +-type; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types index b3f59ab58a..12122d2613 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types @@ -3,60 +3,60 @@ === index.js === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.mjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any === index.cjs === // esm format file import * as cjs from "#cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "#mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "#type"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt index c68a2e33ac..35c27166e7 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt @@ -1,12 +1,27 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -18,11 +33,17 @@ index.cts(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -34,15 +55,17 @@ index.cts(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.cts (2 errors) ==== +==== index.cts (3 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt.diff index e9942e7cee..db9b2c18e8 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).errors.txt.diff @@ -1,20 +1,117 @@ --- old.nodeModulesConditionalPackageExports(module=node16).errors.txt +++ new.nodeModulesConditionalPackageExports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -+ -+ - ==== index.ts (0 errors) ==== - // esm format file ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.cts (2 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cts (3 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -57, +53 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -57, +76 lines =@@ mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js index 7948f14a95..87d5cda21c 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -190,27 +206,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js.diff new file mode 100644 index 0000000000..5a8f5c9077 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).js.diff @@ -0,0 +1,57 @@ +--- old.nodeModulesConditionalPackageExports(module=node16).js ++++ new.nodeModulesConditionalPackageExports(module=node16).js +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -67, +83 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types index b90aa9f028..548c7f4fc2 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types.diff index 970cae843b..b5d4494171 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node16).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesConditionalPackageExports(module=node16).types +++ new.nodeModulesConditionalPackageExports(module=node16).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt index c68a2e33ac..35c27166e7 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt @@ -1,12 +1,27 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -18,11 +33,17 @@ index.cts(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -34,15 +55,17 @@ index.cts(4,23): error TS1479: The current file is a CommonJS module whose impor mjsi.mjsSource; typei.mjsSource; ts.mjsSource; -==== index.cts (2 errors) ==== +==== index.cts (3 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt.diff index 31501b0fc2..9f08cb4b48 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).errors.txt.diff @@ -1,20 +1,117 @@ --- old.nodeModulesConditionalPackageExports(module=node18).errors.txt +++ new.nodeModulesConditionalPackageExports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -+ -+ - ==== index.ts (0 errors) ==== - // esm format file ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.cts (2 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cts (3 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -57, +53 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -57, +76 lines =@@ mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js index 57a3865f78..f9843b3e1b 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -157,27 +173,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js.diff index 7f755a6060..fbf3a6575b 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).js.diff @@ -1,6 +1,29 @@ --- old.nodeModulesConditionalPackageExports(module=node18).js +++ new.nodeModulesConditionalPackageExports(module=node18).js -@@= skipped -140, +140 lines =@@ +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -18, +34 lines =@@ ts.mjsSource; //// [index.cjs] "use strict"; @@ -58,4 +81,33 @@ +const ts = require("inner/types"); cjsi.cjsSource; mjsi.cjsSource; - typei.implicitCjsSource; \ No newline at end of file + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types index b90aa9f028..548c7f4fc2 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types.diff index 6c697d20b0..5d552d69c5 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=node18).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesConditionalPackageExports(module=node18).types +++ new.nodeModulesConditionalPackageExports(module=node18).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000..35c27166e7 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt @@ -0,0 +1,153 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.mjsSource; + mjsi.mjsSource; + typei.mjsSource; + ts.mjsSource; +==== index.mts (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.mjsSource; + mjsi.mjsSource; + typei.mjsSource; + ts.mjsSource; +==== index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/a"; + import * as mjsi from "inner/b"; + import * as typei from "inner"; + import * as ts from "inner/types"; + cjsi.cjsSource; + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const implicitCjsSource = true; +==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const mjsSource = true; +==== node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; + export { cjs }; + export { mjs }; + export { type }; + export { ts }; + export const cjsSource = true; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./a": { + "require": "./index.cjs", + "node": "./index.mjs" + }, + "./b": { + "import": "./index.mjs", + "node": "./index.cjs" + }, + ".": { + "import": "./index.mjs", + "node": "./index.js" + }, + "./types": { + "types": { + "import": "./index.d.mts", + "require": "./index.d.cts" + }, + "node": { + "import": "./index.mjs", + "require": "./index.cjs" + } + } + } + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt.diff index 93dac80b72..e5d6ca3d03 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).errors.txt.diff @@ -1,12 +1,21 @@ --- old.nodeModulesConditionalPackageExports(module=nodenext).errors.txt +++ new.nodeModulesConditionalPackageExports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.ts (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; @@ -40,97 +49,87 @@ - typei.mjsSource; - ts.mjsSource; -==== index.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "package/cjs"; -- import * as mjs from "package/mjs"; -- import * as type from "package"; -- cjs; -- mjs; -- type; -- import * as cjsi from "inner/a"; -- import * as mjsi from "inner/b"; -- import * as typei from "inner"; -- import * as ts from "inner/types"; -- cjsi.cjsSource; -- mjsi.cjsSource; -- typei.implicitCjsSource; -- ts.cjsSource; ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -51, +76 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; -==== node_modules/inner/index.d.ts (1 errors) ==== -- // cjs format file -- import * as cjs from "inner/a"; ++==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const implicitCjsSource = true; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; +@@= skipped -13, +11 lines =@@ + export { type }; + export { ts }; + export const implicitCjsSource = true; -==== node_modules/inner/index.d.mts (1 errors) ==== -- // esm format file -- import * as cjs from "inner/a"; ++==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/a"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const mjsSource = true; --==== node_modules/inner/index.d.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "inner/a"; -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const cjsSource = true; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } --==== node_modules/inner/package.json (0 errors) ==== -- { -- "name": "inner", -- "private": true, -- "exports": { -- "./a": { -- "require": "./index.cjs", -- "node": "./index.mjs" -- }, -- "./b": { -- "import": "./index.mjs", -- "node": "./index.cjs" -- }, -- ".": { -- "import": "./index.mjs", -- "node": "./index.js" -- }, -- "./types": { -- "types": { -- "import": "./index.d.mts", -- "require": "./index.d.cts" -- }, -- "node": { -- "import": "./index.mjs", -- "require": "./index.cjs" -- } -- } -- } -- } -- -+ \ No newline at end of file + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js index 7948f14a95..87d5cda21c 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js @@ -123,6 +123,22 @@ export const cjsSource = true; } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -190,27 +206,11 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js.diff new file mode 100644 index 0000000000..f1050b1157 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).js.diff @@ -0,0 +1,57 @@ +--- old.nodeModulesConditionalPackageExports(module=nodenext).js ++++ new.nodeModulesConditionalPackageExports(module=nodenext).js +@@= skipped -122, +122 lines =@@ + } + + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/a"; ++import * as mjsi from "inner/b"; ++import * as typei from "inner"; ++import * as ts from "inner/types"; ++cjsi.mjsSource; ++mjsi.mjsSource; ++typei.mjsSource; ++ts.mjsSource; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -67, +83 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/a"; +-import * as mjsi from "inner/b"; +-import * as typei from "inner"; +-import * as ts from "inner/types"; +-cjsi.mjsSource; +-mjsi.mjsSource; +-typei.mjsSource; +-ts.mjsSource; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types index b90aa9f028..548c7f4fc2 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -55,22 +55,22 @@ ts.mjsSource; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi @@ -107,22 +107,22 @@ ts.mjsSource; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/a"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types.diff index 755f4a924e..0fc79c354b 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesConditionalPackageExports(module=nodenext).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesConditionalPackageExports(module=nodenext).types +++ new.nodeModulesConditionalPackageExports(module=nodenext).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt index f82891bb16..7de8927f25 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt @@ -1,6 +1,14 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. @@ -8,11 +16,18 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -22,11 +37,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -36,15 +57,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.cts (3 errors) ==== +==== index.cts (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt.diff index 4add3e1812..73553cbdb4 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt.diff @@ -1,15 +1,108 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt +++ new.nodeModulesDeclarationEmitWithPackageExports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -@@= skipped -8, +7 lines =@@ - node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. + node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. + node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. +@@= skipped -9, +16 lines =@@ --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.ts (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; \ No newline at end of file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.cts (3 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.cts (4 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + export const a = cjs; + export const b = mjs; + export const c = type; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js index db97947085..cec3b8c991 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js @@ -91,6 +91,20 @@ export const cjsNonmain = true; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +export const a = cjs; +export const b = mjs; +export const c = type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +export const d = cjsi; +export const e = mjsi; +export const f = typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -155,58 +169,32 @@ const typei = __importStar(require("inner")); exports.d = cjsi; exports.e = mjsi; exports.f = typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export const a = cjs; -export const b = mjs; -export const c = type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -export const d = cjsi; -export const e = mjsi; -export const f = typei; -//// [index.d.mts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.ts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.cts] -// cjs format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.mts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.ts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.cts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js.diff index 48d94cd137..021f0c8268 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).js.diff @@ -1,26 +1,94 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=node16).js +++ new.nodeModulesDeclarationEmitWithPackageExports(module=node16).js -@@= skipped -171, +171 lines =@@ +@@= skipped -90, +90 lines =@@ + } + } - - //// [index.d.mts] ++//// [index.js] +// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++export const a = cjs; ++export const b = mjs; ++export const c = type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++export const d = cjsi; ++export const e = mjsi; ++export const f = typei; + //// [index.mjs] + // esm format file import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ +@@= skipped -64, +78 lines =@@ + exports.d = cjsi; + exports.e = mjsi; + exports.f = typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export const a = cjs; +-export const b = mjs; +-export const c = type; ++ ++ ++//// [index.d.ts] ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +-export const d = cjsi; +-export const e = mjsi; +-export const f = typei; +- +- ++export declare const d: typeof cjsi; ++export declare const e: typeof mjsi; ++export declare const f: typeof typei; + //// [index.d.mts] +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +@@= skipped -30, +23 lines =@@ export declare const e: typeof mjsi; export declare const f: typeof typei; //// [index.d.cts] -+// cjs format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ - export declare const e: typeof mjsi; - export declare const f: typeof typei; - //// [index.d.ts] -+// esm format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; \ No newline at end of file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-export declare const d: typeof cjsi; +-export declare const e: typeof mjsi; +-export declare const f: typeof typei; +-//// [index.d.ts] +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types index 944099872b..182f0977bc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types @@ -3,25 +3,25 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -47,25 +47,25 @@ export const f = typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -91,25 +91,25 @@ export const f = typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types.diff new file mode 100644 index 0000000000..57724ef3fe --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node16).types.diff @@ -0,0 +1,107 @@ +--- old.nodeModulesDeclarationEmitWithPackageExports(module=node16).types ++++ new.nodeModulesDeclarationEmitWithPackageExports(module=node16).types +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt index f82891bb16..7de8927f25 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt @@ -1,6 +1,14 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. @@ -8,11 +16,18 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -22,11 +37,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -36,15 +57,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.cts (3 errors) ==== +==== index.cts (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt.diff index fe5127f4e7..783da0f98a 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt.diff @@ -1,15 +1,108 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt +++ new.nodeModulesDeclarationEmitWithPackageExports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -@@= skipped -8, +7 lines =@@ - node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. + node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. + node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. +@@= skipped -9, +16 lines =@@ --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.ts (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; \ No newline at end of file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.cts (3 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.cts (4 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + export const a = cjs; + export const b = mjs; + export const c = type; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js index d13987b541..e5c52ba9ab 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js @@ -91,6 +91,20 @@ export const cjsNonmain = true; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +export const a = cjs; +export const b = mjs; +export const c = type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +export const d = cjsi; +export const e = mjsi; +export const f = typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -122,58 +136,32 @@ const typei = require("inner"); exports.d = cjsi; exports.e = mjsi; exports.f = typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export const a = cjs; -export const b = mjs; -export const c = type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -export const d = cjsi; -export const e = mjsi; -export const f = typei; -//// [index.d.mts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.ts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.cts] -// cjs format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.mts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.ts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.cts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js.diff index 4443916e75..1e02f710e6 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).js.diff @@ -1,6 +1,27 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=node18).js +++ new.nodeModulesDeclarationEmitWithPackageExports(module=node18).js -@@= skipped -106, +106 lines =@@ +@@= skipped -90, +90 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++export const a = cjs; ++export const b = mjs; ++export const c = type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++export const d = cjsi; ++export const e = mjsi; ++export const f = typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -16, +30 lines =@@ export const f = typei; //// [index.cjs] "use strict"; @@ -58,27 +79,70 @@ exports.d = cjsi; exports.e = mjsi; exports.f = typei; -@@= skipped -65, +32 lines =@@ - - +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export const a = cjs; +-export const b = mjs; +-export const c = type; ++ ++ ++//// [index.d.ts] ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +-export const d = cjsi; +-export const e = mjsi; +-export const f = typei; +- +- ++export declare const d: typeof cjsi; ++export declare const e: typeof mjsi; ++export declare const f: typeof typei; //// [index.d.mts] -+// esm format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +@@= skipped -78, +38 lines =@@ export declare const e: typeof mjsi; export declare const f: typeof typei; //// [index.d.cts] -+// cjs format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ - export declare const e: typeof mjsi; - export declare const f: typeof typei; - //// [index.d.ts] -+// esm format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; \ No newline at end of file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-export declare const d: typeof cjsi; +-export declare const e: typeof mjsi; +-export declare const f: typeof typei; +-//// [index.d.ts] +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types index 944099872b..182f0977bc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types @@ -3,25 +3,25 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -47,25 +47,25 @@ export const f = typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -91,25 +91,25 @@ export const f = typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types.diff new file mode 100644 index 0000000000..0e8041ff08 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=node18).types.diff @@ -0,0 +1,107 @@ +--- old.nodeModulesDeclarationEmitWithPackageExports(module=node18).types ++++ new.nodeModulesDeclarationEmitWithPackageExports(module=node18).types +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt index ee951d981a..0dbba02dff 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt @@ -1,13 +1,30 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -17,11 +34,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; @@ -31,11 +54,17 @@ node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in export const d = cjsi; export const e = mjsi; export const f = typei; -==== index.cts (0 errors) ==== +==== index.cts (3 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. export const a = cjs; export const b = mjs; export const c = type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt.diff index aacb51049e..3aafdb3bf0 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt.diff @@ -1,13 +1,102 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt +++ new.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.ts (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; \ No newline at end of file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- export const a = cjs; +- export const b = mjs; +- export const c = type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- export const d = cjsi; +- export const e = mjsi; +- export const f = typei; +-==== index.cts (0 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ export const a = cjs; ++ export const b = mjs; ++ export const c = type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ export const d = cjsi; ++ export const e = mjsi; ++ export const f = typei; ++==== index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + export const a = cjs; + export const b = mjs; + export const c = type; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js index db97947085..cec3b8c991 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js @@ -91,6 +91,20 @@ export const cjsNonmain = true; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +export const a = cjs; +export const b = mjs; +export const c = type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +export const d = cjsi; +export const e = mjsi; +export const f = typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -155,58 +169,32 @@ const typei = __importStar(require("inner")); exports.d = cjsi; exports.e = mjsi; exports.f = typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export const a = cjs; -export const b = mjs; -export const c = type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -export const d = cjsi; -export const e = mjsi; -export const f = typei; -//// [index.d.mts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.ts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.cts] -// cjs format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.mts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; export declare const d: typeof cjsi; export declare const e: typeof mjsi; export declare const f: typeof typei; -//// [index.d.ts] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -export declare const a: typeof cjs; -export declare const b: typeof mjs; -export declare const c: typeof type; +//// [index.d.cts] +export declare const a: any; +export declare const b: any; +export declare const c: any; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; import * as typei from "inner"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js.diff index f1844e2dd5..eb159540ea 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js.diff @@ -1,26 +1,94 @@ --- old.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js +++ new.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js -@@= skipped -171, +171 lines =@@ +@@= skipped -90, +90 lines =@@ + } + } - - //// [index.d.mts] ++//// [index.js] +// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++export const a = cjs; ++export const b = mjs; ++export const c = type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++export const d = cjsi; ++export const e = mjsi; ++export const f = typei; + //// [index.mjs] + // esm format file import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ +@@= skipped -64, +78 lines =@@ + exports.d = cjsi; + exports.e = mjsi; + exports.f = typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export const a = cjs; +-export const b = mjs; +-export const c = type; ++ ++ ++//// [index.d.ts] ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +-export const d = cjsi; +-export const e = mjsi; +-export const f = typei; +- +- ++export declare const d: typeof cjsi; ++export declare const e: typeof mjsi; ++export declare const f: typeof typei; + //// [index.d.mts] +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; +@@= skipped -30, +23 lines =@@ export declare const e: typeof mjsi; export declare const f: typeof typei; //// [index.d.cts] -+// cjs format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; -@@= skipped -13, +14 lines =@@ - export declare const e: typeof mjsi; - export declare const f: typeof typei; - //// [index.d.ts] -+// esm format file - import * as cjs from "package/cjs"; - import * as mjs from "package/mjs"; - import * as type from "package"; \ No newline at end of file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-export declare const d: typeof cjsi; +-export declare const e: typeof mjsi; +-export declare const f: typeof typei; +-//// [index.d.ts] +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-export declare const a: typeof cjs; +-export declare const b: typeof mjs; +-export declare const c: typeof type; ++export declare const a: any; ++export declare const b: any; ++export declare const c: any; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types index 944099872b..182f0977bc 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types @@ -3,25 +3,25 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -47,25 +47,25 @@ export const f = typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -91,25 +91,25 @@ export const f = typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any export const a = cjs; ->a : typeof cjs ->cjs : typeof cjs +>a : any +>cjs : any export const b = mjs; ->b : typeof mjs ->mjs : typeof mjs +>b : any +>mjs : any export const c = type; ->c : typeof type ->type : typeof type +>c : any +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types.diff new file mode 100644 index 0000000000..ae41c0e252 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types.diff @@ -0,0 +1,107 @@ +--- old.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types ++++ new.nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi +@@= skipped -44, +44 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + export const a = cjs; +->a : typeof cjs +->cjs : typeof cjs ++>a : any ++>cjs : any + + export const b = mjs; +->b : typeof mjs +->mjs : typeof mjs ++>b : any ++>mjs : any + + export const c = type; +->c : typeof type +->type : typeof type ++>c : any ++>type : any + + import * as cjsi from "inner/cjs"; + >cjsi : typeof cjsi \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt index ce2e504ca9..c3a3b37e59 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt @@ -1,15 +1,30 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -19,11 +34,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -33,15 +54,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.cts (3 errors) ==== +==== index.cts (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt.diff index e5ce7ee5df..416acbdd60 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).errors.txt.diff @@ -1,20 +1,111 @@ --- old.nodeModulesPackageExports(module=node16).errors.txt +++ new.nodeModulesPackageExports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.ts (0 errors) ==== - // esm format file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.cts (3 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cts (4 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -55, +52 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -55, +75 lines =@@ cjsi; mjsi; typei; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js index 7d1a5738c7..53f53dc3c1 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -151,25 +165,11 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js.diff new file mode 100644 index 0000000000..8d29012f51 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).js.diff @@ -0,0 +1,53 @@ +--- old.nodeModulesPackageExports(module=node16).js ++++ new.nodeModulesPackageExports(module=node16).js +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -63, +77 lines =@@ + cjsi; + mjsi; + typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types index 91545a2fd7..67faa06aa6 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types.diff index 5d66cd5bfc..edf00e2a30 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node16).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesPackageExports(module=node16).types +++ new.nodeModulesPackageExports(module=node16).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt index ce2e504ca9..c3a3b37e59 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt @@ -1,15 +1,30 @@ -index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. -index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -==== index.ts (0 errors) ==== +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -19,11 +34,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.mts (0 errors) ==== +==== index.mts (3 errors) ==== // esm format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; @@ -33,15 +54,17 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ cjsi; mjsi; typei; -==== index.cts (3 errors) ==== +==== index.cts (4 errors) ==== // cjs format file import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. import * as type from "package"; ~~~~~~~~~ -!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. cjs; mjs; type; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt.diff index 549e862520..b95e8cb421 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).errors.txt.diff @@ -1,20 +1,111 @@ --- old.nodeModulesPackageExports(module=node18).errors.txt +++ new.nodeModulesPackageExports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cts(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cts(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.ts (0 errors) ==== - // esm format file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.ts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.mts (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.cts (3 errors) ==== ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cts (4 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -55, +52 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -55, +75 lines =@@ cjsi; mjsi; typei; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js index afeca4d652..495945686c 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -118,25 +132,11 @@ const typei = require("inner"); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js.diff index 684c35f444..646830d128 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).js.diff @@ -1,6 +1,27 @@ --- old.nodeModulesPackageExports(module=node18).js +++ new.nodeModulesPackageExports(module=node18).js -@@= skipped -103, +103 lines =@@ +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -16, +30 lines =@@ typei; //// [index.cjs] "use strict"; @@ -42,18 +63,50 @@ -const cjs = __importStar(require("package/cjs")); -const mjs = __importStar(require("package/mjs")); -const type = __importStar(require("package")); -+const cjs = require("package/cjs"); -+const mjs = require("package/mjs"); -+const type = require("package"); - cjs; - mjs; - type; +-cjs; +-mjs; +-type; -const cjsi = __importStar(require("inner/cjs")); -const mjsi = __importStar(require("inner/mjs")); -const typei = __importStar(require("inner")); +-cjsi; +-mjsi; +-typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++const cjs = require("package/cjs"); ++const mjs = require("package/mjs"); ++const type = require("package"); ++cjs; ++mjs; ++type; +const cjsi = require("inner/cjs"); +const mjsi = require("inner/mjs"); +const typei = require("inner"); - cjsi; - mjsi; - typei; \ No newline at end of file ++cjsi; ++mjsi; ++typei; ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types index 91545a2fd7..67faa06aa6 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types.diff index e7aec06a09..7d89191a71 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=node18).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesPackageExports(module=node18).types +++ new.nodeModulesPackageExports(module=node18).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000..965adec9a2 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt @@ -0,0 +1,118 @@ +error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. +index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. +index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. +index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + +!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +==== index.ts (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== index.mts (3 errors) ==== + // esm format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt.diff index 8664f03d23..959f1e7201 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).errors.txt.diff @@ -1,11 +1,20 @@ --- old.nodeModulesPackageExports(module=nodenext).errors.txt +++ new.nodeModulesPackageExports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.ts(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.ts(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.ts(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.ts (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; @@ -35,64 +44,70 @@ - mjsi; - typei; -==== index.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "package/cjs"; -- import * as mjs from "package/mjs"; -- import * as type from "package"; -- cjs; -- mjs; -- type; -- import * as cjsi from "inner/cjs"; -- import * as mjsi from "inner/mjs"; -- import * as typei from "inner"; -- cjsi; -- mjsi; -- typei; ++==== index.ts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mts (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -44, +70 lines =@@ + cjsi; + mjsi; + typei; -==== node_modules/inner/index.d.ts (1 errors) ==== -- // cjs format file -- import * as cjs from "inner/cjs"; ++==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== node_modules/inner/index.d.mts (0 errors) ==== -- // esm format file -- import * as cjs from "inner/cjs"; -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== node_modules/inner/index.d.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "inner/cjs"; -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } --==== node_modules/inner/package.json (0 errors) ==== -- { -- "name": "inner", -- "private": true, -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } -+ \ No newline at end of file + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js index 7d1a5738c7..53f53dc3c1 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js @@ -88,6 +88,20 @@ export { type }; } } +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -151,25 +165,11 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; +//// [index.d.ts] +export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; -//// [index.d.ts] -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js.diff new file mode 100644 index 0000000000..e6df4ccb71 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).js.diff @@ -0,0 +1,53 @@ +--- old.nodeModulesPackageExports(module=nodenext).js ++++ new.nodeModulesPackageExports(module=nodenext).js +@@= skipped -87, +87 lines =@@ + } + } + ++//// [index.js] ++// esm format file ++import * as cjs from "package/cjs"; ++import * as mjs from "package/mjs"; ++import * as type from "package"; ++cjs; ++mjs; ++type; ++import * as cjsi from "inner/cjs"; ++import * as mjsi from "inner/mjs"; ++import * as typei from "inner"; ++cjsi; ++mjsi; ++typei; + //// [index.mjs] + // esm format file + import * as cjs from "package/cjs"; +@@= skipped -63, +77 lines =@@ + cjsi; + mjsi; + typei; +-//// [index.js] +-// esm format file +-import * as cjs from "package/cjs"; +-import * as mjs from "package/mjs"; +-import * as type from "package"; +-cjs; +-mjs; +-type; +-import * as cjsi from "inner/cjs"; +-import * as mjsi from "inner/mjs"; +-import * as typei from "inner"; +-cjsi; +-mjsi; +-typei; +- +- ++ ++ ++//// [index.d.ts] ++export {}; + //// [index.d.mts] + export {}; + //// [index.d.cts] +-export {}; +-//// [index.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types index 91545a2fd7..67faa06aa6 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types @@ -3,22 +3,22 @@ === index.ts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -41,22 +41,22 @@ typei; === index.mts === // esm format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi @@ -79,22 +79,22 @@ typei; === index.cts === // cjs format file import * as cjs from "package/cjs"; ->cjs : typeof cjs +>cjs : any import * as mjs from "package/mjs"; ->mjs : typeof mjs +>mjs : any import * as type from "package"; ->type : typeof type +>type : any cjs; ->cjs : typeof cjs +>cjs : any mjs; ->mjs : typeof mjs +>mjs : any type; ->type : typeof type +>type : any import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types.diff index 978703cae3..9730a78e76 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesPackageExports(module=nodenext).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesPackageExports(module=nodenext).types +++ new.nodeModulesPackageExports(module=nodenext).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.ts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mts === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cts === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt.diff index dad6391b99..0421736050 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).errors.txt.diff @@ -1,11 +1,34 @@ --- old.nodeAllowJsPackageSelfName(module=node16).errors.txt +++ new.nodeAllowJsPackageSelfName(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== ++==== index.js (1 errors) ==== // esm format file - import * as self from "package"; \ No newline at end of file + import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; +-==== index.mjs (0 errors) ==== ++==== index.mjs (1 errors) ==== + // esm format file + import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; + ==== index.cjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; + ==== package.json (0 errors) ==== + { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).types.diff new file mode 100644 index 0000000000..79579e2c3d --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node16).types.diff @@ -0,0 +1,32 @@ +--- old.nodeAllowJsPackageSelfName(module=node16).types ++++ new.nodeAllowJsPackageSelfName(module=node16).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.mjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.cjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt.diff index 4c45ede330..636c794545 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).errors.txt.diff @@ -1,11 +1,34 @@ --- old.nodeAllowJsPackageSelfName(module=node18).errors.txt +++ new.nodeAllowJsPackageSelfName(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(2,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== ++==== index.js (1 errors) ==== // esm format file - import * as self from "package"; \ No newline at end of file + import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; +-==== index.mjs (0 errors) ==== ++==== index.mjs (1 errors) ==== + // esm format file + import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; + ==== index.cjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; + ==== package.json (0 errors) ==== + { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).types.diff new file mode 100644 index 0000000000..993201ddcc --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=node18).types.diff @@ -0,0 +1,32 @@ +--- old.nodeAllowJsPackageSelfName(module=node18).types ++++ new.nodeAllowJsPackageSelfName(module=node18).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.mjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.cjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt.diff index ed0557e4a3..04b57f5a08 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).errors.txt.diff @@ -1,10 +1,13 @@ --- old.nodeAllowJsPackageSelfName(module=nodenext).errors.txt +++ new.nodeAllowJsPackageSelfName(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.js (0 errors) ==== - // esm format file - import * as self from "package"; @@ -16,12 +19,23 @@ -==== index.cjs (0 errors) ==== - // esm format file - import * as self from "package"; -- self; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": "./index.js" -- } -+ \ No newline at end of file ++==== index.js (1 errors) ==== ++ // esm format file ++ import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ self; ++==== index.mjs (1 errors) ==== ++ // esm format file ++ import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ self; ++==== index.cjs (1 errors) ==== ++ // esm format file ++ import * as self from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + self; + ==== package.json (0 errors) ==== + { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).types.diff new file mode 100644 index 0000000000..8a0fbd3733 --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName(module=nodenext).types.diff @@ -0,0 +1,32 @@ +--- old.nodeAllowJsPackageSelfName(module=nodenext).types ++++ new.nodeAllowJsPackageSelfName(module=nodenext).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.mjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any + + === index.cjs === + // esm format file + import * as self from "package"; +->self : typeof self ++>self : any + + self; +->self : typeof self ++>self : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName2.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName2.types.diff deleted file mode 100644 index fc132a3084..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeAllowJsPackageSelfName2.types.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- old.nodeAllowJsPackageSelfName2.types -+++ new.nodeAllowJsPackageSelfName2.types -@@= skipped -8, +8 lines =@@ - import { foo } from "js-self-name-import/foo.js"; - >foo : 1 - -+=== /types/src/foo.d.ts === -+export const foo: 1; -+>foo : 1 -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt.diff index 58b08fb0e3..e08d1da38d 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt.diff @@ -1,20 +1,117 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt +++ new.nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -+ -+ - ==== index.js (0 errors) ==== - // esm format file ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.cjs (2 errors) ==== ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cjs (3 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -57, +53 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -57, +76 lines =@@ mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types.diff index f0596cf245..2dffe05f69 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node16).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=node16).types +++ new.nodeModulesAllowJsConditionalPackageExports(module=node16).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt.diff index 2de1a10500..1dc19bd5b1 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt.diff @@ -1,20 +1,117 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt +++ new.nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -+ -+ - ==== index.js (0 errors) ==== - // esm format file ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/a"; +- import * as mjsi from "inner/b"; +- import * as typei from "inner"; +- import * as ts from "inner/types"; +- cjsi.mjsSource; +- mjsi.mjsSource; +- typei.mjsSource; +- ts.mjsSource; +-==== index.cjs (2 errors) ==== ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cjs (3 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -57, +53 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -57, +76 lines =@@ mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types.diff index e8981477a2..d7b146de5d 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=node18).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=node18).types +++ new.nodeModulesAllowJsConditionalPackageExports(module=node18).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt.diff index 0205855c12..2ef14964d2 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt.diff @@ -1,12 +1,21 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt +++ new.nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.js (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; @@ -40,97 +49,87 @@ - typei.mjsSource; - ts.mjsSource; -==== index.cjs (0 errors) ==== -- // cjs format file -- import * as cjs from "package/cjs"; -- import * as mjs from "package/mjs"; -- import * as type from "package"; -- cjs; -- mjs; -- type; -- import * as cjsi from "inner/a"; -- import * as mjsi from "inner/b"; -- import * as typei from "inner"; -- import * as ts from "inner/types"; -- cjsi.cjsSource; -- mjsi.cjsSource; -- typei.implicitCjsSource; -- ts.cjsSource; ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/a"; ++ import * as mjsi from "inner/b"; ++ import * as typei from "inner"; ++ import * as ts from "inner/types"; ++ cjsi.mjsSource; ++ mjsi.mjsSource; ++ typei.mjsSource; ++ ts.mjsSource; ++==== index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -51, +76 lines =@@ + mjsi.cjsSource; + typei.implicitCjsSource; + ts.cjsSource; -==== node_modules/inner/index.d.ts (1 errors) ==== -- // cjs format file -- import * as cjs from "inner/a"; ++==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/a"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const implicitCjsSource = true; + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; +@@= skipped -13, +11 lines =@@ + export { type }; + export { ts }; + export const implicitCjsSource = true; -==== node_modules/inner/index.d.mts (1 errors) ==== -- // esm format file -- import * as cjs from "inner/a"; ++==== node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/a"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const mjsSource = true; --==== node_modules/inner/index.d.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "inner/a"; -- import * as mjs from "inner/b"; -- import * as type from "inner"; -- import * as ts from "inner/types"; -- export { cjs }; -- export { mjs }; -- export { type }; -- export { ts }; -- export const cjsSource = true; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } --==== node_modules/inner/package.json (0 errors) ==== -- { -- "name": "inner", -- "private": true, -- "exports": { -- "./a": { -- "require": "./index.cjs", -- "node": "./index.mjs" -- }, -- "./b": { -- "import": "./index.mjs", -- "node": "./index.cjs" -- }, -- ".": { -- "import": "./index.mjs", -- "node": "./index.js" -- }, -- "./types": { -- "types": { -- "import": "./index.d.mts", -- "require": "./index.d.cts" -- }, -- "node": { -- "import": "./index.mjs", -- "require": "./index.cjs" -- } -- } -- } -- } -- -+ \ No newline at end of file + import * as mjs from "inner/b"; + import * as type from "inner"; + import * as ts from "inner/types"; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types.diff index 77f3f24530..68322d3ac2 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types.diff @@ -1,6 +1,93 @@ --- old.nodeModulesAllowJsConditionalPackageExports(module=nodenext).types +++ new.nodeModulesAllowJsConditionalPackageExports(module=nodenext).types -@@= skipped -130, +130 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -52, +52 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/a"; + >cjsi : typeof cjsi +@@= skipped -24, +24 lines =@@ >mjsi : typeof cjsi import * as typei from "inner"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt.diff index 53583e22aa..e593bff0b7 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).errors.txt.diff @@ -1,20 +1,111 @@ --- old.nodeModulesAllowJsPackageExports(module=node16).errors.txt +++ new.nodeModulesAllowJsPackageExports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cjs(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== - // esm format file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.cjs (3 errors) ==== ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cjs (4 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -55, +52 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -55, +75 lines =@@ cjsi; mjsi; typei; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).types.diff index 470716ed80..fef834137b 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node16).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesAllowJsPackageExports(module=node16).types +++ new.nodeModulesAllowJsPackageExports(module=node16).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt.diff index d606aad7ef..7df9bf176f 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).errors.txt.diff @@ -1,20 +1,111 @@ --- old.nodeModulesAllowJsPackageExports(module=node18).errors.txt +++ new.nodeModulesAllowJsPackageExports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. index.cjs(9,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. node_modules/inner/index.d.cts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("inner/mjs")' call instead. --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== - // esm format file + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "package/cjs"; +- import * as mjs from "package/mjs"; +- import * as type from "package"; +- cjs; +- mjs; +- type; +- import * as cjsi from "inner/cjs"; +- import * as mjsi from "inner/mjs"; +- import * as typei from "inner"; +- cjsi; +- mjsi; +- typei; +-==== index.cjs (3 errors) ==== ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cjs (4 errors) ==== + // cjs format file import * as cjs from "package/cjs"; -@@= skipped -55, +52 lines =@@ ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package/mjs")' call instead. ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; + ~~~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package")' call instead. ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -55, +75 lines =@@ cjsi; mjsi; typei; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).types.diff index 48e501c428..0cb07ae47e 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=node18).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesAllowJsPackageExports(module=node18).types +++ new.nodeModulesAllowJsPackageExports(module=node18).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt.diff index 440a91b5c4..c15c3e629d 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt.diff @@ -1,11 +1,20 @@ --- old.nodeModulesAllowJsPackageExports(module=nodenext).errors.txt +++ new.nodeModulesAllowJsPackageExports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -- -- --!!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module 'package' or its corresponding type declarations. + + + !!! error TS2209: The project root is ambiguous, but is required to resolve export map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.js (0 errors) ==== - // esm format file - import * as cjs from "package/cjs"; @@ -35,64 +44,70 @@ - mjsi; - typei; -==== index.cjs (0 errors) ==== -- // cjs format file -- import * as cjs from "package/cjs"; -- import * as mjs from "package/mjs"; -- import * as type from "package"; -- cjs; -- mjs; -- type; -- import * as cjsi from "inner/cjs"; -- import * as mjsi from "inner/mjs"; -- import * as typei from "inner"; -- cjsi; -- mjsi; -- typei; ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. ++ import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. ++ import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++ import * as cjsi from "inner/cjs"; ++ import * as mjsi from "inner/mjs"; ++ import * as typei from "inner"; ++ cjsi; ++ mjsi; ++ typei; ++==== index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/cjs' or its corresponding type declarations. + import * as mjs from "package/mjs"; ++ ~~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package/mjs' or its corresponding type declarations. + import * as type from "package"; ++ ~~~~~~~~~ ++!!! error TS2307: Cannot find module 'package' or its corresponding type declarations. + cjs; + mjs; + type; +@@= skipped -44, +70 lines =@@ + cjsi; + mjsi; + typei; -==== node_modules/inner/index.d.ts (1 errors) ==== -- // cjs format file -- import * as cjs from "inner/cjs"; ++==== node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; - ~~~ -!!! error TS2303: Circular definition of import alias 'cjs'. -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== node_modules/inner/index.d.mts (0 errors) ==== -- // esm format file -- import * as cjs from "inner/cjs"; -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== node_modules/inner/index.d.cts (0 errors) ==== -- // cjs format file -- import * as cjs from "inner/cjs"; -- import * as mjs from "inner/mjs"; -- import * as type from "inner"; -- export { cjs }; -- export { mjs }; -- export { type }; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } --==== node_modules/inner/package.json (0 errors) ==== -- { -- "name": "inner", -- "private": true, -- "exports": { -- "./cjs": "./index.cjs", -- "./mjs": "./index.mjs", -- ".": "./index.js" -- } -- } -+ \ No newline at end of file + import * as mjs from "inner/mjs"; + import * as type from "inner"; + export { cjs }; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types.diff index cd1be96c79..9090c96128 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageExports(module=nodenext).types.diff @@ -1,6 +1,33 @@ --- old.nodeModulesAllowJsPackageExports(module=nodenext).types +++ new.nodeModulesAllowJsPackageExports(module=nodenext).types -@@= skipped -23, +23 lines =@@ +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -9,7 +36,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -18,7 +45,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.mjs === + // esm format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -27,7 +81,7 @@ import * as typei from "inner"; >typei : typeof typei -@@= skipped -9, +9 lines =@@ +@@= skipped -30, +30 lines =@@ >cjsi : typeof cjsi mjsi; @@ -36,7 +90,34 @@ typei; >typei : typeof typei -@@= skipped -29, +29 lines =@@ +@@= skipped -8, +8 lines =@@ + === index.cjs === + // cjs format file + import * as cjs from "package/cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "package/mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "package"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + import * as cjsi from "inner/cjs"; >cjsi : typeof cjsi import * as mjsi from "inner/mjs"; @@ -84,7 +165,7 @@ === node_modules/inner/index.d.mts === // esm format file -@@= skipped -40, +40 lines =@@ +@@= skipped -61, +61 lines =@@ >cjs : typeof cjs import * as mjs from "inner/mjs"; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt.diff index 1d2cbe9b35..3ec447979a 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).errors.txt.diff @@ -1,12 +1,85 @@ --- old.nodeModulesAllowJsPackageImports(module=node16).errors.txt +++ new.nodeModulesAllowJsPackageImports(module=node16).errors.txt @@= skipped -0, +0 lines =@@ --error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. + error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. ++index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. --!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== - // esm format file - import * as cjs from "#cjs"; \ No newline at end of file + !!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- import * as type from "#type"; +- cjs; +- mjs; +- type; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- import * as type from "#type"; +- cjs; +- mjs; +- type; +-==== index.cjs (2 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- ~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +- import * as type from "#type"; +- ~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.cjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).types.diff new file mode 100644 index 0000000000..1e99d930e1 --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node16).types.diff @@ -0,0 +1,80 @@ +--- old.nodeModulesAllowJsPackageImports(module=node16).types ++++ new.nodeModulesAllowJsPackageImports(module=node16).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.mjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.cjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt.diff index 110b3d4008..6871e9e601 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).errors.txt.diff @@ -1,12 +1,85 @@ --- old.nodeModulesAllowJsPackageImports(module=node18).errors.txt +++ new.nodeModulesAllowJsPackageImports(module=node18).errors.txt @@= skipped -0, +0 lines =@@ --error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. - index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. + error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-index.cjs(3,22): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +-index.cjs(4,23): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. ++index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. --!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. - ==== index.js (0 errors) ==== - // esm format file - import * as cjs from "#cjs"; \ No newline at end of file + !!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. +-==== index.js (0 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- import * as type from "#type"; +- cjs; +- mjs; +- type; +-==== index.mjs (0 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- import * as type from "#type"; +- cjs; +- mjs; +- type; +-==== index.cjs (2 errors) ==== +- // esm format file +- import * as cjs from "#cjs"; +- import * as mjs from "#mjs"; +- ~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#mjs")' call instead. +- import * as type from "#type"; +- ~~~~~~~ +-!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#type")' call instead. ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.cjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).types.diff new file mode 100644 index 0000000000..9296719a24 --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=node18).types.diff @@ -0,0 +1,80 @@ +--- old.nodeModulesAllowJsPackageImports(module=node18).types ++++ new.nodeModulesAllowJsPackageImports(module=node18).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.mjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.cjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt.diff index 493bdc69ed..b544ab3250 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt.diff @@ -1,10 +1,19 @@ --- old.nodeModulesAllowJsPackageImports(module=nodenext).errors.txt +++ new.nodeModulesAllowJsPackageImports(module=nodenext).errors.txt @@= skipped -0, +0 lines =@@ --error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -- -- --!!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. + error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. ++index.cjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.cjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.cjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.js(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.js(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.js(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. ++index.mjs(2,22): error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++index.mjs(3,22): error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++index.mjs(4,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. + + + !!! error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'package.json'. Supply the `rootDir` compiler option to disambiguate. -==== index.js (0 errors) ==== - // esm format file - import * as cjs from "#cjs"; @@ -26,19 +35,45 @@ - import * as cjs from "#cjs"; - import * as mjs from "#mjs"; - import * as type from "#type"; -- cjs; -- mjs; -- type; --==== package.json (0 errors) ==== -- { -- "name": "package", -- "private": true, -- "type": "module", -- "exports": "./index.js", -- "imports": { -- "#cjs": "./index.cjs", -- "#mjs": "./index.mjs", -- "#type": "./index.js" -- } -- } -+ \ No newline at end of file ++==== index.js (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.mjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. ++ cjs; ++ mjs; ++ type; ++==== index.cjs (3 errors) ==== ++ // esm format file ++ import * as cjs from "#cjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#cjs' or its corresponding type declarations. ++ import * as mjs from "#mjs"; ++ ~~~~~~ ++!!! error TS2307: Cannot find module '#mjs' or its corresponding type declarations. ++ import * as type from "#type"; ++ ~~~~~~~ ++!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + cjs; + mjs; + type; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types.diff new file mode 100644 index 0000000000..eceff52ad5 --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/nodeModulesAllowJsPackageImports(module=nodenext).types.diff @@ -0,0 +1,80 @@ +--- old.nodeModulesAllowJsPackageImports(module=nodenext).types ++++ new.nodeModulesAllowJsPackageImports(module=nodenext).types +@@= skipped -2, +2 lines =@@ + === index.js === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.mjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any + + === index.cjs === + // esm format file + import * as cjs from "#cjs"; +->cjs : typeof cjs ++>cjs : any + + import * as mjs from "#mjs"; +->mjs : typeof mjs ++>mjs : any + + import * as type from "#type"; +->type : typeof type ++>type : any + + cjs; +->cjs : typeof cjs ++>cjs : any + + mjs; +->mjs : typeof mjs ++>mjs : any + + type; +->type : typeof type ++>type : any diff --git a/testdata/tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts b/testdata/tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts new file mode 100644 index 0000000000..50d2917404 --- /dev/null +++ b/testdata/tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts @@ -0,0 +1,40 @@ +// @strict: true +// @noEmit: true + +class A { + next: A | null = null; + + constructor(readonly children: (A | null)[]) {} +} + +function getNodes(): A[] { + const out: A[] = []; + + let current: A | null = new A([]); + + while (current !== null) { + let firstChild = null; + + if (out.length) { + current = current.next; + continue; + } + + for (let i = 0; i < current.children.length; i++) { + const child = current.children[i]; + + if (child) { + if (!firstChild) { + firstChild = child; + firstChild.next = current.next; + } + + child.next = current.next; + } + } + + current = firstChild || current.next; + } + + return out; +} \ No newline at end of file diff --git a/testdata/tests/cases/compiler/subpathImportsJS.ts b/testdata/tests/cases/compiler/subpathImportsJS.ts new file mode 100644 index 0000000000..b00ed77066 --- /dev/null +++ b/testdata/tests/cases/compiler/subpathImportsJS.ts @@ -0,0 +1,26 @@ +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "outDir": "dist", + "rootDir": "src", + "declaration": true, + }, + "include": ["src/*.ts"] +} + +// @Filename: /package.json +{ + "name": "pkg", + "type": "module", + "imports": { + "#subpath": "./dist/subpath.js" + } +} + +// @Filename: /src/subpath.ts +export const foo = "foo"; + +// @Filename: /src/index.ts +import { foo } from "#subpath"; +foo;