From 093002c83b856417f1487b0891e27fbfe54653f7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 14 Sep 2021 12:41:12 -0700 Subject: [PATCH 01/12] Initial import/export/self-name support --- src/compiler/checker.ts | 10 +- src/compiler/diagnosticMessages.json | 29 + src/compiler/moduleNameResolver.ts | 520 ++++++++++++-- src/compiler/program.ts | 142 ++-- src/compiler/resolutionCache.ts | 62 +- src/compiler/tsbuildPublic.ts | 6 +- src/compiler/types.ts | 8 +- src/compiler/utilities.ts | 19 +- src/compiler/watchPublic.ts | 4 +- src/server/project.ts | 8 +- src/services/codefixes/convertToEs6Module.ts | 2 +- src/services/codefixes/fixSpelling.ts | 2 +- src/services/findAllReferences.ts | 2 +- src/services/getEditsForFileRename.ts | 5 +- src/services/goToDefinition.ts | 6 +- src/services/services.ts | 4 +- src/services/suggestionDiagnostics.ts | 2 +- src/services/types.ts | 4 +- src/testRunner/unittests/moduleResolution.ts | 12 +- .../unittests/reuseProgramStructure.ts | 19 +- .../unittests/tsserver/typingsInstaller.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 36 +- tests/baselines/reference/api/typescript.d.ts | 32 +- ...sPackageSelfName(module=node12).errors.txt | 24 + ...deAllowJsPackageSelfName(module=node12).js | 63 ++ ...owJsPackageSelfName(module=node12).symbols | 24 + ...llowJsPackageSelfName(module=node12).types | 24 + ...ackageSelfName(module=nodenext).errors.txt | 24 + ...AllowJsPackageSelfName(module=nodenext).js | 63 ++ ...JsPackageSelfName(module=nodenext).symbols | 24 + ...owJsPackageSelfName(module=nodenext).types | 24 + .../nodeModules1(module=node12).errors.txt | 412 ++++++++++- .../reference/nodeModules1(module=node12).js | 359 ++++++++++ .../nodeModules1(module=node12).symbols | 516 +++++++++++++- .../nodeModules1(module=node12).types | 636 +++++++++++++++++ .../nodeModules1(module=nodenext).errors.txt | 412 ++++++++++- .../nodeModules1(module=nodenext).js | 359 ++++++++++ .../nodeModules1(module=nodenext).symbols | 516 +++++++++++++- .../nodeModules1(module=nodenext).types | 636 +++++++++++++++++ ...eModulesAllowJs1(module=node12).errors.txt | 447 +++++++++++- .../nodeModulesAllowJs1(module=node12).js | 363 +++++++++- ...nodeModulesAllowJs1(module=node12).symbols | 518 +++++++++++++- .../nodeModulesAllowJs1(module=node12).types | 638 +++++++++++++++++- ...odulesAllowJs1(module=nodenext).errors.txt | 447 +++++++++++- .../nodeModulesAllowJs1(module=nodenext).js | 363 +++++++++- ...deModulesAllowJs1(module=nodenext).symbols | 518 +++++++++++++- ...nodeModulesAllowJs1(module=nodenext).types | 638 +++++++++++++++++- ...alPackageExports(module=node12).errors.txt | 132 ++++ ...onditionalPackageExports(module=node12).js | 265 ++++++++ ...ionalPackageExports(module=node12).symbols | 243 +++++++ ...itionalPackageExports(module=node12).types | 246 +++++++ ...PackageExports(module=nodenext).errors.txt | 132 ++++ ...ditionalPackageExports(module=nodenext).js | 265 ++++++++ ...nalPackageExports(module=nodenext).symbols | 243 +++++++ ...ionalPackageExports(module=nodenext).types | 246 +++++++ ...JsPackageExports(module=node12).errors.txt | 107 +++ ...lesAllowJsPackageExports(module=node12).js | 213 ++++++ ...lowJsPackageExports(module=node12).symbols | 174 +++++ ...AllowJsPackageExports(module=node12).types | 174 +++++ ...PackageExports(module=nodenext).errors.txt | 107 +++ ...sAllowJsPackageExports(module=nodenext).js | 213 ++++++ ...wJsPackageExports(module=nodenext).symbols | 174 +++++ ...lowJsPackageExports(module=nodenext).types | 174 +++++ ...JsPackageImports(module=node12).errors.txt | 44 ++ ...lesAllowJsPackageImports(module=node12).js | 92 +++ ...lowJsPackageImports(module=node12).symbols | 60 ++ ...AllowJsPackageImports(module=node12).types | 60 ++ ...PackageImports(module=nodenext).errors.txt | 44 ++ ...sAllowJsPackageImports(module=nodenext).js | 92 +++ ...wJsPackageImports(module=nodenext).symbols | 60 ++ ...lowJsPackageImports(module=nodenext).types | 60 ++ ...gePatternExports(module=node12).errors.txt | 78 +++ ...wJsPackagePatternExports(module=node12).js | 172 +++++ ...ckagePatternExports(module=node12).symbols | 120 ++++ ...PackagePatternExports(module=node12).types | 120 ++++ ...PatternExports(module=nodenext).errors.txt | 78 +++ ...sPackagePatternExports(module=nodenext).js | 172 +++++ ...agePatternExports(module=nodenext).symbols | 120 ++++ ...ckagePatternExports(module=nodenext).types | 120 ++++ ...nExportsTrailers(module=node12).errors.txt | 120 ++++ ...gePatternExportsTrailers(module=node12).js | 172 +++++ ...ternExportsTrailers(module=node12).symbols | 120 ++++ ...atternExportsTrailers(module=node12).types | 120 ++++ ...xportsTrailers(module=nodenext).errors.txt | 78 +++ ...PatternExportsTrailers(module=nodenext).js | 172 +++++ ...rnExportsTrailers(module=nodenext).symbols | 120 ++++ ...ternExportsTrailers(module=nodenext).types | 120 ++++ ...alPackageExports(module=node12).errors.txt | 132 ++++ ...onditionalPackageExports(module=node12).js | 265 ++++++++ ...ionalPackageExports(module=node12).symbols | 243 +++++++ ...itionalPackageExports(module=node12).types | 246 +++++++ ...PackageExports(module=nodenext).errors.txt | 132 ++++ ...ditionalPackageExports(module=nodenext).js | 265 ++++++++ ...nalPackageExports(module=nodenext).symbols | 243 +++++++ ...ionalPackageExports(module=nodenext).types | 246 +++++++ ...esPackageExports(module=node12).errors.txt | 107 +++ ...odeModulesPackageExports(module=node12).js | 213 ++++++ ...dulesPackageExports(module=node12).symbols | 174 +++++ ...ModulesPackageExports(module=node12).types | 174 +++++ ...PackageExports(module=nodenext).errors.txt | 107 +++ ...eModulesPackageExports(module=nodenext).js | 213 ++++++ ...lesPackageExports(module=nodenext).symbols | 174 +++++ ...dulesPackageExports(module=nodenext).types | 174 +++++ ...esPackageImports(module=node12).errors.txt | 44 ++ ...odeModulesPackageImports(module=node12).js | 92 +++ ...dulesPackageImports(module=node12).symbols | 60 ++ ...ModulesPackageImports(module=node12).types | 60 ++ ...PackageImports(module=nodenext).errors.txt | 44 ++ ...eModulesPackageImports(module=nodenext).js | 92 +++ ...lesPackageImports(module=nodenext).symbols | 60 ++ ...dulesPackageImports(module=nodenext).types | 60 ++ ...gePatternExports(module=node12).errors.txt | 78 +++ ...lesPackagePatternExports(module=node12).js | 172 +++++ ...ckagePatternExports(module=node12).symbols | 120 ++++ ...PackagePatternExports(module=node12).types | 120 ++++ ...PatternExports(module=nodenext).errors.txt | 78 +++ ...sPackagePatternExports(module=nodenext).js | 172 +++++ ...agePatternExports(module=nodenext).symbols | 120 ++++ ...ckagePatternExports(module=nodenext).types | 120 ++++ ...nExportsTrailers(module=node12).errors.txt | 120 ++++ ...gePatternExportsTrailers(module=node12).js | 172 +++++ ...ternExportsTrailers(module=node12).symbols | 120 ++++ ...atternExportsTrailers(module=node12).types | 120 ++++ ...xportsTrailers(module=nodenext).errors.txt | 78 +++ ...PatternExportsTrailers(module=nodenext).js | 172 +++++ ...rnExportsTrailers(module=nodenext).symbols | 120 ++++ ...ternExportsTrailers(module=nodenext).types | 120 ++++ ...ePackageSelfName(module=node12).errors.txt | 24 + .../nodePackageSelfName(module=node12).js | 63 ++ ...nodePackageSelfName(module=node12).symbols | 24 + .../nodePackageSelfName(module=node12).types | 24 + ...ackageSelfName(module=nodenext).errors.txt | 24 + .../nodePackageSelfName(module=nodenext).js | 63 ++ ...dePackageSelfName(module=nodenext).symbols | 24 + ...nodePackageSelfName(module=nodenext).types | 24 + .../requireOfJsonFileWithAmd.errors.txt | 5 +- .../reference/requireOfJsonFileWithAmd.js | 5 + .../requireOfJsonFileWithAmd.symbols | 10 + .../reference/requireOfJsonFileWithAmd.types | 24 +- ...ireOfJsonFileWithModuleEmitNone.errors.txt | 5 +- .../requireOfJsonFileWithModuleEmitNone.js | 5 + ...equireOfJsonFileWithModuleEmitNone.symbols | 8 + .../requireOfJsonFileWithModuleEmitNone.types | 14 +- .../requireOfJsonFile_PathMapping.trace.json | 18 +- ...t-correctly-with-cts-and-mts-extensions.js | 31 +- .../allowJs/nodeAllowJsPackageSelfName.ts | 24 + .../node/allowJs/nodeModulesAllowJs1.ts | 183 ++++- ...ModulesAllowJsConditionalPackageExports.ts | 126 ++++ .../nodeModulesAllowJsPackageExports.ts | 92 +++ .../nodeModulesAllowJsPackageImports.ts | 41 ++ ...nodeModulesAllowJsPackagePatternExports.ts | 69 ++ ...lesAllowJsPackagePatternExportsTrailers.ts | 69 ++ tests/cases/conformance/node/nodeModules1.ts | 181 +++++ .../nodeModulesConditionalPackageExports.ts | 124 ++++ .../node/nodeModulesPackageExports.ts | 90 +++ .../node/nodeModulesPackageImports.ts | 38 ++ .../node/nodeModulesPackagePatternExports.ts | 67 ++ ...odeModulesPackagePatternExportsTrailers.ts | 67 ++ .../conformance/node/nodePackageSelfName.ts | 21 + 159 files changed, 21494 insertions(+), 321 deletions(-) create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).js create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).symbols create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).types create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).js create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesPackageExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesPackageImports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).types create mode 100644 tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodePackageSelfName(module=node12).js create mode 100644 tests/baselines/reference/nodePackageSelfName(module=node12).symbols create mode 100644 tests/baselines/reference/nodePackageSelfName(module=node12).types create mode 100644 tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodePackageSelfName(module=nodenext).js create mode 100644 tests/baselines/reference/nodePackageSelfName(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodePackageSelfName(module=nodenext).types create mode 100644 tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts create mode 100644 tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts create mode 100644 tests/cases/conformance/node/nodeModulesPackageExports.ts create mode 100644 tests/cases/conformance/node/nodeModulesPackageImports.ts create mode 100644 tests/cases/conformance/node/nodeModulesPackagePatternExports.ts create mode 100644 tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts create mode 100644 tests/cases/conformance/node/nodePackageSelfName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 44e02840e046b..b3ea50f094e60 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -303,7 +303,7 @@ namespace ts { host.getSourceFiles().forEach(sf => { if (!sf.resolvedModules) return; - forEachEntry(sf.resolvedModules, r => { + sf.resolvedModules.forEach(r => { if (r && r.packageId) map.set(r.packageId.name, r.extension === Extension.Dts || !!map.get(r.packageId.name)); }); }); @@ -3325,7 +3325,13 @@ namespace ts { return ambientModule; } const currentSourceFile = getSourceFileOfNode(location); - const resolvedModule = getResolvedModule(currentSourceFile, moduleReference)!; // TODO: GH#18217 + const contextSpecifier = isStringLiteralLike(location) + ? location + : (isImportCall(location) ? location : findAncestor(location, isImportCall))?.arguments[0] || + (isImportDeclaration(location) ? location : findAncestor(location, isImportDeclaration))?.moduleSpecifier || + (isExternalModuleImportEqualsDeclaration(location) ? location : findAncestor(location, isExternalModuleImportEqualsDeclaration))?.moduleReference.expression || + (isExportDeclaration(location) ? location : findAncestor(location, isExportDeclaration))?.moduleSpecifier; + const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : undefined)!; // TODO: GH#18217 const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule); const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 66da25d3ec66a..c5648028d4857 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4843,6 +4843,35 @@ "code": 6257 }, + "Directory '{0}' has no containing package.json scope. Imports will not resolve.": { + "category": "Message", + "code": 6270 + }, + "Import specifier '{0}' does not exist in package.json scope at path '{1}'.": { + "category": "Message", + "code": 6271 + }, + "Invalid import specifier '{0}' has no possible resolutions.": { + "category": "Message", + "code": 6272 + }, + "package.json scope '{0}' has no imports defined.": { + "category": "Message", + "code": 6273 + }, + "package.json scope '{0}' explicitly maps specifier '{1}' to null.": { + "category": "Message", + "code": 6274 + }, + "package.json scope '{0}' has invalid type for target of specifier '{1}'": { + "category": "Message", + "code": 6275 + }, + "Export specifier '{0}' does not exist in package.json scope at path '{1}'.": { + "category": "Message", + "code": 6276 + }, + "Enable project compilation": { "category": "Message", "code": 6302 diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index af8fdf1e3b40a..83355697485e3 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -96,6 +96,7 @@ namespace ts { }; } + /*@internal*/ interface ModuleResolutionState { host: ModuleResolutionHost; compilerOptions: CompilerOptions; @@ -103,6 +104,8 @@ namespace ts { failedLookupLocations: Push; resultFromCache?: ResolvedModuleWithFailedLookupLocations; packageJsonInfoCache: PackageJsonInfoCache | undefined; + features: NodeResolutionFeatures; + conditions: string[]; } /** Just the fields that we use for module resolution. */ @@ -114,6 +117,9 @@ namespace ts { main?: string; tsconfig?: string; type?: string; + imports?: object; + exports?: object; + name?: string; } interface PackageJson extends PackageJsonPathFields { @@ -299,7 +305,7 @@ namespace ts { const containingDirectory = containingFile ? getDirectoryPath(containingFile) : undefined; const perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined; - let result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName); + let result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ undefined); if (result) { if (traceEnabled) { trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile); @@ -334,7 +340,7 @@ namespace ts { } const failedLookupLocations: string[] = []; - const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache }; + const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.AllFeatures, conditions: ["node", "require", "types"] }; let resolved = primaryLookup(); let primary = true; if (!resolved) { @@ -355,7 +361,7 @@ namespace ts { }; } result = { resolvedTypeReferenceDirective, failedLookupLocations }; - perFolderCache?.set(typeReferenceDirectiveName, result); + perFolderCache?.set(typeReferenceDirectiveName, /*mode*/ undefined, result); if (traceEnabled) traceResult(result); return result; @@ -471,12 +477,21 @@ namespace ts { export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache, PackageJsonInfoCache { } + export interface ModeAwareCache { + get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined; + set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this; + delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this; + has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean; + forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void; + size(): number; + } + /** * Cached resolutions per containing directory. * This assumes that any module id will have the same resolution for sibling files located in the same folder. */ export interface PerDirectoryResolutionCache { - getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map; + getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): ModeAwareCache; clear(): void; /** * Updates with the current compilerOptions the cache will operate with. @@ -494,7 +509,7 @@ namespace ts { * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive. */ export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache { - getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; + getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; } export interface PackageJsonInfoCache { @@ -594,7 +609,7 @@ namespace ts { function updateRedirectsMap( options: CompilerOptions, - directoryToModuleNameMap: CacheWithRedirects>, + directoryToModuleNameMap: CacheWithRedirects>, moduleNameToDirectoryMap?: CacheWithRedirects ) { if (!options.configFile) return; @@ -620,7 +635,7 @@ namespace ts { moduleNameToDirectoryMap?.setOwnOptions(options); } - function createPerDirectoryResolutionCache(currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, directoryToModuleNameMap: CacheWithRedirects>): PerDirectoryResolutionCache { + function createPerDirectoryResolutionCache(currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, directoryToModuleNameMap: CacheWithRedirects>): PerDirectoryResolutionCache { return { getOrCreateCacheForDirectory, clear, @@ -637,10 +652,59 @@ namespace ts { function getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference) { const path = toPath(directoryName, currentDirectory, getCanonicalFileName); - return getOrCreateCache>(directoryToModuleNameMap, redirectedReference, path, () => new Map()); + return getOrCreateCache>(directoryToModuleNameMap, redirectedReference, path, () => createModeAwareCache()); + } + } + + /* @internal */ + export function createModeAwareCache(): ModeAwareCache { + const underlying = new Map(); + const memoizedReverseKeys = new Map(); + + const cache: ModeAwareCache = { + get(specifier, mode) { + return underlying.get(getUnderlyingCacheKey(specifier, mode)); + }, + set(specifier, mode, value) { + underlying.set(getUnderlyingCacheKey(specifier, mode), value); + return cache; + }, + delete(specifier, mode) { + underlying.delete(getUnderlyingCacheKey(specifier, mode)); + return cache; + }, + has(specifier, mode) { + return underlying.has(getUnderlyingCacheKey(specifier, mode)); + }, + forEach(cb) { + return underlying.forEach((elem, key) => { + const [specifier, mode] = memoizedReverseKeys.get(key)!; + return cb(elem, specifier, mode); + }); + }, + size() { + return underlying.size; + } + }; + return cache; + + function getUnderlyingCacheKey(specifier: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) { + const result = mode === undefined ? specifier : `${mode}|${specifier}`; + memoizedReverseKeys.set(result, [specifier, mode]); + return result; } } + /* @internal */ + export function zipToModeAwareCache(file: SourceFile, keys: readonly string[], values: readonly V[]): ModeAwareCache { + Debug.assert(keys.length === values.length); + const map = createModeAwareCache(); + for (let i = 0; i < keys.length; ++i) { + map.set(keys[i], getModeForResolutionAtIndex(file, i), values[i]); + } + return map; + } + export function createModuleResolutionCache( currentDirectory: string, getCanonicalFileName: (s: string) => string, @@ -651,14 +715,14 @@ namespace ts { currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, options: undefined, - directoryToModuleNameMap: CacheWithRedirects>, + directoryToModuleNameMap: CacheWithRedirects>, moduleNameToDirectoryMap: CacheWithRedirects, ): ModuleResolutionCache; export function createModuleResolutionCache( currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, options?: CompilerOptions, - directoryToModuleNameMap?: CacheWithRedirects>, + directoryToModuleNameMap?: CacheWithRedirects>, moduleNameToDirectoryMap?: CacheWithRedirects, ): ModuleResolutionCache { const preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap ||= createCacheWithRedirects(options)); @@ -684,9 +748,9 @@ namespace ts { updateRedirectsMap(options, directoryToModuleNameMap!, moduleNameToDirectoryMap); } - function getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache { + function getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache { Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName)); - return getOrCreateCache(moduleNameToDirectoryMap!, redirectedReference, nonRelativeModuleName, createPerModuleNameCache); + return getOrCreateCache(moduleNameToDirectoryMap!, redirectedReference, mode === undefined ? nonRelativeModuleName : `${mode}|${nonRelativeModuleName}`, createPerModuleNameCache); } function createPerModuleNameCache(): PerModuleNameCache { @@ -774,14 +838,14 @@ namespace ts { getCanonicalFileName: GetCanonicalFileName, options: undefined, packageJsonInfoCache: PackageJsonInfoCache | undefined, - directoryToModuleNameMap: CacheWithRedirects>, + directoryToModuleNameMap: CacheWithRedirects>, ): TypeReferenceDirectiveResolutionCache; export function createTypeReferenceDirectiveResolutionCache( currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache | undefined, - directoryToModuleNameMap?: CacheWithRedirects>, + directoryToModuleNameMap?: CacheWithRedirects>, ): TypeReferenceDirectiveResolutionCache { const preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap ||= createCacheWithRedirects(options)); packageJsonInfoCache ||= createPackageJsonInfoCache(currentDirectory, getCanonicalFileName); @@ -798,13 +862,14 @@ namespace ts { } } - export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined { + export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined { const containingDirectory = getDirectoryPath(containingFile); const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory); - return perFolderCache && perFolderCache.get(moduleName); + if (!perFolderCache) return undefined; + return perFolderCache.get(moduleName, mode); } - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations { + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); if (redirectedReference) { compilerOptions = redirectedReference.commandLine.options; @@ -817,7 +882,7 @@ namespace ts { } const containingDirectory = getDirectoryPath(containingFile); const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference); - let result = perFolderCache && perFolderCache.get(moduleName); + let result = perFolderCache && perFolderCache.get(moduleName, resolutionMode); if (result) { if (traceEnabled) { @@ -854,7 +919,11 @@ namespace ts { perfLogger.logStartResolveModule(moduleName /* , containingFile, ModuleResolutionKind[moduleResolution]*/); switch (moduleResolution) { case ModuleResolutionKind.Node12: - case ModuleResolutionKind.NodeNext: // TODO: Implement node12/nodenext resolution rules + result = node12ModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); + break; + case ModuleResolutionKind.NodeNext: + result = nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); + break; case ModuleResolutionKind.NodeJs: result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference); break; @@ -868,10 +937,10 @@ namespace ts { perfLogger.logStopResolveModule((result && result.resolvedModule) ? "" + result.resolvedModule.resolvedFileName : "null"); if (perFolderCache) { - perFolderCache.set(moduleName, result); + perFolderCache.set(moduleName, resolutionMode, result); if (!isExternalModuleNameRelative(moduleName)) { // put result in per-module name cache - cache!.getOrCreateCacheForModuleName(moduleName, redirectedReference).set(containingDirectory, result); + cache!.getOrCreateCacheForModuleName(moduleName, resolutionMode, redirectedReference).set(containingDirectory, result); } } } @@ -1103,25 +1172,77 @@ namespace ts { return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule; } + /* @internal */ + enum NodeResolutionFeatures { + None = 0, + // resolving `#local` names in your own package.json + Imports = 1 << 1, + // resolving `your-own-name` from your own package.json + SelfName = 1 << 2, + // respecting the `.exports` member of packages' package.json files and its (conditional) mappings of export names + Exports = 1 << 3, + // allowing `*` in the LHS of an export to be followed by more content, eg `"./whatever/*.js"` + // not currently backported to node 12 - https://github.com/nodejs/Release/issues/690 + ExportsPatternTrailers = 1 << 4, + AllFeatures = Imports | SelfName | Exports | ExportsPatternTrailers, + + EsmMode = 1 << 5, + } + + function node12ModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { + return nodeNextModuleNameResolverWorker( + NodeResolutionFeatures.Imports | NodeResolutionFeatures.SelfName | NodeResolutionFeatures.Exports, + moduleName, + containingFile, + compilerOptions, + host, + cache, + redirectedReference, + resolutionMode + ); + } + + function nodeNextModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { + return nodeNextModuleNameResolverWorker( + NodeResolutionFeatures.AllFeatures, + moduleName, + containingFile, + compilerOptions, + host, + cache, + redirectedReference, + resolutionMode + ); + } + + function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { + const containingDirectory = getDirectoryPath(containingFile); + + // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features + const esmMode = resolutionMode === ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + } + const jsOnlyExtensions = [Extensions.JavaScript]; const tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; const tsPlusJsonExtensions = [...tsExtensions, Extensions.Json]; const tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName: string, initialDir: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - return nodeModuleNameResolverWorker(moduleName, initialDir, { moduleResolution: ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); + return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; /* @internal */ export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, lookupConfig?: boolean): ResolvedModuleWithFailedLookupLocations; // eslint-disable-line @typescript-eslint/unified-signatures export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, lookupConfig?: boolean): ResolvedModuleWithFailedLookupLocations { - return nodeModuleNameResolverWorker(moduleName, getDirectoryPath(containingFile), compilerOptions, host, cache, lookupConfig ? tsconfigExtensions : (compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions), redirectedReference); + return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, getDirectoryPath(containingFile), compilerOptions, host, cache, lookupConfig ? tsconfigExtensions : (compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions), redirectedReference); } - function nodeModuleNameResolverWorker(moduleName: string, containingDirectory: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache: ModuleResolutionCache | undefined, extensions: Extensions[], redirectedReference: ResolvedProjectReference | undefined): ResolvedModuleWithFailedLookupLocations { + function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingDirectory: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache: ModuleResolutionCache | undefined, extensions: Extensions[], redirectedReference: ResolvedProjectReference | undefined): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); const failedLookupLocations: string[] = []; - const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache }; + // conditions are only used by the node12/nodenext resolver - there's no priority order in the list, it's essentially a set (priority is determined by object insertion order in the object we look at). + const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features, conditions: features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] }; const result = forEach(extensions, ext => tryResolve(ext)); return createResolvedModuleWithFailedLookupLocations(result?.value?.resolved, result?.value?.isExternalLibraryImport, failedLookupLocations, state.resultFromCache); @@ -1134,10 +1255,19 @@ namespace ts { } if (!isExternalModuleNameRelative(moduleName)) { - if (traceEnabled) { - trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]); + let resolved: SearchResult | undefined; + if (features & NodeResolutionFeatures.Imports && startsWith(moduleName, "#")) { + resolved = loadModuleFromImports(extensions, moduleName, containingDirectory, state, cache, redirectedReference); + } + if (!resolved && features & NodeResolutionFeatures.SelfName) { + resolved = loadModuleFromSelfNameReference(extensions, moduleName, containingDirectory, state, cache, redirectedReference); + } + if (!resolved) { + if (traceEnabled) { + trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]); + } + resolved = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference); } - const resolved = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference); if (!resolved) return undefined; let resolvedValue = resolved.value; @@ -1257,15 +1387,22 @@ namespace ts { return (extensionLess === undefined && extensions === Extensions.Json) ? undefined : tryAddingExtensions(extensionLess || candidate, extensions, extension, onlyRecordFailures, state); } - // First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts" - const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, "", onlyRecordFailures, state); - if (resolvedByAddingExtension) { - return resolvedByAddingExtension; + // esm mode resolutions don't include automatic extension lookup (without additional flags, at least) + if (!(state.features & NodeResolutionFeatures.EsmMode)) { + // First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts" + const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, "", onlyRecordFailures, state); + if (resolvedByAddingExtension) { + return resolvedByAddingExtension; + } } + return loadModuleFromFileNoImplicitExtensions(extensions, candidate, onlyRecordFailures, state); + } + + function loadModuleFromFileNoImplicitExtensions(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined { // If that didn't work, try stripping a ".js" or ".jsx" extension and replacing it with a TypeScript one; // e.g. "./foo.js" can be matched by "./foo.ts" or "./foo.d.ts" - if (hasJSFileExtension(candidate)) { + if (hasJSFileExtension(candidate) || (fileExtensionIs(candidate, Extension.Json) && state.compilerOptions.resolveJsonModule)) { const extensionless = removeFileExtension(candidate); const extension = candidate.substring(extensionless.length); if (state.traceEnabled) { @@ -1376,6 +1513,41 @@ namespace ts { versionPaths: VersionPaths | undefined; } + /** + * A function for locating the package.json scope for a given path + */ + /*@internal*/ + export function getPackageScopeForPath(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): PackageJsonInfo | undefined { + const state: { + host: ModuleResolutionHost; + compilerOptions: CompilerOptions; + traceEnabled: boolean; + failedLookupLocations: Push; + resultFromCache?: ResolvedModuleWithFailedLookupLocations; + packageJsonInfoCache: PackageJsonInfoCache | undefined; + features: number; + conditions: never[]; + } = { + host, + compilerOptions: options, + traceEnabled: isTraceEnabled(options, host), + failedLookupLocations: [], + packageJsonInfoCache, + features: 0, + conditions: [], + }; + const parts = getPathComponents(fileName); + parts.pop(); + while (parts.length > 0) { + const pkg = getPackageJsonInfo(getPathFromPathComponents(parts), /*onlyRecordFailures*/ false, state); + if (pkg) { + return pkg; + } + parts.pop(); + } + return undefined; + } + /*@internal*/ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PackageJsonInfo | undefined { const { host, traceEnabled } = state; @@ -1478,7 +1650,10 @@ namespace ts { const packageFileResult = packageFile && removeIgnoredPackageId(loader(extensions, packageFile, onlyRecordFailuresForPackageFile!, state)); if (packageFileResult) return packageFileResult; - return loadModuleFromFile(extensions, indexPath, onlyRecordFailuresForIndex, state); + // esm mode resolutions don't do package `index` lookups + if (!(state.features & NodeResolutionFeatures.EsmMode)) { + return loadModuleFromFile(extensions, indexPath, onlyRecordFailuresForIndex, state); + } } /** Resolve from an arbitrarily specified file. Return `undefined` if it has an unsupported extension. */ @@ -1511,7 +1686,223 @@ namespace ts { return idx === -1 ? { packageName: moduleName, rest: "" } : { packageName: moduleName.slice(0, idx), rest: moduleName.slice(idx + 1) }; } - function loadModuleFromNearestNodeModulesDirectory(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: NonRelativeModuleNameResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { + function allKeysStartWithDot(obj: MapLike) { + return every(getOwnKeys(obj), k => startsWith(k, ".")); + } + + function noKeyStartsWithDot(obj: MapLike) { + return !some(getOwnKeys(obj), k => startsWith(k, ".")); + } + + function loadModuleFromSelfNameReference(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { + const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; + const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions); + if (!scope || !scope.packageJsonContent.exports) { + return undefined; + } + const parts = getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry + if (scope.packageJsonContent.name !== parts[1]) { + return undefined; + } + const trailingParts = parts.slice(2); + return loadModuleFromExports(scope, extensions, !length(trailingParts) ? "." : `.${directorySeparator}${trailingParts.join(directorySeparator)}`, state, cache, redirectedReference); + } + + function loadModuleFromExports(scope: PackageJsonInfo, extensions: Extensions, subpath: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { + if (!scope.packageJsonContent.exports) { + return undefined; + } + + if (subpath === ".") { + let mainExport; + if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports as MapLike))) { + mainExport = scope.packageJsonContent.exports; + } + else if (hasProperty(scope.packageJsonContent.exports as MapLike, ".")) { + mainExport = (scope.packageJsonContent.exports as MapLike)["."]; + } + if (mainExport) { + const loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); + return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); + } + } + else if (allKeysStartWithDot(scope.packageJsonContent.exports as MapLike)) { + if (typeof scope.packageJsonContent.exports !== "object") { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); + } + return toSearchResult(/*value*/ undefined); + } + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + if (result) { + return result; + } + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); + } + return toSearchResult(/*value*/ undefined); + } + + function loadModuleFromImports(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { + if (moduleName === "#" || startsWith(moduleName, "#/")) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Invalid_import_specifier_0_has_no_possible_resolutions, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; + const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions); + if (!scope) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath); + } + return toSearchResult(/*value*/ undefined); + } + if (!scope.packageJsonContent.imports) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); + } + return toSearchResult(/*value*/ undefined); + } + + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + if (result) { + return result; + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Import_specifier_0_does_not_exist_in_package_json_scope_at_path_1, moduleName, scope.packageDirectory); + } + return toSearchResult(/*value*/ undefined); + } + + function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined, moduleName: string, lookupTable: object, scope: PackageJsonInfo, isImports: boolean): SearchResult | undefined { + const loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); + + if (!endsWith(moduleName, directorySeparator) && moduleName.indexOf("*") === -1 && hasProperty(lookupTable, moduleName)) { + const target = (lookupTable as {[idx: string]: unknown})[moduleName]; + return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); + } + const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike), k => k.indexOf("*") !== -1 || endsWith(k, "/")), (a, b) => a.length - b.length); + for (const potentialTarget of expandingKeys) { + if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { + const target = (lookupTable as {[idx: string]: unknown})[potentialTarget]; + const starPos = potentialTarget.indexOf("*"); + const subpath = moduleName.substring(potentialTarget.substring(0, starPos).length, moduleName.length - (potentialTarget.length - 1 - starPos)); + return loadModuleFromTargetImportOrExport(target, subpath, /*pattern*/ true); + } + else if (endsWith(potentialTarget, "*") && startsWith(moduleName, potentialTarget.substring(0, potentialTarget.length - 1))) { + const target = (lookupTable as {[idx: string]: unknown})[potentialTarget]; + const subpath = moduleName.substring(potentialTarget.length - 1); + return loadModuleFromTargetImportOrExport(target, subpath, /*pattern*/ true); + } + else if (startsWith(moduleName, potentialTarget)) { + const target = (lookupTable as {[idx: string]: unknown})[potentialTarget]; + const subpath = moduleName.substring(potentialTarget.length); + return loadModuleFromTargetImportOrExport(target, subpath, /*pattern*/ false); + } + } + + function matchesPatternWithTrailer(target: string, name: string) { + if (endsWith(target, "*")) return false; // handled by next case in loop + const starPos = target.indexOf("*"); + if (starPos === -1) return false; // handled by last case in loop + return startsWith(name, target.substring(0, starPos)) && endsWith(name, target.substring(starPos + 1)); + } + } + + /** + * Gets the self-recursive function specialized to retrieving the targeted import/export element for the given resolution configuration + */ + function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined, moduleName: string, scope: PackageJsonInfo, isImports: boolean) { + return loadModuleFromTargetImportOrExport; + function loadModuleFromTargetImportOrExport(target: unknown, subpath: string, pattern: boolean): SearchResult | undefined { + if (typeof target === "string") { + if (!pattern && subpath.length > 0 && !endsWith(target, "/")) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + if (!startsWith(target, "./")) { + if (isImports && !startsWith(target, "../") && !startsWith(target, "/") && !isRootedDiskPath(target)) { + const combinedLookup = pattern ? target.replace(/\*/g, subpath) : target + subpath; + const result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, [extensions], redirectedReference); + return toSearchResult(result.resolvedModule ? { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension, packageId: result.resolvedModule.packageId, originalPath: result.resolvedModule.originalPath } : undefined); + } + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + const parts = pathIsRelative(target) ? getPathComponents(target).slice(1) : getPathComponents(target); + const partsAfterFirst = parts.slice(1); + if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + const resolvedTarget = combinePaths(scope.packageDirectory, target); + // TODO: Assert that `resolvedTarget` is actually within the package directory? That's what the spec says.... but I'm not sure we need + // to be in the business of validating everyone's import and export map correctness. + const subpathParts = getPathComponents(subpath); + if (subpathParts.indexOf("..") >= 0 || subpathParts.indexOf(".") >= 0 || subpathParts.indexOf("node_modules") >= 0) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + const finalPath = getNormalizedAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath, state.host.getCurrentDirectory?.()); + + return toSearchResult(withPackageId(scope, loadModuleFromFileNoImplicitExtensions(extensions, finalPath, /*onlyRecordFailures*/ false, state))); + } + else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null + if (!Array.isArray(target)) { + for (const key of getOwnKeys(target as MapLike)) { + if (key === "default" || state.conditions.indexOf(key) >= 0) { + const subTarget = (target as MapLike)[key]; + const result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern); + if (result) { + return result; + } + } + } + return undefined; + } + else { + if (!length(target)) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + for (const elem of target) { + const result = loadModuleFromTargetImportOrExport(elem, subpath, pattern); + if (result) { + return result; + } + } + } + } + else if (target === null) { // eslint-disable-line no-null/no-null + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_explicitly_maps_specifier_1_to_null, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); + } + return toSearchResult(/*value*/ undefined); + } + } + + function loadModuleFromNearestNodeModulesDirectory(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { return loadModuleFromNearestNodeModulesDirectoryWorker(extensions, moduleName, directory, state, /*typesScopeOnly*/ false, cache, redirectedReference); } @@ -1520,27 +1911,27 @@ namespace ts { return loadModuleFromNearestNodeModulesDirectoryWorker(Extensions.DtsOnly, moduleName, directory, state, /*typesScopeOnly*/ true, /*cache*/ undefined, /*redirectedReference*/ undefined); } - function loadModuleFromNearestNodeModulesDirectoryWorker(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, typesScopeOnly: boolean, cache: NonRelativeModuleNameResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { - const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName, redirectedReference); + function loadModuleFromNearestNodeModulesDirectoryWorker(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, typesScopeOnly: boolean, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { + const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName, state.features === 0 ? undefined : state.features & NodeResolutionFeatures.EsmMode ? ModuleKind.ESNext : ModuleKind.CommonJS, redirectedReference); return forEachAncestorDirectory(normalizeSlashes(directory), ancestorDirectory => { if (getBaseFileName(ancestorDirectory) !== "node_modules") { const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, ancestorDirectory, state); if (resolutionFromCache) { return resolutionFromCache; } - return toSearchResult(loadModuleFromImmediateNodeModulesDirectory(extensions, moduleName, ancestorDirectory, state, typesScopeOnly)); + return toSearchResult(loadModuleFromImmediateNodeModulesDirectory(extensions, moduleName, ancestorDirectory, state, typesScopeOnly, cache, redirectedReference)); } }); } - function loadModuleFromImmediateNodeModulesDirectory(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, typesScopeOnly: boolean): Resolved | undefined { + function loadModuleFromImmediateNodeModulesDirectory(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, typesScopeOnly: boolean, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): Resolved | undefined { const nodeModulesFolder = combinePaths(directory, "node_modules"); const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host); if (!nodeModulesFolderExists && state.traceEnabled) { trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, nodeModulesFolder); } - const packageResult = typesScopeOnly ? undefined : loadModuleFromSpecificNodeModulesDirectory(extensions, moduleName, nodeModulesFolder, nodeModulesFolderExists, state); + const packageResult = typesScopeOnly ? undefined : loadModuleFromSpecificNodeModulesDirectory(extensions, moduleName, nodeModulesFolder, nodeModulesFolderExists, state, cache, redirectedReference); if (packageResult) { return packageResult; } @@ -1553,33 +1944,41 @@ namespace ts { } nodeModulesAtTypesExists = false; } - return loadModuleFromSpecificNodeModulesDirectory(Extensions.DtsOnly, mangleScopedPackageNameWithTrace(moduleName, state), nodeModulesAtTypes, nodeModulesAtTypesExists, state); + return loadModuleFromSpecificNodeModulesDirectory(Extensions.DtsOnly, mangleScopedPackageNameWithTrace(moduleName, state), nodeModulesAtTypes, nodeModulesAtTypesExists, state, cache, redirectedReference); } } - function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, moduleName: string, nodeModulesDirectory: string, nodeModulesDirectoryExists: boolean, state: ModuleResolutionState): Resolved | undefined { + function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, moduleName: string, nodeModulesDirectory: string, nodeModulesDirectoryExists: boolean, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): Resolved | undefined { const candidate = normalizePath(combinePaths(nodeModulesDirectory, moduleName)); // First look for a nested package.json, as in `node_modules/foo/bar/package.json`. let packageInfo = getPackageJsonInfo(candidate, !nodeModulesDirectoryExists, state); - if (packageInfo) { - const fromFile = loadModuleFromFile(extensions, candidate, !nodeModulesDirectoryExists, state); - if (fromFile) { - return noPackageId(fromFile); - } + // But only if we're not respecting export maps (if we are, we might redirect around this location) + if (!(state.features & NodeResolutionFeatures.Exports)) { + if (packageInfo) { + const fromFile = loadModuleFromFile(extensions, candidate, !nodeModulesDirectoryExists, state); + if (fromFile) { + return noPackageId(fromFile); + } - const fromDirectory = loadNodeModuleFromDirectoryWorker( - extensions, - candidate, - !nodeModulesDirectoryExists, - state, - packageInfo.packageJsonContent, - packageInfo.versionPaths - ); - return withPackageId(packageInfo, fromDirectory); + const fromDirectory = loadNodeModuleFromDirectoryWorker( + extensions, + candidate, + !nodeModulesDirectoryExists, + state, + packageInfo.packageJsonContent, + packageInfo.versionPaths + ); + return withPackageId(packageInfo, fromDirectory); + } } + const { packageName, rest } = parsePackageName(moduleName); const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => { + // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) + if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value; + } const pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker( @@ -1593,7 +1992,6 @@ namespace ts { return withPackageId(packageInfo, pathAndExtension); }; - const { packageName, rest } = parsePackageName(moduleName); if (rest !== "") { // If "rest" is empty, we just did this search above. const packageDirectory = combinePaths(nodeModulesDirectory, packageName); @@ -1702,7 +2100,7 @@ namespace ts { export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); const failedLookupLocations: string[] = []; - const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache }; + const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.None, conditions: [] }; const containingDirectory = getDirectoryPath(containingFile); const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript); @@ -1716,7 +2114,7 @@ namespace ts { } if (!isExternalModuleNameRelative(moduleName)) { - const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName, redirectedReference); + const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName, /*mode*/ undefined, redirectedReference); // Climb up parent directories looking for a module. const resolved = forEachAncestorDirectory(containingDirectory, directory => { const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, state); @@ -1752,8 +2150,8 @@ namespace ts { trace(host, Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, projectName, moduleName, globalCache); } const failedLookupLocations: string[] = []; - const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache }; - const resolved = loadModuleFromImmediateNodeModulesDirectory(Extensions.DtsOnly, moduleName, globalCache, state, /*typesScopeOnly*/ false); + const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache, features: NodeResolutionFeatures.None, conditions: [] }; + const resolved = loadModuleFromImmediateNodeModulesDirectory(Extensions.DtsOnly, moduleName, globalCache, state, /*typesScopeOnly*/ false, /*cache*/ undefined, /*redirectedReference*/ undefined); return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations, state.resultFromCache); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 17de23668d22d..1f476c6e19b40 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -529,6 +529,79 @@ namespace ts { return resolutions; } + /* @internal */ + /** + * Are you sure you want to use this? If you have a bound and parent pointer'd sourcefile, as in the checker, getModeForUsageLocation is much more ergonomic + */ + export function getModeForResolutionAtIndex(file: { statements: readonly Statement[], imports: readonly StringLiteralLike[], moduleAugmentations: readonly (StringLiteral | Identifier)[], impliedNodeFormat?: ModuleKind.CommonJS | ModuleKind.ESNext}, index: number) { + if (file.impliedNodeFormat === undefined) return undefined; + if (file.impliedNodeFormat !== ModuleKind.ESNext) { + const usage = getModuleNameStringLiteralAt(file, index); + if (usage.parent) { + // parent pointers are set - do the fast thing and just check if the parent is an import call expression + return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS; + } + // We can't rely on parent pointers being set - so instead we search for the usage in the top-level statements in the file, + // since that's the only place (module) import declarations and module augmentations (or definitions) are allowed. + // If the usage is anywhere else, by process of elimination, it must be an import call usage. + if (some(file.statements, s => + (isImportDeclaration(s) && s.moduleSpecifier === usage) || + (isImportEqualsDeclaration(s) && isExternalModuleReference(s.moduleReference) && skipParentheses(s.moduleReference.expression) === usage) || + (isModuleDeclaration(s) && s.name === usage) || + (isExportDeclaration(s) && s.moduleSpecifier === usage) + )) { + return ModuleKind.CommonJS; + } + return ModuleKind.ESNext; + } + // in an esnext format file, import require statements desugar to `require` calls, so should follow cjs resolution rules + const usage = getModuleNameStringLiteralAt(file, index); + if (usage.parent) { + // parent pointers are set - do the fast thing and just check if the parent is an import require statement + return isImportEqualsDeclaration(walkUpParenthesizedExpressions(usage.parent).parent) ? ModuleKind.CommonJS : ModuleKind.ESNext; + } + // parent pointers are unset - check to see if the usage is refered to in any of the top-level import require statements, as that's the only place they should be valid + if (some(file.statements, s => isImportEqualsDeclaration(s) && isExternalModuleReference(s.moduleReference) && skipParentheses(s.moduleReference.expression) === usage)) { + return ModuleKind.CommonJS; + } + return ModuleKind.ESNext; + } + + /* @internal */ + export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike) { + if (file.impliedNodeFormat === undefined) return undefined; + if (file.impliedNodeFormat !== ModuleKind.ESNext) { + // in cjs files, import call expressions are esm format, otherwise everything is cjs + return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS; + } + // in esm files, import=require statements are cjs format, otherwise everything is esm + return isImportEqualsDeclaration(walkUpParenthesizedExpressions(usage.parent).parent) ? ModuleKind.CommonJS : ModuleKind.ESNext; + } + + /* @internal */ + export function loadWithModeAwareCache(names: string[], containingFile: SourceFile, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined, loader: (name: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] { + if (names.length === 0) { + return []; + } + const resolutions: T[] = []; + const cache = new Map(); + let i = 0; + for (const name of names) { + let result: T; + const mode = getModeForResolutionAtIndex(containingFile, i); + i++; + const cacheKey = mode !== undefined ? `${mode}|${name}` : name; + if (cache.has(cacheKey)) { + result = cache.get(cacheKey)!; + } + else { + cache.set(cacheKey, result = loader(name, mode, containingFileName, redirectedReference)); + } + resolutions.push(result); + } + return resolutions; + } + /* @internal */ export function forEachResolvedProjectReference( resolvedProjectReferences: readonly (ResolvedProjectReference | undefined)[] | undefined, @@ -623,7 +696,7 @@ namespace ts { switch (kind) { case FileIncludeKind.Import: const importLiteral = getModuleNameStringLiteralAt(file, index); - packageId = file.resolvedModules?.get(importLiteral.text)?.packageId; + packageId = file.resolvedModules?.get(importLiteral.text, getModeForResolutionAtIndex(file, index))?.packageId; if (importLiteral.pos === -1) return { file, packageId, text: importLiteral.text }; pos = skipTrivia(file.text, importLiteral.pos); end = importLiteral.end; @@ -633,7 +706,7 @@ namespace ts { break; case FileIncludeKind.TypeReferenceDirective: ({ pos, end } = file.typeReferenceDirectives[index]); - packageId = file.resolvedTypeReferenceDirectiveNames?.get(toFileNameLowerCase(file.typeReferenceDirectives[index].fileName))?.packageId; + packageId = file.resolvedTypeReferenceDirectiveNames?.get(toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), getModeForResolutionAtIndex(file, index))?.packageId; break; case FileIncludeKind.LibReferenceDirective: ({ pos, end } = file.libReferenceDirectives[index]); @@ -760,30 +833,9 @@ namespace ts { return undefined; } function lookupFromPackageJson(): ModuleKind.ESNext | ModuleKind.CommonJS { - const state: { - host: ModuleResolutionHost; - compilerOptions: CompilerOptions; - traceEnabled: boolean; - failedLookupLocations: Push; - resultFromCache?: ResolvedModuleWithFailedLookupLocations; - packageJsonInfoCache: PackageJsonInfoCache | undefined; - } = { - host, - compilerOptions: options, - traceEnabled: isTraceEnabled(options, host), - failedLookupLocations: [], - packageJsonInfoCache - }; - const parts = getPathComponents(fileName); - parts.pop(); - while (parts.length > 0) { - const pkg = getPackageJsonInfo(getPathFromPathComponents(parts), /*onlyRecordFailures*/ false, state); - if (pkg) { - return pkg.packageJsonContent?.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; - } - parts.pop(); - } - return ModuleKind.CommonJS; + const scope = getPackageScopeForPath(fileName, packageJsonInfoCache, host, options); + return scope?.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; + } } @@ -891,10 +943,10 @@ namespace ts { let moduleResolutionCache: ModuleResolutionCache | undefined; let typeReferenceDirectiveResolutionCache: TypeReferenceDirectiveResolutionCache | undefined; - let actualResolveModuleNamesWorker: (moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference) => ResolvedModuleFull[]; + let actualResolveModuleNamesWorker: (moduleNames: string[], containingFile: SourceFile, containingFileName: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference) => ResolvedModuleFull[]; const hasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse; if (host.resolveModuleNames) { - actualResolveModuleNamesWorker = (moduleNames, containingFile, reusedNames, redirectedReference) => host.resolveModuleNames!(Debug.checkEachDefined(moduleNames), containingFile, reusedNames, redirectedReference, options).map(resolved => { + actualResolveModuleNamesWorker = (moduleNames, containingFile, containingFileName, reusedNames, redirectedReference) => host.resolveModuleNames!(Debug.checkEachDefined(moduleNames), containingFileName, reusedNames, redirectedReference, options, containingFile).map(resolved => { // An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName. if (!resolved || (resolved as ResolvedModuleFull).extension !== undefined) { return resolved as ResolvedModuleFull; @@ -907,8 +959,8 @@ namespace ts { } else { moduleResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options); - const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache, redirectedReference).resolvedModule!; // TODO: GH#18217 - actualResolveModuleNamesWorker = (moduleNames, containingFile, _reusedNames, redirectedReference) => loadWithLocalCache(Debug.checkEachDefined(moduleNames), containingFile, redirectedReference, loader); + const loader = (moduleName: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFileName, options, host, moduleResolutionCache, redirectedReference, resolverMode).resolvedModule!; // TODO: GH#18217 + actualResolveModuleNamesWorker = (moduleNames, containingFile, containingFileName, _reusedNames, redirectedReference) => loadWithModeAwareCache(Debug.checkEachDefined(moduleNames), containingFile, containingFileName, redirectedReference, loader); } let actualResolveTypeReferenceDirectiveNamesWorker: (typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference) => (ResolvedTypeReferenceDirective | undefined)[]; @@ -1187,7 +1239,7 @@ namespace ts { const redirectedReference = getRedirectReferenceForResolution(containingFile); tracing?.push(tracing.Phase.Program, "resolveModuleNamesWorker", { containingFileName }); performance.mark("beforeResolveModule"); - const result = actualResolveModuleNamesWorker(moduleNames, containingFileName, reusedNames, redirectedReference); + const result = actualResolveModuleNamesWorker(moduleNames, containingFile, containingFileName, reusedNames, redirectedReference); performance.mark("afterResolveModule"); performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule"); tracing?.pop(); @@ -1252,8 +1304,8 @@ namespace ts { return libs.length + 2; } - function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined { - return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache); + function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined { + return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache, mode); } function toPath(fileName: string): Path { @@ -1306,8 +1358,10 @@ namespace ts { // Since we assume the filesystem does not change during program creation, // it is safe to reuse resolutions from the earlier call. const result: ResolvedModuleFull[] = []; + let i = 0; for (const moduleName of moduleNames) { - const resolvedModule = file.resolvedModules.get(moduleName)!; + const resolvedModule = file.resolvedModules.get(moduleName, getModeForResolutionAtIndex(file, i))!; + i++; result.push(resolvedModule); } return result; @@ -1337,7 +1391,7 @@ namespace ts { const moduleName = moduleNames[i]; // If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions if (file === oldSourceFile && !hasInvalidatedResolution(oldSourceFile.path)) { - const oldResolvedModule = getResolvedModule(oldSourceFile, moduleName); + const oldResolvedModule = getResolvedModule(oldSourceFile, moduleName, getModeForResolutionAtIndex(oldSourceFile, i)); if (oldResolvedModule) { if (isTraceEnabled(options, host)) { trace(host, @@ -1367,7 +1421,7 @@ namespace ts { } } else { - resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName); + resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName, i); } if (resolvesToAmbientModuleInNonModifiedFile) { @@ -1410,8 +1464,8 @@ namespace ts { // If we change our policy of rechecking failed lookups on each program create, // we should adjust the value returned here. - function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string): boolean { - const resolutionToFile = getResolvedModule(oldSourceFile, moduleName); + function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string, index: number): boolean { + const resolutionToFile = getResolvedModule(oldSourceFile, moduleName, oldSourceFile && getModeForResolutionAtIndex(oldSourceFile, index)); const resolvedFile = resolutionToFile && oldProgram!.getSourceFile(resolutionToFile.resolvedFileName); if (resolutionToFile && resolvedFile) { // In the old program, we resolved to an ambient module that was in the same @@ -1626,10 +1680,10 @@ namespace ts { const moduleNames = getModuleNames(newSourceFile); const resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile); // ensure that module resolution results are still correct - const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, moduleResolutionIsEqualTo); + const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, oldSourceFile, moduleResolutionIsEqualTo); if (resolutionsChanged) { structureIsReused = StructureIsReused.SafeModules; - newSourceFile.resolvedModules = zipToMap(moduleNames, resolutions); + newSourceFile.resolvedModules = zipToModeAwareCache(newSourceFile, moduleNames, resolutions); } else { newSourceFile.resolvedModules = oldSourceFile.resolvedModules; @@ -1638,10 +1692,10 @@ namespace ts { const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, ref => toFileNameLowerCase(ref.fileName)); const typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile); // ensure that types resolutions are still correct - const typeReferenceEesolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, typeDirectiveIsEqualTo); + const typeReferenceEesolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, typeDirectiveIsEqualTo); if (typeReferenceEesolutionsChanged) { structureIsReused = StructureIsReused.SafeModules; - newSourceFile.resolvedTypeReferenceDirectiveNames = zipToMap(typesReferenceDirectives, typeReferenceResolutions); + newSourceFile.resolvedTypeReferenceDirectiveNames = zipToModeAwareCache(newSourceFile, typesReferenceDirectives, typeReferenceResolutions); } else { newSourceFile.resolvedTypeReferenceDirectiveNames = oldSourceFile.resolvedTypeReferenceDirectiveNames; @@ -2974,7 +3028,7 @@ namespace ts { const optionsForFile = (useSourceOfProjectReferenceRedirect ? getRedirectReferenceForResolution(file)?.commandLine.options : undefined) || options; for (let index = 0; index < moduleNames.length; index++) { const resolution = resolutions[index]; - setResolvedModule(file, moduleNames[index], resolution); + setResolvedModule(file, moduleNames[index], resolution, getModeForResolutionAtIndex(file, index)); if (!resolution) { continue; @@ -4065,7 +4119,7 @@ namespace ts { } /* @internal */ - export function getModuleNameStringLiteralAt({ imports, moduleAugmentations }: SourceFile, index: number): StringLiteralLike { + export function getModuleNameStringLiteralAt({ imports, moduleAugmentations }: {imports: readonly StringLiteralLike[], moduleAugmentations: readonly (StringLiteral | Identifier)[]}, index: number): StringLiteralLike { if (index < imports.length) return imports[index]; let augIndex = imports.length; for (const aug of moduleAugmentations) { diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index f15cc9766d507..8c09ec3ef721d 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -5,8 +5,8 @@ namespace ts { startRecordingFilesWithChangedResolutions(): void; finishRecordingFilesWithChangedResolutions(): Path[] | undefined; - resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference?: ResolvedProjectReference): (ResolvedModuleFull | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): CachedResolvedModuleWithFailedLookupLocations | undefined; + resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference?: ResolvedProjectReference, containingSourceFile?: SourceFile): (ResolvedModuleFull | undefined)[]; + getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): CachedResolvedModuleWithFailedLookupLocations | undefined; resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[]; invalidateResolutionsOfFailedLookupLocations(): boolean; @@ -166,8 +166,8 @@ namespace ts { // The resolvedModuleNames and resolvedTypeReferenceDirectives are the cache of resolutions per file. // The key in the map is source file's path. // The values are Map of resolutions with key being name lookedup. - const resolvedModuleNames = new Map>(); - const perDirectoryResolvedModuleNames: CacheWithRedirects> = createCacheWithRedirects(); + const resolvedModuleNames = new Map>(); + const perDirectoryResolvedModuleNames: CacheWithRedirects> = createCacheWithRedirects(); const nonRelativeModuleNameCache: CacheWithRedirects = createCacheWithRedirects(); const moduleResolutionCache = createModuleResolutionCache( getCurrentDirectory(), @@ -177,8 +177,8 @@ namespace ts { nonRelativeModuleNameCache, ); - const resolvedTypeReferenceDirectives = new Map>(); - const perDirectoryResolvedTypeReferenceDirectives: CacheWithRedirects> = createCacheWithRedirects(); + const resolvedTypeReferenceDirectives = new Map>(); + const perDirectoryResolvedTypeReferenceDirectives: CacheWithRedirects> = createCacheWithRedirects(); const typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache( getCurrentDirectory(), resolutionHost.getCanonicalFileName, @@ -354,27 +354,28 @@ namespace ts { names: readonly string[]; containingFile: string; redirectedReference: ResolvedProjectReference | undefined; - cache: ESMap>; - perDirectoryCacheWithRedirects: CacheWithRedirects>; - loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference) => T; + cache: ESMap>; + perDirectoryCacheWithRedirects: CacheWithRedirects>; + loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, containingSourceFile?: SourceFile) => T; getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName; shouldRetryResolution: (t: T) => boolean; reusedNames?: readonly string[]; logChanges?: boolean; + containingSourceFile?: SourceFile; } function resolveNamesWithLocalCache({ names, containingFile, redirectedReference, cache, perDirectoryCacheWithRedirects, loader, getResolutionWithResolvedFileName, - shouldRetryResolution, reusedNames, logChanges + shouldRetryResolution, reusedNames, logChanges, containingSourceFile }: ResolveNamesWithLocalCacheInput): (R | undefined)[] { const path = resolutionHost.toPath(containingFile); - const resolutionsInFile = cache.get(path) || cache.set(path, new Map()).get(path)!; + const resolutionsInFile = cache.get(path) || cache.set(path, createModeAwareCache()).get(path)!; const dirPath = getDirectoryPath(path); const perDirectoryCache = perDirectoryCacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference); let perDirectoryResolution = perDirectoryCache.get(dirPath); if (!perDirectoryResolution) { - perDirectoryResolution = new Map(); + perDirectoryResolution = createModeAwareCache(); perDirectoryCache.set(dirPath, perDirectoryResolution); } const resolvedModules: (R | undefined)[] = []; @@ -388,16 +389,19 @@ namespace ts { !redirectedReference || redirectedReference.sourceFile.path !== oldRedirect.sourceFile.path : !!redirectedReference; - const seenNamesInFile = new Map(); + const seenNamesInFile = createModeAwareCache(); + let i = 0; for (const name of names) { - let resolution = resolutionsInFile.get(name); + const mode = containingSourceFile ? getModeForResolutionAtIndex(containingSourceFile, i) : undefined; + i++; + let resolution = resolutionsInFile.get(name, mode); // Resolution is valid if it is present and not invalidated - if (!seenNamesInFile.has(name) && + if (!seenNamesInFile.has(name, mode) && unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate (hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution))) { const existingResolution = resolution; - const resolutionInDirectory = perDirectoryResolution.get(name); + const resolutionInDirectory = perDirectoryResolution.get(name, mode); if (resolutionInDirectory) { resolution = resolutionInDirectory; const host = resolutionHost.getCompilerHost?.() || resolutionHost; @@ -425,10 +429,10 @@ namespace ts { } } else { - resolution = loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference); - perDirectoryResolution.set(name, resolution); + resolution = loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference, containingSourceFile); + perDirectoryResolution.set(name, mode, resolution); } - resolutionsInFile.set(name, resolution); + resolutionsInFile.set(name, mode, resolution); watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName); if (existingResolution) { stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolutionWithResolvedFileName); @@ -442,7 +446,7 @@ namespace ts { } else { const host = resolutionHost.getCompilerHost?.() || resolutionHost; - if (isTraceEnabled(compilerOptions, host) && !seenNamesInFile.has(name)) { + if (isTraceEnabled(compilerOptions, host) && !seenNamesInFile.has(name, mode)) { const resolved = getResolutionWithResolvedFileName(resolution); trace( host, @@ -465,15 +469,15 @@ namespace ts { } } Debug.assert(resolution !== undefined && !resolution.isInvalidated); - seenNamesInFile.set(name, true); + seenNamesInFile.set(name, mode, true); resolvedModules.push(getResolutionWithResolvedFileName(resolution)); } // Stop watching and remove the unused name - resolutionsInFile.forEach((resolution, name) => { - if (!seenNamesInFile.has(name) && !contains(reusedNames, name)) { + resolutionsInFile.forEach((resolution, name, mode) => { + if (!seenNamesInFile.has(name, mode) && !contains(reusedNames, name)) { stopWatchFailedLookupLocationOfResolution(resolution, path, getResolutionWithResolvedFileName); - resolutionsInFile.delete(name); + resolutionsInFile.delete(name, mode); } }); @@ -511,7 +515,7 @@ namespace ts { }); } - function resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference?: ResolvedProjectReference): (ResolvedModuleFull | undefined)[] { + function resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference?: ResolvedProjectReference, containingSourceFile?: SourceFile): (ResolvedModuleFull | undefined)[] { return resolveNamesWithLocalCache({ names: moduleNames, containingFile, @@ -523,12 +527,14 @@ namespace ts { shouldRetryResolution: resolution => !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension), reusedNames, logChanges: logChangesWhenResolvingModule, + containingSourceFile, }); } - function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): CachedResolvedModuleWithFailedLookupLocations | undefined { + function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): CachedResolvedModuleWithFailedLookupLocations | undefined { const cache = resolvedModuleNames.get(resolutionHost.toPath(containingFile)); - return cache && cache.get(moduleName); + if (!cache) return undefined; + return cache.get(moduleName, resolutionMode); } function isNodeModulesAtTypesDirectory(dirPath: Path) { @@ -751,7 +757,7 @@ namespace ts { } function removeResolutionsOfFileFromCache( - cache: ESMap>, + cache: ESMap>, filePath: Path, getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName, ) { diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index e8c0b689c62f1..3f0e366be3afe 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -281,9 +281,9 @@ namespace ts { const moduleResolutionCache = !compilerHost.resolveModuleNames ? createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined; const typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache()) : undefined; if (!compilerHost.resolveModuleNames) { - const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, state.projectCompilerOptions, compilerHost, moduleResolutionCache, redirectedReference).resolvedModule!; - compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference) => - loadWithLocalCache(Debug.checkEachDefined(moduleNames), containingFile, redirectedReference, loader); + const loader = (moduleName: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, state.projectCompilerOptions, compilerHost, moduleResolutionCache, redirectedReference, resolverMode).resolvedModule!; + compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, _options, containingSourceFile) => + loadWithModeAwareCache(Debug.checkEachDefined(moduleNames), Debug.checkDefined(containingSourceFile), containingFile, redirectedReference, loader); compilerHost.getModuleResolutionCache = () => moduleResolutionCache; } if (!compilerHost.resolveTypeReferenceDirectives) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 06bc45a5a216c..64fb41d0f6ad4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3607,8 +3607,8 @@ namespace ts { // Stores a mapping 'external module reference text' -> 'resolved file name' | undefined // It is used to resolve module names in the checker. // Content of this field should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead - /* @internal */ resolvedModules?: ESMap; - /* @internal */ resolvedTypeReferenceDirectiveNames: ESMap; + /* @internal */ resolvedModules?: ModeAwareCache; + /* @internal */ resolvedTypeReferenceDirectiveNames: ModeAwareCache; /* @internal */ imports: readonly StringLiteralLike[]; // Identifier only if `declare global` /* @internal */ moduleAugmentations: readonly (StringLiteral | Identifier)[]; @@ -3990,7 +3990,7 @@ namespace ts { /* @internal */ getFileIncludeReasons(): MultiMap; /* @internal */ useCaseSensitiveFileNames(): boolean; - /* @internal */ getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; + /* @internal */ getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; getProjectReferences(): readonly ProjectReference[] | undefined; getResolvedProjectReferences(): readonly (ResolvedProjectReference | undefined)[] | undefined; @@ -6614,7 +6614,7 @@ namespace ts { * If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just * 'throw new Error("NotImplemented")' */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** * Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 627c0f8eb9b90..eacfece485065 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -169,24 +169,24 @@ namespace ts { return node.end - node.pos; } - export function getResolvedModule(sourceFile: SourceFile | undefined, moduleNameText: string): ResolvedModuleFull | undefined { - return sourceFile && sourceFile.resolvedModules && sourceFile.resolvedModules.get(moduleNameText); + export function getResolvedModule(sourceFile: SourceFile | undefined, moduleNameText: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): ResolvedModuleFull | undefined { + return sourceFile && sourceFile.resolvedModules && sourceFile.resolvedModules.get(moduleNameText, mode); } - export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModuleFull): void { + export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModuleFull, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): void { if (!sourceFile.resolvedModules) { - sourceFile.resolvedModules = new Map(); + sourceFile.resolvedModules = createModeAwareCache(); } - sourceFile.resolvedModules.set(moduleNameText, resolvedModule); + sourceFile.resolvedModules.set(moduleNameText, mode, resolvedModule); } export function setResolvedTypeReferenceDirective(sourceFile: SourceFile, typeReferenceDirectiveName: string, resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective): void { if (!sourceFile.resolvedTypeReferenceDirectiveNames) { - sourceFile.resolvedTypeReferenceDirectiveNames = new Map(); + sourceFile.resolvedTypeReferenceDirectiveNames = createModeAwareCache(); } - sourceFile.resolvedTypeReferenceDirectiveNames.set(typeReferenceDirectiveName, resolvedTypeReferenceDirective); + sourceFile.resolvedTypeReferenceDirectiveNames.set(typeReferenceDirectiveName, /*mode*/ undefined, resolvedTypeReferenceDirective); } export function projectReferenceIsEqualTo(oldRef: ProjectReference, newRef: ProjectReference) { @@ -221,13 +221,14 @@ namespace ts { export function hasChangesInResolutions( names: readonly string[], newResolutions: readonly T[], - oldResolutions: ReadonlyESMap | undefined, + oldResolutions: ModeAwareCache | undefined, + oldSourceFile: SourceFile | undefined, comparer: (oldResolution: T, newResolution: T) => boolean): boolean { Debug.assert(names.length === newResolutions.length); for (let i = 0; i < names.length; i++) { const newResolution = newResolutions[i]; - const oldResolution = oldResolutions && oldResolutions.get(names[i]); + const oldResolution = oldResolutions && oldResolutions.get(names[i], oldSourceFile && getModeForResolutionAtIndex(oldSourceFile, i)); const changed = oldResolution ? !newResolution || !comparer(oldResolution, newResolution) diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 1cc21a0bc9400..4b1eba91b7cdc 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -101,7 +101,7 @@ namespace ts { getEnvironmentVariable?(name: string): string | undefined; /** If provided, used to resolve the module names, otherwise typescript's default module resolution */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** If provided, used to resolve type reference directives, otherwise typescript's default resolution */ resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; } @@ -349,7 +349,7 @@ namespace ts { // Resolve module using host module resolution strategy if provided otherwise use resolution cache to resolve module names compilerHost.resolveModuleNames = host.resolveModuleNames ? ((...args) => host.resolveModuleNames!(...args)) : - ((moduleNames, containingFile, reusedNames, redirectedReference) => resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference)); + ((moduleNames, containingFile, reusedNames, redirectedReference, _options, sourceFile) => resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, sourceFile)); compilerHost.resolveTypeReferenceDirectives = host.resolveTypeReferenceDirectives ? ((...args) => host.resolveTypeReferenceDirectives!(...args)) : ((typeDirectiveNames, containingFile, redirectedReference) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference)); diff --git a/src/server/project.ts b/src/server/project.ts index 30560bc3e2b2a..197585ff86b91 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -472,12 +472,12 @@ namespace ts.server { return !this.isWatchedMissingFile(path) && this.directoryStructureHost.fileExists(file); } - resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModuleFull | undefined)[] { - return this.resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference); + resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModuleFull | undefined)[] { + return this.resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile); } - getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined { - return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile); + getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined { + return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode); } resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[] { diff --git a/src/services/codefixes/convertToEs6Module.ts b/src/services/codefixes/convertToEs6Module.ts index 1a5a92abb78f8..f01209290b234 100644 --- a/src/services/codefixes/convertToEs6Module.ts +++ b/src/services/codefixes/convertToEs6Module.ts @@ -19,7 +19,7 @@ namespace ts.codefix { function fixImportOfModuleExports(importingFile: SourceFile, exportingFile: SourceFile, changes: textChanges.ChangeTracker, quotePreference: QuotePreference) { for (const moduleSpecifier of importingFile.imports) { - const imported = getResolvedModule(importingFile, moduleSpecifier.text); + const imported = getResolvedModule(importingFile, moduleSpecifier.text, getModeForUsageLocation(importingFile, moduleSpecifier)); if (!imported || imported.resolvedFileName !== exportingFile.fileName) { continue; } diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index c7b1d66391048..1df43c19521ae 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -127,7 +127,7 @@ namespace ts.codefix { function getResolvedSourceFileFromImportDeclaration(sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined { if (!importDeclaration || !isStringLiteralLike(importDeclaration.moduleSpecifier)) return undefined; - const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text); + const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text, getModeForUsageLocation(sourceFile, importDeclaration.moduleSpecifier)); if (!resolvedModule) return undefined; return context.program.getSourceFile(resolvedModule.resolvedFileName); diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index ded586904aa4b..06fe9626e2f82 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -658,7 +658,7 @@ namespace ts.FindAllReferences { if (!options.implementations && isStringLiteralLike(node)) { if (isModuleSpecifierLike(node)) { const fileIncludeReasons = program.getFileIncludeReasons(); - const referencedFileName = node.getSourceFile().resolvedModules?.get(node.text)?.resolvedFileName; + const referencedFileName = node.getSourceFile().resolvedModules?.get(node.text, getModeForUsageLocation(node.getSourceFile(), node))?.resolvedFileName; const referencedFile = referencedFileName ? program.getSourceFile(referencedFileName) : undefined; if (referencedFile) { return [{ definition: { type: DefinitionKind.String, node }, references: getReferencesForNonModule(referencedFile, fileIncludeReasons, program) || emptyArray }]; diff --git a/src/services/getEditsForFileRename.ts b/src/services/getEditsForFileRename.ts index 907cc8f221ee6..a12283dddeea9 100644 --- a/src/services/getEditsForFileRename.ts +++ b/src/services/getEditsForFileRename.ts @@ -189,9 +189,10 @@ namespace ts { return newFileName === undefined ? { newFileName: oldFileName, updated: false } : { newFileName, updated: true }; } else { + const mode = getModeForResolutionAtIndex({ statements: importingSourceFile.statements, imports: [importLiteral], moduleAugmentations: [], impliedNodeFormat: importingSourceFile.impliedNodeFormat }, 0); const resolved = host.resolveModuleNames - ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName) - : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName); + ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode) + : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode); return getSourceFileToImportFromResolved(importLiteral, resolved, oldToNew, program.getSourceFiles()); } } diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 746e5a19a6927..af03eb260f507 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -170,10 +170,10 @@ namespace ts.GoToDefinition { return file && { reference: libReferenceDirective, fileName: file.fileName, file, unverified: false }; } - if (sourceFile.resolvedModules?.size) { + if (sourceFile.resolvedModules?.size()) { const node = getTokenAtPosition(sourceFile, position); - if (isModuleSpecifierLike(node) && isExternalModuleNameRelative(node.text) && sourceFile.resolvedModules.has(node.text)) { - const verifiedFileName = sourceFile.resolvedModules.get(node.text)?.resolvedFileName; + if (isModuleSpecifierLike(node) && isExternalModuleNameRelative(node.text) && sourceFile.resolvedModules.has(node.text, getModeForUsageLocation(sourceFile, node))) { + const verifiedFileName = sourceFile.resolvedModules.get(node.text, getModeForUsageLocation(sourceFile, node))?.resolvedFileName; const fileName = verifiedFileName || resolvePath(getDirectoryPath(sourceFile.fileName), node.text); return { file: program.getSourceFile(fileName), diff --git a/src/services/services.ts b/src/services/services.ts index 3f4096093a0f9..6161054f805ac 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -642,8 +642,8 @@ namespace ts { public languageVariant!: LanguageVariant; public identifiers!: ESMap; public nameTable: UnderscoreEscapedMap | undefined; - public resolvedModules: ESMap | undefined; - public resolvedTypeReferenceDirectiveNames!: ESMap; + public resolvedModules: ModeAwareCache | undefined; + public resolvedTypeReferenceDirectiveNames!: ModeAwareCache; public imports!: readonly StringLiteralLike[]; public moduleAugmentations!: StringLiteral[]; private namedDeclarations: ESMap | undefined; diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index 09740f8f2eef4..31517cf6660e5 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -23,7 +23,7 @@ namespace ts { const importNode = importFromModuleSpecifier(moduleSpecifier); const name = importNameForConvertToDefaultImport(importNode); if (!name) continue; - const module = getResolvedModule(sourceFile, moduleSpecifier.text); + const module = getResolvedModule(sourceFile, moduleSpecifier.text, getModeForUsageLocation(sourceFile, moduleSpecifier)); const resolvedFile = module && program.getSourceFile(module.resolvedFileName); if (resolvedFile && resolvedFile.externalModuleIndicator && isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) { diags.push(createDiagnosticForNode(name, Diagnostics.Import_may_be_converted_to_a_default_import)); diff --git a/src/services/types.ts b/src/services/types.ts index d664b6f0c94c7..816c83771b0a5 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -275,8 +275,8 @@ namespace ts { * * If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too. */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; + getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; /* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution; /* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames; diff --git a/src/testRunner/unittests/moduleResolution.ts b/src/testRunner/unittests/moduleResolution.ts index 390eb7857b521..87c3587ec2fed 100644 --- a/src/testRunner/unittests/moduleResolution.ts +++ b/src/testRunner/unittests/moduleResolution.ts @@ -206,7 +206,7 @@ namespace ts { describe("unittests:: moduleResolution:: Node module resolution - non-relative paths", () => { it("computes correct commonPrefix for moduleName cache", () => { const resolutionCache = createModuleResolutionCache("/", (f) => f); - let cache = resolutionCache.getOrCreateCacheForModuleName("a"); + let cache = resolutionCache.getOrCreateCacheForModuleName("a", /*mode*/ undefined); cache.set("/sub", { resolvedModule: { originalPath: undefined, @@ -219,7 +219,7 @@ namespace ts { assert.isDefined(cache.get("/sub")); assert.isUndefined(cache.get("/")); - cache = resolutionCache.getOrCreateCacheForModuleName("b"); + cache = resolutionCache.getOrCreateCacheForModuleName("b", /*mode*/ undefined); cache.set("/sub/dir/foo", { resolvedModule: { originalPath: undefined, @@ -234,7 +234,7 @@ namespace ts { assert.isDefined(cache.get("/sub")); assert.isUndefined(cache.get("/")); - cache = resolutionCache.getOrCreateCacheForModuleName("c"); + cache = resolutionCache.getOrCreateCacheForModuleName("c", /*mode*/ undefined); cache.set("/foo/bar", { resolvedModule: { originalPath: undefined, @@ -248,7 +248,7 @@ namespace ts { assert.isDefined(cache.get("/foo")); assert.isDefined(cache.get("/")); - cache = resolutionCache.getOrCreateCacheForModuleName("d"); + cache = resolutionCache.getOrCreateCacheForModuleName("d", /*mode*/ undefined); cache.set("/foo", { resolvedModule: { originalPath: undefined, @@ -261,7 +261,7 @@ namespace ts { assert.isDefined(cache.get("/foo")); assert.isUndefined(cache.get("/")); - cache = resolutionCache.getOrCreateCacheForModuleName("e"); + cache = resolutionCache.getOrCreateCacheForModuleName("e", /*mode*/ undefined); cache.set("c:/foo", { resolvedModule: { originalPath: undefined, @@ -275,7 +275,7 @@ namespace ts { assert.isDefined(cache.get("c:/")); assert.isUndefined(cache.get("d:/")); - cache = resolutionCache.getOrCreateCacheForModuleName("f"); + cache = resolutionCache.getOrCreateCacheForModuleName("f", /*mode*/ undefined); cache.set("/foo/bar/baz", { resolvedModule: undefined, failedLookupLocations: [], diff --git a/src/testRunner/unittests/reuseProgramStructure.ts b/src/testRunner/unittests/reuseProgramStructure.ts index 2face82e2d0aa..6dc13de241d47 100644 --- a/src/testRunner/unittests/reuseProgramStructure.ts +++ b/src/testRunner/unittests/reuseProgramStructure.ts @@ -175,7 +175,7 @@ namespace ts { return true; } - function checkCache(caption: string, program: Program, fileName: string, expectedContent: ESMap | undefined, getCache: (f: SourceFile) => ESMap | undefined, entryChecker: (expected: T, original: T) => boolean): void { + function checkCache(caption: string, program: Program, fileName: string, expectedContent: ESMap | undefined, getCache: (f: SourceFile) => ModeAwareCache | undefined, entryChecker: (expected: T, original: T) => boolean): void { const file = program.getSourceFile(fileName); assert.isTrue(file !== undefined, `cannot find file ${fileName}`); const cache = getCache(file!); @@ -184,21 +184,22 @@ namespace ts { } else { assert.isTrue(cache !== undefined, `expected ${caption} to be set`); - assert.isTrue(mapsAreEqual(expectedContent, cache!, entryChecker), `contents of ${caption} did not match the expected contents.`); + assert.isTrue(mapEqualToCache(expectedContent, cache!, entryChecker), `contents of ${caption} did not match the expected contents.`); } } /** True if the maps have the same keys and values. */ - function mapsAreEqual(left: ESMap, right: ESMap, valuesAreEqual?: (left: T, right: T) => boolean): boolean { - if (left === right) return true; + function mapEqualToCache(left: ESMap, right: ModeAwareCache, valuesAreEqual?: (left: T, right: T) => boolean): boolean { + if (left as any === right) return true; // given the type mismatch (the tests never pass a cache), this'll never be true if (!left || !right) return false; const someInLeftHasNoMatch = forEachEntry(left, (leftValue, leftKey) => { - if (!right.has(leftKey)) return true; - const rightValue = right.get(leftKey)!; + if (!right.has(leftKey, /*mode*/ undefined)) return true; + const rightValue = right.get(leftKey, /*mode*/ undefined)!; return !(valuesAreEqual ? valuesAreEqual(leftValue, rightValue) : leftValue === rightValue); }); if (someInLeftHasNoMatch) return false; - const someInRightHasNoMatch = forEachKey(right, rightKey => !left.has(rightKey)); + let someInRightHasNoMatch = false; + right.forEach((_, rightKey) => someInRightHasNoMatch = someInRightHasNoMatch || !left.has(rightKey)); return !someInRightHasNoMatch; } @@ -383,7 +384,7 @@ namespace ts { const program2 = updateProgram(program1, ["/a.ts"], options, files => { files[0].text = files[0].text.updateProgram('import * as aa from "a";'); }); - assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a"), "'a' is not an unresolved module after re-use"); + assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a", /*mode*/ undefined), "'a' is not an unresolved module after re-use"); }); it("works with updated SourceFiles", () => { @@ -406,7 +407,7 @@ namespace ts { } }; const program2 = createProgram(["/a.ts"], options, updateHost, program1); - assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a"), "'a' is not an unresolved module after re-use"); + assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a", /*mode*/ undefined), "'a' is not an unresolved module after re-use"); assert.strictEqual(sourceFile.statements[2].getSourceFile(), sourceFile, "parent pointers are not altered"); }); diff --git a/src/testRunner/unittests/tsserver/typingsInstaller.ts b/src/testRunner/unittests/tsserver/typingsInstaller.ts index 7995b66670ec8..470eb8717f276 100644 --- a/src/testRunner/unittests/tsserver/typingsInstaller.ts +++ b/src/testRunner/unittests/tsserver/typingsInstaller.ts @@ -1838,7 +1838,7 @@ namespace ts.projectSystem { const foooPath = "/a/b/node_modules/fooo/index.d.ts"; function verifyResolvedModuleOfFooo(project: server.Project) { server.updateProjectIfDirty(project); - const foooResolution = project.getLanguageService().getProgram()!.getSourceFileByPath(appPath)!.resolvedModules!.get("fooo")!; + const foooResolution = project.getLanguageService().getProgram()!.getSourceFileByPath(appPath)!.resolvedModules!.get("fooo", /*mode*/ undefined)!; assert.equal(foooResolution.resolvedFileName, foooPath); return foooResolution; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 317e58e1f923c..c0969c3a7949c 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3163,7 +3163,7 @@ declare namespace ts { useCaseSensitiveFileNames(): boolean; getNewLine(): string; readDirectory?(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number): string[]; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** * Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it */ @@ -4787,14 +4787,6 @@ declare namespace ts { export {}; } declare namespace ts { - interface ModuleResolutionState { - host: ModuleResolutionHost; - compilerOptions: CompilerOptions; - traceEnabled: boolean; - failedLookupLocations: Push; - resultFromCache?: ResolvedModuleWithFailedLookupLocations; - packageJsonInfoCache: PackageJsonInfoCache | undefined; - } export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined; /** * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. @@ -4813,12 +4805,20 @@ declare namespace ts { export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache, PackageJsonInfoCache { } + export interface ModeAwareCache { + get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined; + set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this; + delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this; + has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean; + forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void; + size(): number; + } /** * Cached resolutions per containing directory. * This assumes that any module id will have the same resolution for sibling files located in the same folder. */ export interface PerDirectoryResolutionCache { - getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map; + getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): ModeAwareCache; clear(): void; /** * Updates with the current compilerOptions the cache will operate with. @@ -4834,7 +4834,7 @@ declare namespace ts { * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive. */ export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache { - getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; + getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; } export interface PackageJsonInfoCache { clear(): void; @@ -4845,8 +4845,8 @@ declare namespace ts { } export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache; export function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache; - export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; + export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations; export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; export {}; @@ -5212,7 +5212,7 @@ declare namespace ts { /** If provided is used to get the environment variable */ getEnvironmentVariable?(name: string): string | undefined; /** If provided, used to resolve the module names, otherwise typescript's default module resolution */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** If provided, used to resolve type reference directives, otherwise typescript's default resolution */ resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; } @@ -5602,8 +5602,8 @@ declare namespace ts { realpath?(path: string): string; fileExists?(path: string): boolean; getTypeRootsVersion?(): number; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; + getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; getDirectories?(directoryName: string): string[]; /** @@ -9794,8 +9794,8 @@ declare namespace ts.server { readFile(fileName: string): string | undefined; writeFile(fileName: string, content: string): void; fileExists(file: string): boolean; - resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModuleFull | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; + resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModuleFull | undefined)[]; + getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[]; directoryExists(path: string): boolean; getDirectories(path: string): string[]; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 27dc0a8b38885..4341aaed4f122 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3163,7 +3163,7 @@ declare namespace ts { useCaseSensitiveFileNames(): boolean; getNewLine(): string; readDirectory?(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number): string[]; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** * Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it */ @@ -4787,14 +4787,6 @@ declare namespace ts { export {}; } declare namespace ts { - interface ModuleResolutionState { - host: ModuleResolutionHost; - compilerOptions: CompilerOptions; - traceEnabled: boolean; - failedLookupLocations: Push; - resultFromCache?: ResolvedModuleWithFailedLookupLocations; - packageJsonInfoCache: PackageJsonInfoCache | undefined; - } export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined; /** * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. @@ -4813,12 +4805,20 @@ declare namespace ts { export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache, PackageJsonInfoCache { } + export interface ModeAwareCache { + get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined; + set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this; + delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this; + has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean; + forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void; + size(): number; + } /** * Cached resolutions per containing directory. * This assumes that any module id will have the same resolution for sibling files located in the same folder. */ export interface PerDirectoryResolutionCache { - getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map; + getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): ModeAwareCache; clear(): void; /** * Updates with the current compilerOptions the cache will operate with. @@ -4834,7 +4834,7 @@ declare namespace ts { * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive. */ export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache { - getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; + getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; } export interface PackageJsonInfoCache { clear(): void; @@ -4845,8 +4845,8 @@ declare namespace ts { } export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache; export function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache; - export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; + export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations; export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; export {}; @@ -5212,7 +5212,7 @@ declare namespace ts { /** If provided is used to get the environment variable */ getEnvironmentVariable?(name: string): string | undefined; /** If provided, used to resolve the module names, otherwise typescript's default module resolution */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; /** If provided, used to resolve type reference directives, otherwise typescript's default resolution */ resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; } @@ -5602,8 +5602,8 @@ declare namespace ts { realpath?(path: string): string; fileExists?(path: string): boolean; getTypeRootsVersion?(): number; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; + resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[]; + getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined; resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; getDirectories?(directoryName: string): string[]; /** diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt new file mode 100644 index 0000000000000..06b0d70c3e18a --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/allowJs/index.cjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + self; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).js b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).js new file mode 100644 index 0000000000000..07532294ff7d3 --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts] //// + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +// esm format file +import * as self from "package"; +self; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const self = __importStar(require("package")); +self; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).symbols b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).symbols new file mode 100644 index 0000000000000..eb9fab3a89a50 --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.js, 1, 6)) + +self; +>self : Symbol(self, Decl(index.js, 1, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.mjs, 1, 6)) + +self; +>self : Symbol(self, Decl(index.mjs, 1, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.cjs, 1, 6)) + +self; +>self : Symbol(self, Decl(index.cjs, 1, 6)) + diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).types b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).types new file mode 100644 index 0000000000000..894b0d651035f --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt new file mode 100644 index 0000000000000..06b0d70c3e18a --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/allowJs/index.cjs (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + self; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).js b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).js new file mode 100644 index 0000000000000..07532294ff7d3 --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts] //// + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +// esm format file +import * as self from "package"; +self; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const self = __importStar(require("package")); +self; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).symbols b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).symbols new file mode 100644 index 0000000000000..eb9fab3a89a50 --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.js, 1, 6)) + +self; +>self : Symbol(self, Decl(index.js, 1, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.mjs, 1, 6)) + +self; +>self : Symbol(self, Decl(index.mjs, 1, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.cjs, 1, 6)) + +self; +>self : Symbol(self, Decl(index.cjs, 1, 6)) + diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).types b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).types new file mode 100644 index 0000000000000..894b0d651035f --- /dev/null +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + diff --git a/tests/baselines/reference/nodeModules1(module=node12).errors.txt b/tests/baselines/reference/nodeModules1(module=node12).errors.txt index 72fc62c6aed5f..683fdbd5b5f48 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModules1(module=node12).errors.txt @@ -4,6 +4,81 @@ tests/cases/conformance/node/index.cts(6,21): error TS1445: Module './subfolder/ tests/cases/conformance/node/index.cts(9,21): error TS1445: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(11,22): error TS1445: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(15,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(16,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(23,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(24,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(25,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(51,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(52,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(59,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(60,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(61,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(78,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(79,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(80,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(81,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(82,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(83,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(84,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(85,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. ==== tests/cases/conformance/node/subfolder/index.ts (0 errors) ==== @@ -42,7 +117,7 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.mts (0 errors) ==== +==== tests/cases/conformance/node/index.mts (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -55,6 +130,40 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should all fail - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -67,10 +176,91 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. + // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.cts (6 errors) ==== +==== tests/cases/conformance/node/index.cts (27 errors) ==== // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ @@ -96,6 +286,28 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) + import * as m13 from "./"; + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m15 from "./subfolder"; + import * as m16 from "./subfolder/"; + import * as m17 from "./subfolder/index"; + import * as m18 from "./subfolder2"; + import * as m19 from "./subfolder2/"; + import * as m20 from "./subfolder2/index"; + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -108,10 +320,90 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.ts (0 errors) ==== +==== tests/cases/conformance/node/index.ts (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -124,6 +416,40 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones shouldn't all work - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -136,6 +462,86 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // esm format file const x = 1; export {x}; diff --git a/tests/baselines/reference/nodeModules1(module=node12).js b/tests/baselines/reference/nodeModules1(module=node12).js index fba5f41f193e3..0f3e1bb74d782 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).js +++ b/tests/baselines/reference/nodeModules1(module=node12).js @@ -49,6 +49,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -61,6 +73,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; @@ -78,6 +139,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -90,6 +163,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -106,6 +227,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -118,6 +251,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; @@ -191,6 +372,8 @@ exports.x = void 0; const x = 1; exports.x = x; //// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -203,6 +386,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -215,10 +410,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; //// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -231,6 +474,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -243,6 +498,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; @@ -282,6 +583,18 @@ const m9 = __importStar(require("./subfolder2/index.cjs")); const m10 = __importStar(require("./subfolder2/another/index.js")); const m11 = __importStar(require("./subfolder2/another/index.mjs")); const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -294,6 +607,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; exports.x = x; diff --git a/tests/baselines/reference/nodeModules1(module=node12).symbols b/tests/baselines/reference/nodeModules1(module=node12).symbols index b8caa52c8cfa0..287b1e895d1a1 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).symbols +++ b/tests/baselines/reference/nodeModules1(module=node12).symbols @@ -107,6 +107,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.mts, 11, 6)) +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.mts, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.mts, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.mts, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.mts, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.mts, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.mts, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.mts, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.mts, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.mts, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.mts, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.mts, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.mts, 0, 6)) @@ -143,12 +177,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.mts, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.mts, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.mts, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.mts, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.mts, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.mts, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.mts, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.mts, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.mts, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.mts, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.mts, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.mts, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.mts, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.mts, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.mts, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.mts, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.mts, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.mts, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.mts, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.mts, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.mts, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.mts, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.mts, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.mts, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.mts, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.mts, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.mts, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.mts, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.mts, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.mts, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.mts, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.mts, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.mts, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.mts, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.mts, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.mts, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.mts, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.mts, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.mts, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.mts, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.mts, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.mts, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.mts, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.mts, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.mts, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.mts, 25, 5)) +>x : Symbol(x, Decl(index.mts, 86, 5)) export {x}; ->x : Symbol(m2.x, Decl(index.mts, 26, 8)) +>x : Symbol(m2.x, Decl(index.mts, 87, 8)) === tests/cases/conformance/node/index.cts === // ESM-format imports below should issue errors @@ -188,6 +356,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.cts, 12, 6)) +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.cts, 14, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.cts, 15, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.cts, 16, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.cts, 17, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.cts, 18, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.cts, 19, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.cts, 20, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.cts, 21, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.cts, 22, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.cts, 23, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.cts, 24, 6)) + void m1; >m1 : Symbol(m1, Decl(index.cts, 1, 6)) @@ -224,12 +426,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.cts, 12, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.cts, 14, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.cts, 15, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.cts, 16, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.cts, 17, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.cts, 18, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.cts, 19, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.cts, 20, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.cts, 21, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.cts, 22, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.cts, 23, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.cts, 24, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.cts, 47, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.cts, 50, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.cts, 51, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.cts, 52, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.cts, 53, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.cts, 54, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.cts, 55, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.cts, 56, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.cts, 57, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.cts, 58, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.cts, 59, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.cts, 47, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.cts, 50, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.cts, 51, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.cts, 52, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.cts, 53, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.cts, 54, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.cts, 55, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.cts, 56, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.cts, 57, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.cts, 58, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.cts, 59, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.cts, 74, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.cts, 75, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.cts, 76, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.cts, 77, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.cts, 78, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.cts, 79, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.cts, 80, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.cts, 81, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.cts, 82, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.cts, 83, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.cts, 84, 5)) + // cjs format file const x = 1; ->x : Symbol(x, Decl(index.cts, 26, 5)) +>x : Symbol(x, Decl(index.cts, 86, 5)) export {x}; ->x : Symbol(m3.x, Decl(index.cts, 27, 8)) +>x : Symbol(m3.x, Decl(index.cts, 87, 8)) === tests/cases/conformance/node/index.ts === import * as m1 from "./index.js"; @@ -268,6 +604,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.ts, 11, 6)) +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.ts, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.ts, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.ts, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.ts, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.ts, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.ts, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.ts, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.ts, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.ts, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.ts, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.ts, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.ts, 0, 6)) @@ -304,10 +674,144 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.ts, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.ts, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.ts, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.ts, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.ts, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.ts, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.ts, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.ts, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.ts, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.ts, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.ts, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.ts, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.ts, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.ts, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.ts, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.ts, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.ts, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.ts, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.ts, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.ts, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.ts, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.ts, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.ts, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.ts, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.ts, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.ts, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.ts, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.ts, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.ts, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.ts, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.ts, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.ts, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.ts, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.ts, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.ts, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.ts, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.ts, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.ts, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.ts, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.ts, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.ts, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.ts, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.ts, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.ts, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.ts, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.ts, 25, 5)) +>x : Symbol(x, Decl(index.ts, 85, 5)) export {x}; ->x : Symbol(m1.x, Decl(index.ts, 26, 8)) +>x : Symbol(m1.x, Decl(index.ts, 86, 8)) diff --git a/tests/baselines/reference/nodeModules1(module=node12).types b/tests/baselines/reference/nodeModules1(module=node12).types index cf878a592d2e9..3a7a0c0b9b6a3 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).types +++ b/tests/baselines/reference/nodeModules1(module=node12).types @@ -116,6 +116,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -164,6 +198,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 @@ -210,6 +422,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : typeof m1 + +import * as m14 from "./index"; +>m14 : typeof m1 + +import * as m15 from "./subfolder"; +>m15 : typeof m4 + +import * as m16 from "./subfolder/"; +>m16 : typeof m4 + +import * as m17 from "./subfolder/index"; +>m17 : typeof m4 + +import * as m18 from "./subfolder2"; +>m18 : typeof m7 + +import * as m19 from "./subfolder2/"; +>m19 : typeof m7 + +import * as m20 from "./subfolder2/index"; +>m20 : typeof m7 + +import * as m21 from "./subfolder2/another"; +>m21 : typeof m10 + +import * as m22 from "./subfolder2/another/"; +>m22 : typeof m10 + +import * as m23 from "./subfolder2/another/index"; +>m23 : typeof m10 + void m1; >void m1 : undefined >m1 : typeof m1 @@ -258,6 +504,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : typeof m1 + +void m14; +>void m14 : undefined +>m14 : typeof m1 + +void m15; +>void m15 : undefined +>m15 : typeof m4 + +void m16; +>void m16 : undefined +>m16 : typeof m4 + +void m17; +>void m17 : undefined +>m17 : typeof m4 + +void m18; +>void m18 : undefined +>m18 : typeof m7 + +void m19; +>void m19 : undefined +>m19 : typeof m7 + +void m20; +>void m20 : undefined +>m20 : typeof m7 + +void m21; +>void m21 : undefined +>m21 : typeof m10 + +void m22; +>void m22 : undefined +>m22 : typeof m10 + +void m23; +>void m23 : undefined +>m23 : typeof m10 + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // cjs format file const x = 1; >x : 1 @@ -303,6 +727,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -351,6 +809,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt index 72fc62c6aed5f..683fdbd5b5f48 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt @@ -4,6 +4,81 @@ tests/cases/conformance/node/index.cts(6,21): error TS1445: Module './subfolder/ tests/cases/conformance/node/index.cts(9,21): error TS1445: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(11,22): error TS1445: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(15,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(16,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(23,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(24,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(25,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(51,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(52,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(59,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(60,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(61,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(78,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(79,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(80,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(81,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(82,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(83,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(84,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(85,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. ==== tests/cases/conformance/node/subfolder/index.ts (0 errors) ==== @@ -42,7 +117,7 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.mts (0 errors) ==== +==== tests/cases/conformance/node/index.mts (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -55,6 +130,40 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should all fail - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -67,10 +176,91 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. + // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.cts (6 errors) ==== +==== tests/cases/conformance/node/index.cts (27 errors) ==== // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ @@ -96,6 +286,28 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) + import * as m13 from "./"; + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m15 from "./subfolder"; + import * as m16 from "./subfolder/"; + import * as m17 from "./subfolder/index"; + import * as m18 from "./subfolder2"; + import * as m19 from "./subfolder2/"; + import * as m20 from "./subfolder2/index"; + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -108,10 +320,90 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/index.ts (0 errors) ==== +==== tests/cases/conformance/node/index.ts (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -124,6 +416,40 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones shouldn't all work - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -136,6 +462,86 @@ tests/cases/conformance/node/index.cts(12,22): error TS1445: Module './subfolder void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // esm format file const x = 1; export {x}; diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).js b/tests/baselines/reference/nodeModules1(module=nodenext).js index fba5f41f193e3..0f3e1bb74d782 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).js +++ b/tests/baselines/reference/nodeModules1(module=nodenext).js @@ -49,6 +49,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -61,6 +73,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; @@ -78,6 +139,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -90,6 +163,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -106,6 +227,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -118,6 +251,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; @@ -191,6 +372,8 @@ exports.x = void 0; const x = 1; exports.x = x; //// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -203,6 +386,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -215,10 +410,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; //// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -231,6 +474,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -243,6 +498,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; @@ -282,6 +583,18 @@ const m9 = __importStar(require("./subfolder2/index.cjs")); const m10 = __importStar(require("./subfolder2/another/index.js")); const m11 = __importStar(require("./subfolder2/another/index.mjs")); const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -294,6 +607,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; exports.x = x; diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).symbols b/tests/baselines/reference/nodeModules1(module=nodenext).symbols index b8caa52c8cfa0..287b1e895d1a1 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).symbols +++ b/tests/baselines/reference/nodeModules1(module=nodenext).symbols @@ -107,6 +107,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.mts, 11, 6)) +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.mts, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.mts, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.mts, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.mts, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.mts, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.mts, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.mts, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.mts, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.mts, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.mts, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.mts, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.mts, 0, 6)) @@ -143,12 +177,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.mts, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.mts, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.mts, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.mts, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.mts, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.mts, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.mts, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.mts, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.mts, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.mts, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.mts, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.mts, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.mts, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.mts, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.mts, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.mts, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.mts, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.mts, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.mts, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.mts, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.mts, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.mts, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.mts, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.mts, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.mts, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.mts, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.mts, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.mts, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.mts, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.mts, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.mts, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.mts, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.mts, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.mts, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.mts, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.mts, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.mts, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.mts, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.mts, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.mts, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.mts, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.mts, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.mts, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.mts, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.mts, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.mts, 25, 5)) +>x : Symbol(x, Decl(index.mts, 86, 5)) export {x}; ->x : Symbol(m2.x, Decl(index.mts, 26, 8)) +>x : Symbol(m2.x, Decl(index.mts, 87, 8)) === tests/cases/conformance/node/index.cts === // ESM-format imports below should issue errors @@ -188,6 +356,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.cts, 12, 6)) +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.cts, 14, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.cts, 15, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.cts, 16, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.cts, 17, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.cts, 18, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.cts, 19, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.cts, 20, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.cts, 21, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.cts, 22, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.cts, 23, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.cts, 24, 6)) + void m1; >m1 : Symbol(m1, Decl(index.cts, 1, 6)) @@ -224,12 +426,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.cts, 12, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.cts, 14, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.cts, 15, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.cts, 16, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.cts, 17, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.cts, 18, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.cts, 19, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.cts, 20, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.cts, 21, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.cts, 22, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.cts, 23, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.cts, 24, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.cts, 47, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.cts, 50, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.cts, 51, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.cts, 52, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.cts, 53, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.cts, 54, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.cts, 55, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.cts, 56, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.cts, 57, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.cts, 58, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.cts, 59, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.cts, 47, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.cts, 50, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.cts, 51, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.cts, 52, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.cts, 53, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.cts, 54, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.cts, 55, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.cts, 56, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.cts, 57, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.cts, 58, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.cts, 59, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.cts, 74, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.cts, 75, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.cts, 76, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.cts, 77, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.cts, 78, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.cts, 79, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.cts, 80, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.cts, 81, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.cts, 82, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.cts, 83, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.cts, 84, 5)) + // cjs format file const x = 1; ->x : Symbol(x, Decl(index.cts, 26, 5)) +>x : Symbol(x, Decl(index.cts, 86, 5)) export {x}; ->x : Symbol(m3.x, Decl(index.cts, 27, 8)) +>x : Symbol(m3.x, Decl(index.cts, 87, 8)) === tests/cases/conformance/node/index.ts === import * as m1 from "./index.js"; @@ -268,6 +604,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.ts, 11, 6)) +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.ts, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.ts, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.ts, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.ts, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.ts, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.ts, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.ts, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.ts, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.ts, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.ts, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.ts, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.ts, 0, 6)) @@ -304,10 +674,144 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.ts, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.ts, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.ts, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.ts, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.ts, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.ts, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.ts, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.ts, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.ts, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.ts, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.ts, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.ts, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.ts, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.ts, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.ts, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.ts, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.ts, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.ts, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.ts, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.ts, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.ts, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.ts, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.ts, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.ts, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.ts, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.ts, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.ts, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.ts, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.ts, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.ts, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.ts, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.ts, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.ts, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.ts, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.ts, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.ts, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.ts, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.ts, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.ts, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.ts, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.ts, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.ts, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.ts, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.ts, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.ts, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.ts, 25, 5)) +>x : Symbol(x, Decl(index.ts, 85, 5)) export {x}; ->x : Symbol(m1.x, Decl(index.ts, 26, 8)) +>x : Symbol(m1.x, Decl(index.ts, 86, 8)) diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).types b/tests/baselines/reference/nodeModules1(module=nodenext).types index cf878a592d2e9..3a7a0c0b9b6a3 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).types +++ b/tests/baselines/reference/nodeModules1(module=nodenext).types @@ -116,6 +116,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -164,6 +198,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 @@ -210,6 +422,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : typeof m1 + +import * as m14 from "./index"; +>m14 : typeof m1 + +import * as m15 from "./subfolder"; +>m15 : typeof m4 + +import * as m16 from "./subfolder/"; +>m16 : typeof m4 + +import * as m17 from "./subfolder/index"; +>m17 : typeof m4 + +import * as m18 from "./subfolder2"; +>m18 : typeof m7 + +import * as m19 from "./subfolder2/"; +>m19 : typeof m7 + +import * as m20 from "./subfolder2/index"; +>m20 : typeof m7 + +import * as m21 from "./subfolder2/another"; +>m21 : typeof m10 + +import * as m22 from "./subfolder2/another/"; +>m22 : typeof m10 + +import * as m23 from "./subfolder2/another/index"; +>m23 : typeof m10 + void m1; >void m1 : undefined >m1 : typeof m1 @@ -258,6 +504,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : typeof m1 + +void m14; +>void m14 : undefined +>m14 : typeof m1 + +void m15; +>void m15 : undefined +>m15 : typeof m4 + +void m16; +>void m16 : undefined +>m16 : typeof m4 + +void m17; +>void m17 : undefined +>m17 : typeof m4 + +void m18; +>void m18 : undefined +>m18 : typeof m7 + +void m19; +>void m19 : undefined +>m19 : typeof m7 + +void m20; +>void m20 : undefined +>m20 : typeof m7 + +void m21; +>void m21 : undefined +>m21 : typeof m10 + +void m22; +>void m22 : undefined +>m22 : typeof m10 + +void m23; +>void m23 : undefined +>m23 : typeof m10 + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // cjs format file const x = 1; >x : 1 @@ -303,6 +727,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -351,6 +809,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt index 41443989a961d..63b623a8d25cf 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt @@ -4,6 +4,92 @@ tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1445: Module './su tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1445: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1445: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(78,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(79,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(80,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(81,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(82,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(83,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(84,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(85,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(50,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(51,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(52,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(53,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(54,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(55,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(56,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(57,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(58,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(59,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(60,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. ==== tests/cases/conformance/node/allowJs/subfolder/index.js (0 errors) ==== @@ -42,7 +128,7 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== +==== tests/cases/conformance/node/allowJs/index.js (38 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -55,6 +141,40 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones shouldn't all work - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -67,11 +187,113 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m27 = require("./subfolder/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m28 = require("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m29 = require("./subfolder2"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m30 = require("./subfolder2/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m31 = require("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.cjs (6 errors) ==== - // ESM format imports below should error +==== tests/cases/conformance/node/allowJs/index.cjs (27 errors) ==== + // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ !!! error TS1445: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. @@ -96,6 +318,28 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) + import * as m13 from "./"; + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m15 from "./subfolder"; + import * as m16 from "./subfolder/"; + import * as m17 from "./subfolder/index"; + import * as m18 from "./subfolder2"; + import * as m19 from "./subfolder2/"; + import * as m20 from "./subfolder2/index"; + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -108,10 +352,90 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== +==== tests/cases/conformance/node/allowJs/index.mjs (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -124,6 +448,40 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should all fail - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -136,6 +494,87 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. + // esm format file const x = 1; export {x}; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).js b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).js index 0ec674cdd18b3..ec1664707e795 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).js +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).js @@ -49,6 +49,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -61,11 +73,59 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; //// [index.cjs] -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -78,6 +138,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -90,6 +162,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -106,6 +226,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -118,6 +250,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; @@ -213,7 +394,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.x = void 0; -// ESM format imports below should error +// ESM-format imports below should issue errors const m1 = __importStar(require("./index.js")); const m2 = __importStar(require("./index.mjs")); const m3 = __importStar(require("./index.cjs")); @@ -226,6 +407,18 @@ const m9 = __importStar(require("./subfolder2/index.cjs")); const m10 = __importStar(require("./subfolder2/another/index.js")); const m11 = __importStar(require("./subfolder2/another/index.mjs")); const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -238,10 +431,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; exports.x = x; //// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -254,6 +495,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -266,10 +519,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; //// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -282,6 +583,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -294,6 +607,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).symbols index 90c86e3a1be64..d874ab0c830dd 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).symbols +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).symbols @@ -107,6 +107,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.js, 11, 6)) +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.js, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.js, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.js, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.js, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.js, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.js, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.js, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.js, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.js, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.js, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.js, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.js, 0, 6)) @@ -143,15 +177,149 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.js, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.js, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.js, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.js, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.js, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.js, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.js, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.js, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.js, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.js, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.js, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.js, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.js, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.js, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.js, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.js, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.js, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.js, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.js, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.js, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.js, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.js, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.js, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.js, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.js, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.js, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.js, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.js, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.js, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.js, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.js, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.js, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.js, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.js, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.js, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.js, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.js, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.js, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.js, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.js, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.js, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.js, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.js, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.js, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.js, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.js, 25, 5)) +>x : Symbol(x, Decl(index.js, 85, 5)) export {x}; ->x : Symbol(m1.x, Decl(index.js, 26, 8)) +>x : Symbol(m1.x, Decl(index.js, 86, 8)) === tests/cases/conformance/node/allowJs/index.cjs === -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; >m1 : Symbol(m1, Decl(index.cjs, 1, 6)) @@ -188,6 +356,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.cjs, 12, 6)) +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.cjs, 14, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.cjs, 15, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.cjs, 16, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.cjs, 17, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.cjs, 18, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.cjs, 19, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.cjs, 20, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.cjs, 21, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.cjs, 22, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.cjs, 23, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.cjs, 24, 6)) + void m1; >m1 : Symbol(m1, Decl(index.cjs, 1, 6)) @@ -224,12 +426,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.cjs, 12, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.cjs, 14, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.cjs, 15, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.cjs, 16, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.cjs, 17, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.cjs, 18, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.cjs, 19, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.cjs, 20, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.cjs, 21, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.cjs, 22, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.cjs, 23, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.cjs, 24, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.cjs, 47, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.cjs, 50, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.cjs, 51, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.cjs, 52, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.cjs, 53, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.cjs, 54, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.cjs, 55, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.cjs, 56, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.cjs, 57, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.cjs, 58, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.cjs, 59, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.cjs, 47, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.cjs, 50, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.cjs, 51, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.cjs, 52, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.cjs, 53, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.cjs, 54, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.cjs, 55, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.cjs, 56, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.cjs, 57, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.cjs, 58, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.cjs, 59, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.cjs, 74, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.cjs, 75, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.cjs, 76, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.cjs, 77, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.cjs, 78, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.cjs, 79, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.cjs, 80, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.cjs, 81, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.cjs, 82, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.cjs, 83, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.cjs, 84, 5)) + // cjs format file const x = 1; ->x : Symbol(x, Decl(index.cjs, 26, 5)) +>x : Symbol(x, Decl(index.cjs, 86, 5)) export {x}; ->x : Symbol(m3.x, Decl(index.cjs, 27, 8)) +>x : Symbol(m3.x, Decl(index.cjs, 87, 8)) === tests/cases/conformance/node/allowJs/index.mjs === import * as m1 from "./index.js"; @@ -268,6 +604,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.mjs, 11, 6)) +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.mjs, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.mjs, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.mjs, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.mjs, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.mjs, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.mjs, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.mjs, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.mjs, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.mjs, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.mjs, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.mjs, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.mjs, 0, 6)) @@ -304,10 +674,144 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.mjs, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.mjs, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.mjs, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.mjs, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.mjs, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.mjs, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.mjs, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.mjs, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.mjs, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.mjs, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.mjs, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.mjs, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.mjs, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.mjs, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.mjs, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.mjs, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.mjs, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.mjs, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.mjs, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.mjs, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.mjs, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.mjs, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.mjs, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.mjs, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.mjs, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.mjs, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.mjs, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.mjs, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.mjs, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.mjs, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.mjs, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.mjs, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.mjs, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.mjs, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.mjs, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.mjs, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.mjs, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.mjs, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.mjs, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.mjs, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.mjs, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.mjs, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.mjs, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.mjs, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.mjs, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.mjs, 25, 5)) +>x : Symbol(x, Decl(index.mjs, 86, 5)) export {x}; ->x : Symbol(m2.x, Decl(index.mjs, 26, 8)) +>x : Symbol(m2.x, Decl(index.mjs, 87, 8)) diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).types b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).types index d0acce4132567..148c55c036dde 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).types +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).types @@ -116,6 +116,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -164,6 +198,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 @@ -173,7 +385,7 @@ export {x}; >x : 1 === tests/cases/conformance/node/allowJs/index.cjs === -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; >m1 : typeof m1 @@ -210,6 +422,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : typeof m1 + +import * as m14 from "./index"; +>m14 : typeof m1 + +import * as m15 from "./subfolder"; +>m15 : typeof m4 + +import * as m16 from "./subfolder/"; +>m16 : typeof m4 + +import * as m17 from "./subfolder/index"; +>m17 : typeof m4 + +import * as m18 from "./subfolder2"; +>m18 : typeof m7 + +import * as m19 from "./subfolder2/"; +>m19 : typeof m7 + +import * as m20 from "./subfolder2/index"; +>m20 : typeof m7 + +import * as m21 from "./subfolder2/another"; +>m21 : typeof m10 + +import * as m22 from "./subfolder2/another/"; +>m22 : typeof m10 + +import * as m23 from "./subfolder2/another/index"; +>m23 : typeof m10 + void m1; >void m1 : undefined >m1 : typeof m1 @@ -258,6 +504,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : typeof m1 + +void m14; +>void m14 : undefined +>m14 : typeof m1 + +void m15; +>void m15 : undefined +>m15 : typeof m4 + +void m16; +>void m16 : undefined +>m16 : typeof m4 + +void m17; +>void m17 : undefined +>m17 : typeof m4 + +void m18; +>void m18 : undefined +>m18 : typeof m7 + +void m19; +>void m19 : undefined +>m19 : typeof m7 + +void m20; +>void m20 : undefined +>m20 : typeof m7 + +void m21; +>void m21 : undefined +>m21 : typeof m10 + +void m22; +>void m22 : undefined +>m22 : typeof m10 + +void m23; +>void m23 : undefined +>m23 : typeof m10 + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // cjs format file const x = 1; >x : 1 @@ -303,6 +727,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -351,6 +809,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt index 41443989a961d..63b623a8d25cf 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt @@ -4,6 +4,92 @@ tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1445: Module './su tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1445: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1445: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(78,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(79,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(80,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(81,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(82,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(83,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(84,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(85,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(50,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(51,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(52,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(53,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(54,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(55,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(56,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(57,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(58,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(59,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(60,1): error TS8002: 'import ... =' can only be used in TypeScript files. +tests/cases/conformance/node/allowJs/index.js(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(14,22): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(15,22): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(16,22): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(17,22): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(18,22): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(19,22): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(20,22): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(21,22): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(77,21): error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(78,21): error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(79,21): error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(80,21): error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(81,21): error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(82,21): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(83,21): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. ==== tests/cases/conformance/node/allowJs/subfolder/index.js (0 errors) ==== @@ -42,7 +128,7 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== +==== tests/cases/conformance/node/allowJs/index.js (38 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -55,6 +141,40 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones shouldn't all work - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -67,11 +187,113 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m27 = require("./subfolder/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m28 = require("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m29 = require("./subfolder2"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m30 = require("./subfolder2/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m31 = require("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in TypeScript files. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // esm format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.cjs (6 errors) ==== - // ESM format imports below should error +==== tests/cases/conformance/node/allowJs/index.cjs (27 errors) ==== + // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ !!! error TS1445: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. @@ -96,6 +318,28 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1445: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) + import * as m13 from "./"; + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m15 from "./subfolder"; + import * as m16 from "./subfolder/"; + import * as m17 from "./subfolder/index"; + import * as m18 from "./subfolder2"; + import * as m19 from "./subfolder2/"; + import * as m20 from "./subfolder2/index"; + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -108,10 +352,90 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. // cjs format file const x = 1; export {x}; -==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== +==== tests/cases/conformance/node/allowJs/index.mjs (27 errors) ==== import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -124,6 +448,40 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; + // The next ones should all fail - esm format files have no index resolution or extension resolution + import * as m13 from "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + import * as m14 from "./index"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + import * as m15 from "./subfolder"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + import * as m16 from "./subfolder/"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + import * as m17 from "./subfolder/index"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + import * as m18 from "./subfolder2"; + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + import * as m19 from "./subfolder2/"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + import * as m20 from "./subfolder2/index"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + import * as m21 from "./subfolder2/another"; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + import * as m22 from "./subfolder2/another/"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + import * as m23 from "./subfolder2/another/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. void m1; void m2; void m3; @@ -136,6 +494,87 @@ tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1445: Module './s void m10; void m11; void m12; + void m13; + void m14; + void m15; + void m16; + void m17; + void m18; + void m19; + void m20; + void m21; + void m22; + void m23; + + // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) + import m24 = require("./"); + ~~~~ +!!! error TS1445: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m25 = require("./index"); + ~~~~~~~~~ +!!! error TS1445: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m26 = require("./subfolder"); + import m27 = require("./subfolder/"); + import m28 = require("./subfolder/index"); + import m29 = require("./subfolder2"); + import m30 = require("./subfolder2/"); + import m31 = require("./subfolder2/index"); + import m32 = require("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m33 = require("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import m34 = require("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + void m24; + void m25; + void m26; + void m27; + void m28; + void m29; + void m30; + void m31; + void m32; + void m33; + void m34; + + // These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution + const _m35 = import("./"); + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. + const _m36 = import("./index"); + ~~~~~~~~~ +!!! error TS2307: Cannot find module './index' or its corresponding type declarations. + const _m37 = import("./subfolder"); + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder' or its corresponding type declarations. + const _m38 = import("./subfolder/"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/' or its corresponding type declarations. + const _m39 = import("./subfolder/index"); + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder/index' or its corresponding type declarations. + const _m40 = import("./subfolder2"); + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2' or its corresponding type declarations. + const _m41 = import("./subfolder2/"); + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/' or its corresponding type declarations. + const _m42 = import("./subfolder2/index"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/index' or its corresponding type declarations. + const _m43 = import("./subfolder2/another"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. + const _m44 = import("./subfolder2/another/"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. + const _m45 = import("./subfolder2/another/index"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. + // esm format file const x = 1; export {x}; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).js index 0ec674cdd18b3..ec1664707e795 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).js @@ -49,6 +49,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -61,11 +73,59 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; //// [index.cjs] -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -78,6 +138,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -90,6 +162,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -106,6 +226,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -118,6 +250,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; @@ -213,7 +394,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.x = void 0; -// ESM format imports below should error +// ESM-format imports below should issue errors const m1 = __importStar(require("./index.js")); const m2 = __importStar(require("./index.mjs")); const m3 = __importStar(require("./index.cjs")); @@ -226,6 +407,18 @@ const m9 = __importStar(require("./subfolder2/index.cjs")); const m10 = __importStar(require("./subfolder2/another/index.js")); const m11 = __importStar(require("./subfolder2/another/index.mjs")); const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -238,10 +431,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; exports.x = x; //// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -254,6 +495,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -266,10 +519,58 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; //// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -282,6 +583,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -294,6 +607,52 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).symbols index 90c86e3a1be64..d874ab0c830dd 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).symbols +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).symbols @@ -107,6 +107,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.js, 11, 6)) +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.js, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.js, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.js, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.js, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.js, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.js, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.js, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.js, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.js, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.js, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.js, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.js, 0, 6)) @@ -143,15 +177,149 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.js, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.js, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.js, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.js, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.js, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.js, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.js, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.js, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.js, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.js, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.js, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.js, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.js, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.js, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.js, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.js, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.js, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.js, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.js, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.js, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.js, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.js, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.js, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.js, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.js, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.js, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.js, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.js, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.js, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.js, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.js, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.js, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.js, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.js, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.js, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.js, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.js, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.js, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.js, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.js, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.js, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.js, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.js, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.js, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.js, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.js, 25, 5)) +>x : Symbol(x, Decl(index.js, 85, 5)) export {x}; ->x : Symbol(m1.x, Decl(index.js, 26, 8)) +>x : Symbol(m1.x, Decl(index.js, 86, 8)) === tests/cases/conformance/node/allowJs/index.cjs === -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; >m1 : Symbol(m1, Decl(index.cjs, 1, 6)) @@ -188,6 +356,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.cjs, 12, 6)) +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.cjs, 14, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.cjs, 15, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.cjs, 16, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.cjs, 17, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.cjs, 18, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.cjs, 19, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.cjs, 20, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.cjs, 21, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.cjs, 22, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.cjs, 23, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.cjs, 24, 6)) + void m1; >m1 : Symbol(m1, Decl(index.cjs, 1, 6)) @@ -224,12 +426,146 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.cjs, 12, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.cjs, 14, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.cjs, 15, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.cjs, 16, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.cjs, 17, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.cjs, 18, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.cjs, 19, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.cjs, 20, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.cjs, 21, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.cjs, 22, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.cjs, 23, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.cjs, 24, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.cjs, 47, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.cjs, 50, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.cjs, 51, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.cjs, 52, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.cjs, 53, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.cjs, 54, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.cjs, 55, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.cjs, 56, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.cjs, 57, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.cjs, 58, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.cjs, 59, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.cjs, 47, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.cjs, 50, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.cjs, 51, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.cjs, 52, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.cjs, 53, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.cjs, 54, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.cjs, 55, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.cjs, 56, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.cjs, 57, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.cjs, 58, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.cjs, 59, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.cjs, 74, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.cjs, 75, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.cjs, 76, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.cjs, 77, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.cjs, 78, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.cjs, 79, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.cjs, 80, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.cjs, 81, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.cjs, 82, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.cjs, 83, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.cjs, 84, 5)) + // cjs format file const x = 1; ->x : Symbol(x, Decl(index.cjs, 26, 5)) +>x : Symbol(x, Decl(index.cjs, 86, 5)) export {x}; ->x : Symbol(m3.x, Decl(index.cjs, 27, 8)) +>x : Symbol(m3.x, Decl(index.cjs, 87, 8)) === tests/cases/conformance/node/allowJs/index.mjs === import * as m1 from "./index.js"; @@ -268,6 +604,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : Symbol(m12, Decl(index.mjs, 11, 6)) +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : Symbol(m13, Decl(index.mjs, 13, 6)) + +import * as m14 from "./index"; +>m14 : Symbol(m14, Decl(index.mjs, 14, 6)) + +import * as m15 from "./subfolder"; +>m15 : Symbol(m15, Decl(index.mjs, 15, 6)) + +import * as m16 from "./subfolder/"; +>m16 : Symbol(m16, Decl(index.mjs, 16, 6)) + +import * as m17 from "./subfolder/index"; +>m17 : Symbol(m17, Decl(index.mjs, 17, 6)) + +import * as m18 from "./subfolder2"; +>m18 : Symbol(m18, Decl(index.mjs, 18, 6)) + +import * as m19 from "./subfolder2/"; +>m19 : Symbol(m19, Decl(index.mjs, 19, 6)) + +import * as m20 from "./subfolder2/index"; +>m20 : Symbol(m20, Decl(index.mjs, 20, 6)) + +import * as m21 from "./subfolder2/another"; +>m21 : Symbol(m21, Decl(index.mjs, 21, 6)) + +import * as m22 from "./subfolder2/another/"; +>m22 : Symbol(m22, Decl(index.mjs, 22, 6)) + +import * as m23 from "./subfolder2/another/index"; +>m23 : Symbol(m23, Decl(index.mjs, 23, 6)) + void m1; >m1 : Symbol(m1, Decl(index.mjs, 0, 6)) @@ -304,10 +674,144 @@ void m11; void m12; >m12 : Symbol(m12, Decl(index.mjs, 11, 6)) +void m13; +>m13 : Symbol(m13, Decl(index.mjs, 13, 6)) + +void m14; +>m14 : Symbol(m14, Decl(index.mjs, 14, 6)) + +void m15; +>m15 : Symbol(m15, Decl(index.mjs, 15, 6)) + +void m16; +>m16 : Symbol(m16, Decl(index.mjs, 16, 6)) + +void m17; +>m17 : Symbol(m17, Decl(index.mjs, 17, 6)) + +void m18; +>m18 : Symbol(m18, Decl(index.mjs, 18, 6)) + +void m19; +>m19 : Symbol(m19, Decl(index.mjs, 19, 6)) + +void m20; +>m20 : Symbol(m20, Decl(index.mjs, 20, 6)) + +void m21; +>m21 : Symbol(m21, Decl(index.mjs, 21, 6)) + +void m22; +>m22 : Symbol(m22, Decl(index.mjs, 22, 6)) + +void m23; +>m23 : Symbol(m23, Decl(index.mjs, 23, 6)) + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : Symbol(m24, Decl(index.mjs, 46, 9)) + +import m25 = require("./index"); +>m25 : Symbol(m25, Decl(index.mjs, 49, 27)) + +import m26 = require("./subfolder"); +>m26 : Symbol(m26, Decl(index.mjs, 50, 32)) + +import m27 = require("./subfolder/"); +>m27 : Symbol(m27, Decl(index.mjs, 51, 36)) + +import m28 = require("./subfolder/index"); +>m28 : Symbol(m28, Decl(index.mjs, 52, 37)) + +import m29 = require("./subfolder2"); +>m29 : Symbol(m29, Decl(index.mjs, 53, 42)) + +import m30 = require("./subfolder2/"); +>m30 : Symbol(m30, Decl(index.mjs, 54, 37)) + +import m31 = require("./subfolder2/index"); +>m31 : Symbol(m31, Decl(index.mjs, 55, 38)) + +import m32 = require("./subfolder2/another"); +>m32 : Symbol(m32, Decl(index.mjs, 56, 43)) + +import m33 = require("./subfolder2/another/"); +>m33 : Symbol(m33, Decl(index.mjs, 57, 45)) + +import m34 = require("./subfolder2/another/index"); +>m34 : Symbol(m34, Decl(index.mjs, 58, 46)) + +void m24; +>m24 : Symbol(m24, Decl(index.mjs, 46, 9)) + +void m25; +>m25 : Symbol(m25, Decl(index.mjs, 49, 27)) + +void m26; +>m26 : Symbol(m26, Decl(index.mjs, 50, 32)) + +void m27; +>m27 : Symbol(m27, Decl(index.mjs, 51, 36)) + +void m28; +>m28 : Symbol(m28, Decl(index.mjs, 52, 37)) + +void m29; +>m29 : Symbol(m29, Decl(index.mjs, 53, 42)) + +void m30; +>m30 : Symbol(m30, Decl(index.mjs, 54, 37)) + +void m31; +>m31 : Symbol(m31, Decl(index.mjs, 55, 38)) + +void m32; +>m32 : Symbol(m32, Decl(index.mjs, 56, 43)) + +void m33; +>m33 : Symbol(m33, Decl(index.mjs, 57, 45)) + +void m34; +>m34 : Symbol(m34, Decl(index.mjs, 58, 46)) + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Symbol(_m35, Decl(index.mjs, 73, 5)) + +const _m36 = import("./index"); +>_m36 : Symbol(_m36, Decl(index.mjs, 74, 5)) + +const _m37 = import("./subfolder"); +>_m37 : Symbol(_m37, Decl(index.mjs, 75, 5)) + +const _m38 = import("./subfolder/"); +>_m38 : Symbol(_m38, Decl(index.mjs, 76, 5)) + +const _m39 = import("./subfolder/index"); +>_m39 : Symbol(_m39, Decl(index.mjs, 77, 5)) + +const _m40 = import("./subfolder2"); +>_m40 : Symbol(_m40, Decl(index.mjs, 78, 5)) + +const _m41 = import("./subfolder2/"); +>_m41 : Symbol(_m41, Decl(index.mjs, 79, 5)) + +const _m42 = import("./subfolder2/index"); +>_m42 : Symbol(_m42, Decl(index.mjs, 80, 5)) + +const _m43 = import("./subfolder2/another"); +>_m43 : Symbol(_m43, Decl(index.mjs, 81, 5)) + +const _m44 = import("./subfolder2/another/"); +>_m44 : Symbol(_m44, Decl(index.mjs, 82, 5)) + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Symbol(_m45, Decl(index.mjs, 83, 5)) + // esm format file const x = 1; ->x : Symbol(x, Decl(index.mjs, 25, 5)) +>x : Symbol(x, Decl(index.mjs, 86, 5)) export {x}; ->x : Symbol(m2.x, Decl(index.mjs, 26, 8)) +>x : Symbol(m2.x, Decl(index.mjs, 87, 8)) diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).types index d0acce4132567..148c55c036dde 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).types +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).types @@ -116,6 +116,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -164,6 +198,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 @@ -173,7 +385,7 @@ export {x}; >x : 1 === tests/cases/conformance/node/allowJs/index.cjs === -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; >m1 : typeof m1 @@ -210,6 +422,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +>m13 : typeof m1 + +import * as m14 from "./index"; +>m14 : typeof m1 + +import * as m15 from "./subfolder"; +>m15 : typeof m4 + +import * as m16 from "./subfolder/"; +>m16 : typeof m4 + +import * as m17 from "./subfolder/index"; +>m17 : typeof m4 + +import * as m18 from "./subfolder2"; +>m18 : typeof m7 + +import * as m19 from "./subfolder2/"; +>m19 : typeof m7 + +import * as m20 from "./subfolder2/index"; +>m20 : typeof m7 + +import * as m21 from "./subfolder2/another"; +>m21 : typeof m10 + +import * as m22 from "./subfolder2/another/"; +>m22 : typeof m10 + +import * as m23 from "./subfolder2/another/index"; +>m23 : typeof m10 + void m1; >void m1 : undefined >m1 : typeof m1 @@ -258,6 +504,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : typeof m1 + +void m14; +>void m14 : undefined +>m14 : typeof m1 + +void m15; +>void m15 : undefined +>m15 : typeof m4 + +void m16; +>void m16 : undefined +>m16 : typeof m4 + +void m17; +>void m17 : undefined +>m17 : typeof m4 + +void m18; +>void m18 : undefined +>m18 : typeof m7 + +void m19; +>void m19 : undefined +>m19 : typeof m7 + +void m20; +>void m20 : undefined +>m20 : typeof m7 + +void m21; +>void m21 : undefined +>m21 : typeof m10 + +void m22; +>void m22 : undefined +>m22 : typeof m10 + +void m23; +>void m23 : undefined +>m23 : typeof m10 + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // cjs format file const x = 1; >x : 1 @@ -303,6 +727,40 @@ import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; >m12 : typeof m12 +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +>m13 : any + +import * as m14 from "./index"; +>m14 : any + +import * as m15 from "./subfolder"; +>m15 : any + +import * as m16 from "./subfolder/"; +>m16 : any + +import * as m17 from "./subfolder/index"; +>m17 : any + +import * as m18 from "./subfolder2"; +>m18 : any + +import * as m19 from "./subfolder2/"; +>m19 : any + +import * as m20 from "./subfolder2/index"; +>m20 : any + +import * as m21 from "./subfolder2/another"; +>m21 : any + +import * as m22 from "./subfolder2/another/"; +>m22 : any + +import * as m23 from "./subfolder2/another/index"; +>m23 : any + void m1; >void m1 : undefined >m1 : typeof m1 @@ -351,6 +809,184 @@ void m12; >void m12 : undefined >m12 : typeof m12 +void m13; +>void m13 : undefined +>m13 : any + +void m14; +>void m14 : undefined +>m14 : any + +void m15; +>void m15 : undefined +>m15 : any + +void m16; +>void m16 : undefined +>m16 : any + +void m17; +>void m17 : undefined +>m17 : any + +void m18; +>void m18 : undefined +>m18 : any + +void m19; +>void m19 : undefined +>m19 : any + +void m20; +>void m20 : undefined +>m20 : any + +void m21; +>void m21 : undefined +>m21 : any + +void m22; +>void m22 : undefined +>m22 : any + +void m23; +>void m23 : undefined +>m23 : any + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +>m24 : typeof m1 + +import m25 = require("./index"); +>m25 : typeof m1 + +import m26 = require("./subfolder"); +>m26 : typeof m4 + +import m27 = require("./subfolder/"); +>m27 : typeof m4 + +import m28 = require("./subfolder/index"); +>m28 : typeof m4 + +import m29 = require("./subfolder2"); +>m29 : typeof m7 + +import m30 = require("./subfolder2/"); +>m30 : typeof m7 + +import m31 = require("./subfolder2/index"); +>m31 : typeof m7 + +import m32 = require("./subfolder2/another"); +>m32 : typeof m10 + +import m33 = require("./subfolder2/another/"); +>m33 : typeof m10 + +import m34 = require("./subfolder2/another/index"); +>m34 : typeof m10 + +void m24; +>void m24 : undefined +>m24 : typeof m1 + +void m25; +>void m25 : undefined +>m25 : typeof m1 + +void m26; +>void m26 : undefined +>m26 : typeof m4 + +void m27; +>void m27 : undefined +>m27 : typeof m4 + +void m28; +>void m28 : undefined +>m28 : typeof m4 + +void m29; +>void m29 : undefined +>m29 : typeof m7 + +void m30; +>void m30 : undefined +>m30 : typeof m7 + +void m31; +>void m31 : undefined +>m31 : typeof m7 + +void m32; +>void m32 : undefined +>m32 : typeof m10 + +void m33; +>void m33 : undefined +>m33 : typeof m10 + +void m34; +>void m34 : undefined +>m34 : typeof m10 + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +>_m35 : Promise +>import("./") : Promise +>"./" : "./" + +const _m36 = import("./index"); +>_m36 : Promise +>import("./index") : Promise +>"./index" : "./index" + +const _m37 = import("./subfolder"); +>_m37 : Promise +>import("./subfolder") : Promise +>"./subfolder" : "./subfolder" + +const _m38 = import("./subfolder/"); +>_m38 : Promise +>import("./subfolder/") : Promise +>"./subfolder/" : "./subfolder/" + +const _m39 = import("./subfolder/index"); +>_m39 : Promise +>import("./subfolder/index") : Promise +>"./subfolder/index" : "./subfolder/index" + +const _m40 = import("./subfolder2"); +>_m40 : Promise +>import("./subfolder2") : Promise +>"./subfolder2" : "./subfolder2" + +const _m41 = import("./subfolder2/"); +>_m41 : Promise +>import("./subfolder2/") : Promise +>"./subfolder2/" : "./subfolder2/" + +const _m42 = import("./subfolder2/index"); +>_m42 : Promise +>import("./subfolder2/index") : Promise +>"./subfolder2/index" : "./subfolder2/index" + +const _m43 = import("./subfolder2/another"); +>_m43 : Promise +>import("./subfolder2/another") : Promise +>"./subfolder2/another" : "./subfolder2/another" + +const _m44 = import("./subfolder2/another/"); +>_m44 : Promise +>import("./subfolder2/another/") : Promise +>"./subfolder2/another/" : "./subfolder2/another/" + +const _m45 = import("./subfolder2/another/index"); +>_m45 : Promise +>import("./subfolder2/another/index") : Promise +>"./subfolder2/another/index" : "./subfolder2/another/index" + // esm format file const x = 1; >x : 1 diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt new file mode 100644 index 0000000000000..5751e7ada9d36 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (2 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + 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; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (1 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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js new file mode 100644 index 0000000000000..140980f9624de --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js @@ -0,0 +1,265 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts] //// + +//// [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"; +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] +// 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.d.ts] +// 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; +//// [index.d.mts] +// 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; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "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" + } + } + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/a")); +const mjsi = __importStar(require("inner/b")); +const typei = __importStar(require("inner")); +const ts = __importStar(require("inner/types")); +cjsi.cjsSource; +mjsi.cjsSource; +typei.implicitCjsSource; +ts.cjsSource; +//// [index.mjs] +// 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; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/a")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/b")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; +const ts = __importStar(require("inner/types")); +exports.ts = ts; +exports.cjsSource = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +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 declare const mjsSource = true; +//// [index.d.cts] +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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..b1b4757000e77 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols @@ -0,0 +1,243 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.js, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.js, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.js, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.mjs, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.mjs, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.cjs, 10, 6)) + +cjsi.cjsSource; +>cjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +mjsi.cjsSource; +>mjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +typei.implicitCjsSource; +>typei.implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) +>implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +ts.cjsSource; +>ts.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>ts : Symbol(ts, Decl(index.cjs, 10, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.ts, 4, 6)) + +export { cjs }; +>cjs : Symbol(mjs.type.cjs, Decl(index.d.ts, 5, 8)) + +export { mjs }; +>mjs : Symbol(mjs.type.mjs, Decl(index.d.ts, 6, 8)) + +export { type }; +>type : Symbol(mjs.type.type, Decl(index.d.ts, 7, 8)) + +export { ts }; +>ts : Symbol(mjs.type.ts, Decl(index.d.ts, 8, 8)) + +export const implicitCjsSource = true; +>implicitCjsSource : Symbol(mjs.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.mts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) + +export const mjsSource = true; +>mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.cts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.cts, 8, 8)) + +export const cjsSource = true; +>cjsSource : Symbol(cjs.cjsSource, Decl(index.d.cts, 9, 12)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types new file mode 100644 index 0000000000000..4df6899a8a148 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types @@ -0,0 +1,246 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi.type + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.cjsSource; +>cjsi.cjsSource : true +>cjsi : typeof cjsi +>cjsSource : true + +mjsi.cjsSource; +>mjsi.cjsSource : true +>mjsi : typeof cjsi +>cjsSource : true + +typei.implicitCjsSource; +>typei.implicitCjsSource : true +>typei : typeof cjsi.type +>implicitCjsSource : true + +ts.cjsSource; +>ts.cjsSource : true +>ts : typeof cjsi +>cjsSource : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : any + +import * as mjs from "inner/b"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.type + +import * as ts from "inner/types"; +>ts : typeof mjs + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.type + +export { ts }; +>ts : typeof mjs + +export const implicitCjsSource = true; +>implicitCjsSource : true +>true : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs + +export { ts }; +>ts : typeof cjs + +export const mjsSource = true; +>mjsSource : true +>true : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs.type + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs.type + +export { ts }; +>ts : typeof cjs + +export const cjsSource = true; +>cjsSource : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..5751e7ada9d36 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (2 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + 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; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (1 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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..140980f9624de --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js @@ -0,0 +1,265 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts] //// + +//// [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"; +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] +// 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.d.ts] +// 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; +//// [index.d.mts] +// 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; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "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" + } + } + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/a")); +const mjsi = __importStar(require("inner/b")); +const typei = __importStar(require("inner")); +const ts = __importStar(require("inner/types")); +cjsi.cjsSource; +mjsi.cjsSource; +typei.implicitCjsSource; +ts.cjsSource; +//// [index.mjs] +// 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; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/a")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/b")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; +const ts = __importStar(require("inner/types")); +exports.ts = ts; +exports.cjsSource = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +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 declare const mjsSource = true; +//// [index.d.cts] +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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..b1b4757000e77 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols @@ -0,0 +1,243 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.js, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.js, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.js, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.mjs, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.mjs, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.cjs, 10, 6)) + +cjsi.cjsSource; +>cjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +mjsi.cjsSource; +>mjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +typei.implicitCjsSource; +>typei.implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) +>implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +ts.cjsSource; +>ts.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>ts : Symbol(ts, Decl(index.cjs, 10, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.ts, 4, 6)) + +export { cjs }; +>cjs : Symbol(mjs.type.cjs, Decl(index.d.ts, 5, 8)) + +export { mjs }; +>mjs : Symbol(mjs.type.mjs, Decl(index.d.ts, 6, 8)) + +export { type }; +>type : Symbol(mjs.type.type, Decl(index.d.ts, 7, 8)) + +export { ts }; +>ts : Symbol(mjs.type.ts, Decl(index.d.ts, 8, 8)) + +export const implicitCjsSource = true; +>implicitCjsSource : Symbol(mjs.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.mts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) + +export const mjsSource = true; +>mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.cts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.cts, 8, 8)) + +export const cjsSource = true; +>cjsSource : Symbol(cjs.cjsSource, Decl(index.d.cts, 9, 12)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..4df6899a8a148 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types @@ -0,0 +1,246 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi.type + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.cjsSource; +>cjsi.cjsSource : true +>cjsi : typeof cjsi +>cjsSource : true + +mjsi.cjsSource; +>mjsi.cjsSource : true +>mjsi : typeof cjsi +>cjsSource : true + +typei.implicitCjsSource; +>typei.implicitCjsSource : true +>typei : typeof cjsi.type +>implicitCjsSource : true + +ts.cjsSource; +>ts.cjsSource : true +>ts : typeof cjsi +>cjsSource : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : any + +import * as mjs from "inner/b"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.type + +import * as ts from "inner/types"; +>ts : typeof mjs + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.type + +export { ts }; +>ts : typeof mjs + +export const implicitCjsSource = true; +>implicitCjsSource : true +>true : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs + +export { ts }; +>ts : typeof cjs + +export const mjsSource = true; +>mjsSource : true +>true : true + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs.type + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs.type + +export { ts }; +>ts : typeof cjs + +export const cjsSource = true; +>cjsSource : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt new file mode 100644 index 0000000000000..e35973a75ac53 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt @@ -0,0 +1,107 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/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 }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js new file mode 100644 index 0000000000000..aaac0fe09c108 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js @@ -0,0 +1,213 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts] //// + +//// [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"; +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] +// 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.d.ts] +// 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 }; +//// [index.d.mts] +// 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 }; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// 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 }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..67cf88b744a92 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).symbols @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).types new file mode 100644 index 0000000000000..a4138d3738e89 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).types @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : any + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..e35973a75ac53 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt @@ -0,0 +1,107 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/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 }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..aaac0fe09c108 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js @@ -0,0 +1,213 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts] //// + +//// [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"; +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] +// 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.d.ts] +// 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 }; +//// [index.d.mts] +// 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 }; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// 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 }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..67cf88b744a92 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).symbols @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 9, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 9, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 9, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..a4138d3738e89 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).types @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : any + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt new file mode 100644 index 0000000000000..8197ba5190a62 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (2 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "#type"; + ~~~~~~~ +!!! error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).js new file mode 100644 index 0000000000000..c6fa45d5bb7a3 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts] //// + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js", + "imports": { + "#cjs": "./index.cjs", + "#mjs": "./index.mjs", + "#type": "./index.js" + } +} + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const cjs = __importStar(require("#cjs")); +const mjs = __importStar(require("#mjs")); +const type = __importStar(require("#type")); +cjs; +mjs; +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).symbols new file mode 100644 index 0000000000000..196837bc0bcf1 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).types new file mode 100644 index 0000000000000..6387f04fcb693 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..8197ba5190a62 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/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; +==== tests/cases/conformance/node/allowJs/index.cjs (2 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "#type"; + ~~~~~~~ +!!! error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; +==== tests/cases/conformance/node/allowJs/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/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js new file mode 100644 index 0000000000000..c6fa45d5bb7a3 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts] //// + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js", + "imports": { + "#cjs": "./index.cjs", + "#mjs": "./index.mjs", + "#type": "./index.js" + } +} + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const cjs = __importStar(require("#cjs")); +const mjs = __importStar(require("#mjs")); +const type = __importStar(require("#type")); +cjs; +mjs; +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).symbols new file mode 100644 index 0000000000000..196837bc0bcf1 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.js, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.js, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.js, 2, 6)) + +type; +>type : Symbol(type, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cjs, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cjs, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cjs, 3, 6)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).types new file mode 100644 index 0000000000000..6387f04fcb693 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt new file mode 100644 index 0000000000000..d4de70ddb8829 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js new file mode 100644 index 0000000000000..65b383a70ec7c --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index")); +const mjsi = __importStar(require("inner/mjs/index")); +const typei = __importStar(require("inner/js/index")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).symbols new file mode 100644 index 0000000000000..3b5ca0ad0c6c7 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).types new file mode 100644 index 0000000000000..65f2fc46d87f6 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..d4de70ddb8829 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js new file mode 100644 index 0000000000000..65b383a70ec7c --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index")); +const mjsi = __importStar(require("inner/mjs/index")); +const typei = __importStar(require("inner/js/index")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).symbols new file mode 100644 index 0000000000000..3b5ca0ad0c6c7 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).types new file mode 100644 index 0000000000000..65f2fc46d87f6 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).errors.txt new file mode 100644 index 0000000000000..2036308bb9b9f --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).errors.txt @@ -0,0 +1,120 @@ +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + + +==== tests/cases/conformance/node/allowJs/index.js (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (3 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js new file mode 100644 index 0000000000000..825b1371c4a14 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index.cjs")); +const mjsi = __importStar(require("inner/mjs/index.mjs")); +const typei = __importStar(require("inner/js/index.js")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index.cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index.mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index.js")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).symbols new file mode 100644 index 0000000000000..870a2298deadd --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).types new file mode 100644 index 0000000000000..c35a6bdbf60f5 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt new file mode 100644 index 0000000000000..6cbffcab08141 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index.cjs"; + import * as mjs from "inner/mjs/index.mjs"; + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js new file mode 100644 index 0000000000000..825b1371c4a14 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index.cjs")); +const mjsi = __importStar(require("inner/mjs/index.mjs")); +const typei = __importStar(require("inner/js/index.js")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index.cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index.mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index.js")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).symbols new file mode 100644 index 0000000000000..572b5ddd1100e --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).types new file mode 100644 index 0000000000000..d36dd358d8bb3 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof mjs + +import * as type from "inner/js/index.js"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index.js"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index.js"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt new file mode 100644 index 0000000000000..c47227892582f --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (2 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + 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; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (1 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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js new file mode 100644 index 0000000000000..5154e5ea3e670 --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js @@ -0,0 +1,265 @@ +//// [tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// 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.d.ts] +// 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; +//// [index.d.mts] +// 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; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "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" + } + } + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/a")); +const mjsi = __importStar(require("inner/b")); +const typei = __importStar(require("inner")); +const ts = __importStar(require("inner/types")); +cjsi.cjsSource; +mjsi.cjsSource; +typei.implicitCjsSource; +ts.cjsSource; +//// [index.mjs] +// 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; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/a")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/b")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; +const ts = __importStar(require("inner/types")); +exports.ts = ts; +exports.cjsSource = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +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 declare const mjsSource = true; +//// [index.d.cts] +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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..7f4d8533a44fd --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols @@ -0,0 +1,243 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.ts, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.ts, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.ts, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.mts, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.mts, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.mts, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.cts, 10, 6)) + +cjsi.cjsSource; +>cjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +mjsi.cjsSource; +>mjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +typei.implicitCjsSource; +>typei.implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) +>typei : Symbol(typei, Decl(index.cts, 9, 6)) +>implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +ts.cjsSource; +>ts.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>ts : Symbol(ts, Decl(index.cts, 10, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.ts, 4, 6)) + +export { cjs }; +>cjs : Symbol(mjs.type.cjs, Decl(index.d.ts, 5, 8)) + +export { mjs }; +>mjs : Symbol(mjs.type.mjs, Decl(index.d.ts, 6, 8)) + +export { type }; +>type : Symbol(mjs.type.type, Decl(index.d.ts, 7, 8)) + +export { ts }; +>ts : Symbol(mjs.type.ts, Decl(index.d.ts, 8, 8)) + +export const implicitCjsSource = true; +>implicitCjsSource : Symbol(mjs.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.mts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) + +export const mjsSource = true; +>mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.cts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.cts, 8, 8)) + +export const cjsSource = true; +>cjsSource : Symbol(cjs.cjsSource, Decl(index.d.cts, 9, 12)) + diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types new file mode 100644 index 0000000000000..fe81bf80e7f83 --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types @@ -0,0 +1,246 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi.type + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.cjsSource; +>cjsi.cjsSource : true +>cjsi : typeof cjsi +>cjsSource : true + +mjsi.cjsSource; +>mjsi.cjsSource : true +>mjsi : typeof cjsi +>cjsSource : true + +typei.implicitCjsSource; +>typei.implicitCjsSource : true +>typei : typeof cjsi.type +>implicitCjsSource : true + +ts.cjsSource; +>ts.cjsSource : true +>ts : typeof cjsi +>cjsSource : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : any + +import * as mjs from "inner/b"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.type + +import * as ts from "inner/types"; +>ts : typeof mjs + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.type + +export { ts }; +>ts : typeof mjs + +export const implicitCjsSource = true; +>implicitCjsSource : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs + +export { ts }; +>ts : typeof cjs + +export const mjsSource = true; +>mjsSource : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs.type + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs.type + +export { ts }; +>ts : typeof cjs + +export const cjsSource = true; +>cjsSource : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..c47227892582f --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (2 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + 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; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (1 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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..5154e5ea3e670 --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js @@ -0,0 +1,265 @@ +//// [tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// 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.d.ts] +// 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; +//// [index.d.mts] +// 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; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "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" + } + } + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/a")); +const mjsi = __importStar(require("inner/b")); +const typei = __importStar(require("inner")); +const ts = __importStar(require("inner/types")); +cjsi.cjsSource; +mjsi.cjsSource; +typei.implicitCjsSource; +ts.cjsSource; +//// [index.mjs] +// 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; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/a")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/b")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; +const ts = __importStar(require("inner/types")); +exports.ts = ts; +exports.cjsSource = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +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 declare const mjsSource = true; +//// [index.d.cts] +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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..7f4d8533a44fd --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols @@ -0,0 +1,243 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.ts, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.ts, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.ts, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.mts, 10, 6)) + +cjsi.mjsSource; +>cjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +mjsi.mjsSource; +>mjsi.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +typei.mjsSource; +>typei.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>typei : Symbol(typei, Decl(index.mts, 9, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +ts.mjsSource; +>ts.mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) +>ts : Symbol(ts, Decl(index.mts, 10, 6)) +>mjsSource : Symbol(cjsi.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/a"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/b"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.cts, 10, 6)) + +cjsi.cjsSource; +>cjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +mjsi.cjsSource; +>mjsi.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +typei.implicitCjsSource; +>typei.implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) +>typei : Symbol(typei, Decl(index.cts, 9, 6)) +>implicitCjsSource : Symbol(cjsi.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +ts.cjsSource; +>ts.cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) +>ts : Symbol(ts, Decl(index.cts, 10, 6)) +>cjsSource : Symbol(cjsi.cjsSource, Decl(index.d.cts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.ts, 4, 6)) + +export { cjs }; +>cjs : Symbol(mjs.type.cjs, Decl(index.d.ts, 5, 8)) + +export { mjs }; +>mjs : Symbol(mjs.type.mjs, Decl(index.d.ts, 6, 8)) + +export { type }; +>type : Symbol(mjs.type.type, Decl(index.d.ts, 7, 8)) + +export { ts }; +>ts : Symbol(mjs.type.ts, Decl(index.d.ts, 8, 8)) + +export const implicitCjsSource = true; +>implicitCjsSource : Symbol(mjs.type.implicitCjsSource, Decl(index.d.ts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.mts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) + +export const mjsSource = true; +>mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/b"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +import * as ts from "inner/types"; +>ts : Symbol(ts, Decl(index.d.cts, 4, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 5, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 6, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 7, 8)) + +export { ts }; +>ts : Symbol(cjs.ts, Decl(index.d.cts, 8, 8)) + +export const cjsSource = true; +>cjsSource : Symbol(cjs.cjsSource, Decl(index.d.cts, 9, 12)) + diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..fe81bf80e7f83 --- /dev/null +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types @@ -0,0 +1,246 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.mjsSource; +>cjsi.mjsSource : true +>cjsi : typeof cjsi +>mjsSource : true + +mjsi.mjsSource; +>mjsi.mjsSource : true +>mjsi : typeof cjsi +>mjsSource : true + +typei.mjsSource; +>typei.mjsSource : true +>typei : typeof cjsi +>mjsSource : true + +ts.mjsSource; +>ts.mjsSource : true +>ts : typeof cjsi +>mjsSource : true + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/a"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/b"; +>mjsi : typeof cjsi + +import * as typei from "inner"; +>typei : typeof cjsi.type + +import * as ts from "inner/types"; +>ts : typeof cjsi + +cjsi.cjsSource; +>cjsi.cjsSource : true +>cjsi : typeof cjsi +>cjsSource : true + +mjsi.cjsSource; +>mjsi.cjsSource : true +>mjsi : typeof cjsi +>cjsSource : true + +typei.implicitCjsSource; +>typei.implicitCjsSource : true +>typei : typeof cjsi.type +>implicitCjsSource : true + +ts.cjsSource; +>ts.cjsSource : true +>ts : typeof cjsi +>cjsSource : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : any + +import * as mjs from "inner/b"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.type + +import * as ts from "inner/types"; +>ts : typeof mjs + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.type + +export { ts }; +>ts : typeof mjs + +export const implicitCjsSource = true; +>implicitCjsSource : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs + +export { ts }; +>ts : typeof cjs + +export const mjsSource = true; +>mjsSource : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/a"; +>cjs : typeof cjs + +import * as mjs from "inner/b"; +>mjs : typeof cjs + +import * as type from "inner"; +>type : typeof cjs.type + +import * as ts from "inner/types"; +>ts : typeof cjs + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs + +export { type }; +>type : typeof cjs.type + +export { ts }; +>ts : typeof cjs + +export const cjsSource = true; +>cjsSource : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt new file mode 100644 index 0000000000000..c2b9f89ae410a --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt @@ -0,0 +1,107 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/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 }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js new file mode 100644 index 0000000000000..120273188d958 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js @@ -0,0 +1,213 @@ +//// [tests/cases/conformance/node/nodeModulesPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// 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.d.ts] +// 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 }; +//// [index.d.mts] +// 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 }; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// 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 }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..8093c39582ddc --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).symbols @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesPackageExports(module=node12).types new file mode 100644 index 0000000000000..85dad3ea25f98 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).types @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : any + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..c2b9f89ae410a --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt @@ -0,0 +1,107 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1445: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/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 }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..120273188d958 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js @@ -0,0 +1,213 @@ +//// [tests/cases/conformance/node/nodeModulesPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// 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.d.ts] +// 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 }; +//// [index.d.mts] +// 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 }; +//// [index.d.cts] +// 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] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +cjs; +mjs; +type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// 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 }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..8093c39582ddc --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).symbols @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..85dad3ea25f98 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).types @@ -0,0 +1,174 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : any + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt new file mode 100644 index 0000000000000..4de06801c128d --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + import * as type from "#type"; + cjs; + mjs; + type; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + import * as type from "#type"; + cjs; + mjs; + type; +==== tests/cases/conformance/node/index.cts (2 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "#type"; + ~~~~~~~ +!!! error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesPackageImports(module=node12).js b/tests/baselines/reference/nodeModulesPackageImports(module=node12).js new file mode 100644 index 0000000000000..11b7ef2f6a449 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/node/nodeModulesPackageImports.ts] //// + +//// [index.ts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.mts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js", + "imports": { + "#cjs": "./index.cjs", + "#mjs": "./index.mjs", + "#type": "./index.js" + } +} + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const cjs = __importStar(require("#cjs")); +const mjs = __importStar(require("#mjs")); +const type = __importStar(require("#type")); +cjs; +mjs; +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=node12).symbols b/tests/baselines/reference/nodeModulesPackageImports(module=node12).symbols new file mode 100644 index 0000000000000..2a0fece72371f --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=node12).types b/tests/baselines/reference/nodeModulesPackageImports(module=node12).types new file mode 100644 index 0000000000000..b4ade0559239b --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..4de06801c128d --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + import * as type from "#type"; + cjs; + mjs; + type; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + import * as type from "#type"; + cjs; + mjs; + type; +==== tests/cases/conformance/node/index.cts (2 errors) ==== + // esm format file + import * as cjs from "#cjs"; + import * as mjs from "#mjs"; + ~~~~~~ +!!! error TS1445: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "#type"; + ~~~~~~~ +!!! error TS1445: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + cjs; + mjs; + type; +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js new file mode 100644 index 0000000000000..11b7ef2f6a449 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/node/nodeModulesPackageImports.ts] //// + +//// [index.ts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.mts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cts] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js", + "imports": { + "#cjs": "./index.cjs", + "#mjs": "./index.mjs", + "#type": "./index.js" + } +} + +//// [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"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const cjs = __importStar(require("#cjs")); +const mjs = __importStar(require("#mjs")); +const type = __importStar(require("#type")); +cjs; +mjs; +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).symbols new file mode 100644 index 0000000000000..2a0fece72371f --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as cjs from "#cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "#mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 3, 6)) + diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).types b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).types new file mode 100644 index 0000000000000..b4ade0559239b --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as cjs from "#cjs"; +>cjs : typeof cjs + +import * as mjs from "#mjs"; +>mjs : typeof mjs + +import * as type from "#type"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt new file mode 100644 index 0000000000000..bcfafcc16a916 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/index.cts(3,23): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js new file mode 100644 index 0000000000000..d7d5f415e1c9c --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExports.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index")); +const mjsi = __importStar(require("inner/mjs/index")); +const typei = __importStar(require("inner/js/index")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).symbols b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).symbols new file mode 100644 index 0000000000000..adbb566941d1a --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).types b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).types new file mode 100644 index 0000000000000..28015ecbd24c3 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..bcfafcc16a916 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/index.cts(3,23): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index"; + import * as mjsi from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js new file mode 100644 index 0000000000000..d7d5f415e1c9c --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExports.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index")); +const mjsi = __importStar(require("inner/mjs/index")); +const typei = __importStar(require("inner/js/index")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).symbols new file mode 100644 index 0000000000000..adbb566941d1a --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/index"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/index"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).types b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).types new file mode 100644 index 0000000000000..28015ecbd24c3 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).errors.txt new file mode 100644 index 0000000000000..6c400a3f69c84 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).errors.txt @@ -0,0 +1,120 @@ +tests/cases/conformance/node/index.cts(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(3,23): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(4,24): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + + +==== tests/cases/conformance/node/index.ts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.mts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.cts (3 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as typei from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/index.cjs' or its corresponding type declarations. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/index.mjs' or its corresponding type declarations. + import * as type from "inner/js/index.js"; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/index.js' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js new file mode 100644 index 0000000000000..b96800f1159b4 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index.cjs")); +const mjsi = __importStar(require("inner/mjs/index.mjs")); +const typei = __importStar(require("inner/js/index.js")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index.cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index.mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index.js")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).symbols b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).symbols new file mode 100644 index 0000000000000..0a9b4ceb3a00d --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).types b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).types new file mode 100644 index 0000000000000..c7f760959691f --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : any + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : any + +import * as typei from "inner/js/index.js"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : any + +import * as type from "inner/js/index.js"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt new file mode 100644 index 0000000000000..3650ae6969fbb --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/node/index.cts(3,23): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/index.cjs"; + import * as mjsi from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner/js/index.js"; + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index.cjs"; + import * as mjs from "inner/mjs/index.mjs"; + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index.cjs"; + import * as mjs from "inner/mjs/index.mjs"; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1445: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index.js"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js new file mode 100644 index 0000000000000..b96800f1159b4 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/index.cjs")); +const mjsi = __importStar(require("inner/mjs/index.mjs")); +const typei = __importStar(require("inner/js/index.js")); +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.type = exports.mjs = exports.cjs = void 0; +// cjs format file +const cjs = __importStar(require("inner/cjs/index.cjs")); +exports.cjs = cjs; +const mjs = __importStar(require("inner/mjs/index.mjs")); +exports.mjs = mjs; +const type = __importStar(require("inner/js/index.js")); +exports.type = type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).symbols b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).symbols new file mode 100644 index 0000000000000..c8c8c3a38f8ab --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/index.js"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index.js"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).types b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).types new file mode 100644 index 0000000000000..efc768d50a237 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs/index.mjs"; +>mjsi : typeof cjsi.mjs + +import * as typei from "inner/js/index.js"; +>typei : typeof cjsi.mjs.type + +cjsi; +>cjsi : typeof cjsi + +mjsi; +>mjsi : typeof cjsi.mjs + +typei; +>typei : typeof cjsi.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : any + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof mjs + +import * as type from "inner/js/index.js"; +>type : typeof mjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index.js"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index.mjs"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index.js"; +>type : typeof cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.type + diff --git a/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt b/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt new file mode 100644 index 0000000000000..549e462f42aac --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/node/index.cts(2,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + self; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" + } \ No newline at end of file diff --git a/tests/baselines/reference/nodePackageSelfName(module=node12).js b/tests/baselines/reference/nodePackageSelfName(module=node12).js new file mode 100644 index 0000000000000..23c9f6f1fa067 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=node12).js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/node/nodePackageSelfName.ts] //// + +//// [index.ts] +// esm format file +import * as self from "package"; +self; +//// [index.mts] +// esm format file +import * as self from "package"; +self; +//// [index.cts] +// esm format file +import * as self from "package"; +self; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const self = __importStar(require("package")); +self; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodePackageSelfName(module=node12).symbols b/tests/baselines/reference/nodePackageSelfName(module=node12).symbols new file mode 100644 index 0000000000000..44b9566b90c93 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=node12).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.ts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.mts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.cts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodePackageSelfName(module=node12).types b/tests/baselines/reference/nodePackageSelfName(module=node12).types new file mode 100644 index 0000000000000..b41eef255ab89 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=node12).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + diff --git a/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt b/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt new file mode 100644 index 0000000000000..549e462f42aac --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/node/index.cts(2,23): error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + import * as self from "package"; + self; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // esm format file + import * as self from "package"; + ~~~~~~~~~ +!!! error TS1445: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + self; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" + } \ No newline at end of file diff --git a/tests/baselines/reference/nodePackageSelfName(module=nodenext).js b/tests/baselines/reference/nodePackageSelfName(module=nodenext).js new file mode 100644 index 0000000000000..23c9f6f1fa067 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=nodenext).js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/node/nodePackageSelfName.ts] //// + +//// [index.ts] +// esm format file +import * as self from "package"; +self; +//// [index.mts] +// esm format file +import * as self from "package"; +self; +//// [index.cts] +// esm format file +import * as self from "package"; +self; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} + +//// [index.js] +// esm format file +import * as self from "package"; +self; +//// [index.mjs] +// esm format file +import * as self from "package"; +self; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const self = __importStar(require("package")); +self; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodePackageSelfName(module=nodenext).symbols b/tests/baselines/reference/nodePackageSelfName(module=nodenext).symbols new file mode 100644 index 0000000000000..44b9566b90c93 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=nodenext).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.ts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.mts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as self from "package"; +>self : Symbol(self, Decl(index.cts, 1, 6)) + +self; +>self : Symbol(self, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodePackageSelfName(module=nodenext).types b/tests/baselines/reference/nodePackageSelfName(module=nodenext).types new file mode 100644 index 0000000000000..b41eef255ab89 --- /dev/null +++ b/tests/baselines/reference/nodePackageSelfName(module=nodenext).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as self from "package"; +>self : typeof self + +self; +>self : typeof self + diff --git a/tests/baselines/reference/requireOfJsonFileWithAmd.errors.txt b/tests/baselines/reference/requireOfJsonFileWithAmd.errors.txt index 43a71b9fbb590..361d1d71f0eaf 100644 --- a/tests/baselines/reference/requireOfJsonFileWithAmd.errors.txt +++ b/tests/baselines/reference/requireOfJsonFileWithAmd.errors.txt @@ -1,17 +1,14 @@ error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy. tests/cases/compiler/file1.ts(1,21): error TS2792: Cannot find module './b'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? -tests/cases/compiler/file1.ts(3,21): error TS2792: Cannot find module './b.json'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? !!! error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy. -==== tests/cases/compiler/file1.ts (2 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== import b1 = require('./b'); ~~~~~ !!! error TS2792: Cannot find module './b'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? let x = b1.a; import b2 = require('./b.json'); - ~~~~~~~~~~ -!!! error TS2792: Cannot find module './b.json'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? if (x) { let b = b2.b; x = (b1.b === b); diff --git a/tests/baselines/reference/requireOfJsonFileWithAmd.js b/tests/baselines/reference/requireOfJsonFileWithAmd.js index 6e4928174c2d8..6d02fb151c0ab 100644 --- a/tests/baselines/reference/requireOfJsonFileWithAmd.js +++ b/tests/baselines/reference/requireOfJsonFileWithAmd.js @@ -15,6 +15,11 @@ if (x) { "b": "hello" } +//// [out/b.json] +{ + "a": true, + "b": "hello" +} //// [out/file1.js] define(["require", "exports", "./b", "./b.json"], function (require, exports, b1, b2) { "use strict"; diff --git a/tests/baselines/reference/requireOfJsonFileWithAmd.symbols b/tests/baselines/reference/requireOfJsonFileWithAmd.symbols index 1729461ef07bb..c32e6d05df4ec 100644 --- a/tests/baselines/reference/requireOfJsonFileWithAmd.symbols +++ b/tests/baselines/reference/requireOfJsonFileWithAmd.symbols @@ -14,7 +14,9 @@ if (x) { let b = b2.b; >b : Symbol(b, Decl(file1.ts, 4, 7)) +>b2.b : Symbol("b", Decl(b.json, 1, 14)) >b2 : Symbol(b2, Decl(file1.ts, 1, 13)) +>b : Symbol("b", Decl(b.json, 1, 14)) x = (b1.b === b); >x : Symbol(x, Decl(file1.ts, 1, 3)) @@ -22,3 +24,11 @@ if (x) { >b : Symbol(b, Decl(file1.ts, 4, 7)) } +=== tests/cases/compiler/b.json === +{ + "a": true, +>"a" : Symbol("a", Decl(b.json, 0, 1)) + + "b": "hello" +>"b" : Symbol("b", Decl(b.json, 1, 14)) +} diff --git a/tests/baselines/reference/requireOfJsonFileWithAmd.types b/tests/baselines/reference/requireOfJsonFileWithAmd.types index 7984743550dae..6e06eecf0e17a 100644 --- a/tests/baselines/reference/requireOfJsonFileWithAmd.types +++ b/tests/baselines/reference/requireOfJsonFileWithAmd.types @@ -9,16 +9,16 @@ let x = b1.a; >a : any import b2 = require('./b.json'); ->b2 : any +>b2 : { a: boolean; b: string; } if (x) { >x : any let b = b2.b; ->b : any ->b2.b : any ->b2 : any ->b : any +>b : string +>b2.b : string +>b2 : { a: boolean; b: string; } +>b : string x = (b1.b === b); >x = (b1.b === b) : boolean @@ -28,6 +28,18 @@ if (x) { >b1.b : any >b1 : any >b : any ->b : any +>b : string } +=== tests/cases/compiler/b.json === +{ +>{ "a": true, "b": "hello"} : { a: boolean; b: string; } + + "a": true, +>"a" : boolean +>true : true + + "b": "hello" +>"b" : string +>"hello" : "hello" +} diff --git a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.errors.txt b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.errors.txt index ac67223d7e6a9..6d1d5b7751429 100644 --- a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.errors.txt +++ b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.errors.txt @@ -1,15 +1,12 @@ error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy. tests/cases/compiler/file1.ts(1,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. -tests/cases/compiler/file1.ts(1,20): error TS2792: Cannot find module './b.json'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? !!! error TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy. -==== tests/cases/compiler/file1.ts (2 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== import * as b from './b.json'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. - ~~~~~~~~~~ -!!! error TS2792: Cannot find module './b.json'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? ==== tests/cases/compiler/b.json (0 errors) ==== { diff --git a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.js b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.js index a94bdd896dddd..ee7f0e24127c3 100644 --- a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.js +++ b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.js @@ -9,6 +9,11 @@ import * as b from './b.json'; "b": "hello" } +//// [out/b.json] +{ + "a": true, + "b": "hello" +} //// [out/file1.js] "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.symbols b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.symbols index 27f9d9d811796..827f2e674e630 100644 --- a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.symbols +++ b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.symbols @@ -2,3 +2,11 @@ import * as b from './b.json'; >b : Symbol(b, Decl(file1.ts, 0, 6)) +=== tests/cases/compiler/b.json === +{ + "a": true, +>"a" : Symbol("a", Decl(b.json, 0, 1)) + + "b": "hello" +>"b" : Symbol("b", Decl(b.json, 1, 14)) +} diff --git a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.types b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.types index 999e912a291e7..20cc701340cac 100644 --- a/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.types +++ b/tests/baselines/reference/requireOfJsonFileWithModuleEmitNone.types @@ -1,4 +1,16 @@ === tests/cases/compiler/file1.ts === import * as b from './b.json'; ->b : any +>b : { a: boolean; b: string; } +=== tests/cases/compiler/b.json === +{ +>{ "a": true, "b": "hello"} : { a: boolean; b: string; } + + "a": true, +>"a" : boolean +>true : true + + "b": "hello" +>"b" : string +>"hello" : "hello" +} diff --git a/tests/baselines/reference/requireOfJsonFile_PathMapping.trace.json b/tests/baselines/reference/requireOfJsonFile_PathMapping.trace.json index a8e76904b715d..e13cc91a3da29 100644 --- a/tests/baselines/reference/requireOfJsonFile_PathMapping.trace.json +++ b/tests/baselines/reference/requireOfJsonFile_PathMapping.trace.json @@ -9,6 +9,8 @@ "File '/node_modules/foo/bar/foobar.json.ts' does not exist.", "File '/node_modules/foo/bar/foobar.json.tsx' does not exist.", "File '/node_modules/foo/bar/foobar.json.d.ts' does not exist.", + "File name '/node_modules/foo/bar/foobar.json' has a '.json' extension - stripping it.", + "File '/node_modules/foo/bar/foobar.json.d.ts' does not exist.", "Directory '/node_modules/foo/bar/foobar.json' does not exist, skipping all lookups in it.", "Trying substitution 'src/types', candidate module location: 'src/types'.", "Loading module as file / folder, candidate module location '/src/types', target file type 'TypeScript'.", @@ -17,7 +19,10 @@ "File '/node_modules/foo/bar/foobar.json.ts' does not exist.", "File '/node_modules/foo/bar/foobar.json.tsx' does not exist.", "File '/node_modules/foo/bar/foobar.json.d.ts' does not exist.", + "File name '/node_modules/foo/bar/foobar.json' has a '.json' extension - stripping it.", + "File '/node_modules/foo/bar/foobar.json.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", + "File name '/node_modules/@types/foo/bar/foobar.json' has a '.json' extension - stripping it.", "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.json'.", "'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.json'.", "Module name 'foo/bar/foobar.json', matched pattern '*'.", @@ -25,18 +30,7 @@ "Loading module as file / folder, candidate module location '/node_modules/foo/bar/foobar.json', target file type 'JavaScript'.", "File '/node_modules/foo/bar/foobar.json.js' does not exist.", "File '/node_modules/foo/bar/foobar.json.jsx' does not exist.", - "Directory '/node_modules/foo/bar/foobar.json' does not exist, skipping all lookups in it.", - "Trying substitution 'src/types', candidate module location: 'src/types'.", - "Loading module as file / folder, candidate module location '/src/types', target file type 'JavaScript'.", - "Loading module 'foo/bar/foobar.json' from 'node_modules' folder, target file type 'JavaScript'.", - "File '/node_modules/foo/package.json' does not exist according to earlier cached lookups.", - "File '/node_modules/foo/bar/foobar.json.js' does not exist.", - "File '/node_modules/foo/bar/foobar.json.jsx' does not exist.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.json'.", - "'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.json'.", - "Module name 'foo/bar/foobar.json', matched pattern '*'.", - "Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.json'.", - "Loading module as file / folder, candidate module location '/node_modules/foo/bar/foobar.json', target file type 'Json'.", + "File name '/node_modules/foo/bar/foobar.json' has a '.json' extension - stripping it.", "File '/node_modules/foo/bar/foobar.json' exist - use it as a name resolution result.", "File '/node_modules/foo/package.json' does not exist according to earlier cached lookups.", "======== Module name 'foo/bar/foobar.json' was successfully resolved to '/node_modules/foo/bar/foobar.json'. ========" diff --git a/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js index 1a445f232047e..d190e968fc9cc 100644 --- a/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js +++ b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js @@ -54,9 +54,6 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg2/package ======== Resolving module './const.cjs' from '/user/username/projects/myproject/packages/pkg2/index.ts'. ======== Module resolution kind is not specified, using 'Node12'. Loading module as file / folder, candidate module location '/user/username/projects/myproject/packages/pkg2/const.cjs', target file type 'TypeScript'. -File '/user/username/projects/myproject/packages/pkg2/const.cjs.ts' does not exist. -File '/user/username/projects/myproject/packages/pkg2/const.cjs.tsx' does not exist. -File '/user/username/projects/myproject/packages/pkg2/const.cjs.d.ts' does not exist. File name '/user/username/projects/myproject/packages/pkg2/const.cjs' has a '.cjs' extension - stripping it. File '/user/username/projects/myproject/packages/pkg2/const.cts' exist - use it as a name resolution result. ======== Module name './const.cjs' was successfully resolved to '/user/username/projects/myproject/packages/pkg2/const.cts'. ======== @@ -71,23 +68,18 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg1/package 'package.json' does not have a 'typesVersions' field. ======== Resolving module 'pkg2' from '/user/username/projects/myproject/packages/pkg1/index.ts'. ======== Module resolution kind is not specified, using 'Node12'. +File '/user/username/projects/myproject/packages/pkg1/package.json' exists according to earlier cached lookups. Loading module 'pkg2' from 'node_modules' folder, target file type 'TypeScript'. Directory '/user/username/projects/myproject/packages/pkg1/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/projects/myproject/packages/node_modules' does not exist, skipping all lookups in it. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg2/package.json'. 'package.json' does not have a 'typesVersions' field. -File '/user/username/projects/myproject/node_modules/pkg2.ts' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2.tsx' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2.d.ts' does not exist. 'package.json' does not have a 'typings' field. 'package.json' does not have a 'types' field. 'package.json' has 'main' field 'build/index.js' that references '/user/username/projects/myproject/node_modules/pkg2/build/index.js'. File '/user/username/projects/myproject/node_modules/pkg2/build/index.js' exist - use it as a name resolution result. File '/user/username/projects/myproject/node_modules/pkg2/build/index.js' has an unsupported extension, so skipping it. Loading module as file / folder, candidate module location '/user/username/projects/myproject/node_modules/pkg2/build/index.js', target file type 'TypeScript'. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.ts' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.tsx' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.d.ts' does not exist. File name '/user/username/projects/myproject/node_modules/pkg2/build/index.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg2/build/index.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg2/build/index.tsx' does not exist. @@ -100,9 +92,6 @@ File '/user/username/projects/myproject/packages/pkg2/package.json' exists accor Using compiler options of project reference redirect '/user/username/projects/myproject/packages/pkg2/tsconfig.json'. Module resolution kind is not specified, using 'Node12'. Loading module as file / folder, candidate module location '/user/username/projects/myproject/packages/pkg2/build/const.cjs', target file type 'TypeScript'. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.ts' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.tsx' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.d.ts' does not exist. File name '/user/username/projects/myproject/packages/pkg2/build/const.cjs' has a '.cjs' extension - stripping it. File '/user/username/projects/myproject/packages/pkg2/build/const.cts' does not exist. File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - use it as a name resolution result. @@ -286,6 +275,7 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg1/package 'package.json' does not have a 'typesVersions' field. ======== Resolving module 'pkg2' from '/user/username/projects/myproject/packages/pkg1/index.ts'. ======== Module resolution kind is not specified, using 'Node12'. +File '/user/username/projects/myproject/packages/pkg1/package.json' exists according to earlier cached lookups. Loading module 'pkg2' from 'node_modules' folder, target file type 'TypeScript'. Directory '/user/username/projects/myproject/packages/pkg1/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/projects/myproject/packages/node_modules' does not exist, skipping all lookups in it. @@ -316,9 +306,6 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg2/package Using compiler options of project reference redirect '/user/username/projects/myproject/packages/pkg2/tsconfig.json'. Module resolution kind is not specified, using 'Node12'. Loading module as file / folder, candidate module location '/user/username/projects/myproject/packages/pkg2/build/const.cjs', target file type 'TypeScript'. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.ts' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.tsx' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.d.ts' does not exist. File name '/user/username/projects/myproject/packages/pkg2/build/const.cjs' has a '.cjs' extension - stripping it. File '/user/username/projects/myproject/packages/pkg2/build/const.cts' does not exist. File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - use it as a name resolution result. @@ -407,23 +394,18 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg1/package 'package.json' does not have a 'typesVersions' field. ======== Resolving module 'pkg2' from '/user/username/projects/myproject/packages/pkg1/index.ts'. ======== Module resolution kind is not specified, using 'Node12'. +File '/user/username/projects/myproject/packages/pkg1/package.json' exists according to earlier cached lookups. Loading module 'pkg2' from 'node_modules' folder, target file type 'TypeScript'. Directory '/user/username/projects/myproject/packages/pkg1/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/projects/myproject/packages/node_modules' does not exist, skipping all lookups in it. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg2/package.json'. 'package.json' does not have a 'typesVersions' field. -File '/user/username/projects/myproject/node_modules/pkg2.ts' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2.tsx' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2.d.ts' does not exist. 'package.json' does not have a 'typings' field. 'package.json' does not have a 'types' field. 'package.json' has 'main' field 'build/index.js' that references '/user/username/projects/myproject/node_modules/pkg2/build/index.js'. File '/user/username/projects/myproject/node_modules/pkg2/build/index.js' exist - use it as a name resolution result. File '/user/username/projects/myproject/node_modules/pkg2/build/index.js' has an unsupported extension, so skipping it. Loading module as file / folder, candidate module location '/user/username/projects/myproject/node_modules/pkg2/build/index.js', target file type 'TypeScript'. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.ts' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.tsx' does not exist. -File '/user/username/projects/myproject/node_modules/pkg2/build/index.js.d.ts' does not exist. File name '/user/username/projects/myproject/node_modules/pkg2/build/index.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg2/build/index.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg2/build/index.tsx' does not exist. @@ -437,9 +419,6 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg2/package Using compiler options of project reference redirect '/user/username/projects/myproject/packages/pkg2/tsconfig.json'. Module resolution kind is not specified, using 'Node12'. Loading module as file / folder, candidate module location '/user/username/projects/myproject/packages/pkg2/build/const.cjs', target file type 'TypeScript'. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.ts' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.tsx' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.d.ts' does not exist. File name '/user/username/projects/myproject/packages/pkg2/build/const.cjs' has a '.cjs' extension - stripping it. File '/user/username/projects/myproject/packages/pkg2/build/const.cts' does not exist. File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - use it as a name resolution result. @@ -524,6 +503,7 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg1/package 'package.json' does not have a 'typesVersions' field. ======== Resolving module 'pkg2' from '/user/username/projects/myproject/packages/pkg1/index.ts'. ======== Module resolution kind is not specified, using 'Node12'. +File '/user/username/projects/myproject/packages/pkg1/package.json' exists according to earlier cached lookups. Loading module 'pkg2' from 'node_modules' folder, target file type 'TypeScript'. Directory '/user/username/projects/myproject/packages/pkg1/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/projects/myproject/packages/node_modules' does not exist, skipping all lookups in it. @@ -554,9 +534,6 @@ Found 'package.json' at '/user/username/projects/myproject/packages/pkg2/package Using compiler options of project reference redirect '/user/username/projects/myproject/packages/pkg2/tsconfig.json'. Module resolution kind is not specified, using 'Node12'. Loading module as file / folder, candidate module location '/user/username/projects/myproject/packages/pkg2/build/const.cjs', target file type 'TypeScript'. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.ts' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.tsx' does not exist. -File '/user/username/projects/myproject/packages/pkg2/build/const.cjs.d.ts' does not exist. File name '/user/username/projects/myproject/packages/pkg2/build/const.cjs' has a '.cjs' extension - stripping it. File '/user/username/projects/myproject/packages/pkg2/build/const.cts' does not exist. File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - use it as a name resolution result. diff --git a/tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts b/tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts new file mode 100644 index 0000000000000..a19a7104ae127 --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeAllowJsPackageSelfName.ts @@ -0,0 +1,24 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: index.js +// esm format file +import * as self from "package"; +self; +// @filename: index.mjs +// esm format file +import * as self from "package"; +self; +// @filename: index.cjs +// esm format file +import * as self from "package"; +self; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} \ No newline at end of file diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts index 174300a96b045..113c1fdeb8a62 100644 --- a/tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts @@ -52,6 +52,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -64,11 +76,59 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; // @filename: index.cjs -// ESM format imports below should error +// ESM-format imports below should issue errors import * as m1 from "./index.js"; import * as m2 from "./index.mjs"; import * as m3 from "./index.cjs"; @@ -81,6 +141,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -93,6 +165,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -109,6 +229,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -121,6 +253,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts new file mode 100644 index 0000000000000..1020812d5aeb2 --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsConditionalPackageExports.ts @@ -0,0 +1,126 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: 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; +// @filename: index.mjs +// 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; +// @filename: index.cjs +// 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; +// @filename: node_modules/inner/index.d.ts +// 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; +// @filename: node_modules/inner/index.d.mts +// 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; +// @filename: node_modules/inner/index.d.cts +// 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; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "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/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts new file mode 100644 index 0000000000000..65e5721b0bb75 --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageExports.ts @@ -0,0 +1,92 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: 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; +// @filename: index.mjs +// 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; +// @filename: index.cjs +// 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; +// @filename: node_modules/inner/index.d.ts +// 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 }; +// @filename: node_modules/inner/index.d.mts +// 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 }; +// @filename: node_modules/inner/index.d.cts +// 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 }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts new file mode 100644 index 0000000000000..b9d6027f5d791 --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackageImports.ts @@ -0,0 +1,41 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: index.js +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: index.mjs +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: index.cjs +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: package.json +{ + "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/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts new file mode 100644 index 0000000000000..2691885690b1b --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExports.ts @@ -0,0 +1,69 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: index.js +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: index.mjs +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: index.cjs +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts new file mode 100644 index 0000000000000..6b96f3475834d --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsTrailers.ts @@ -0,0 +1,69 @@ +// @module: node12,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: index.js +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: index.mjs +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: index.cjs +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodeModules1.ts b/tests/cases/conformance/node/nodeModules1.ts index b0ba13a1e346e..698a6efec1e24 100644 --- a/tests/cases/conformance/node/nodeModules1.ts +++ b/tests/cases/conformance/node/nodeModules1.ts @@ -49,6 +49,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -61,6 +73,55 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); + // esm format file const x = 1; export {x}; @@ -78,6 +139,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -90,6 +163,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // cjs format file const x = 1; export {x}; @@ -106,6 +227,18 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -118,6 +251,54 @@ void m9; void m10; void m11; void m12; +void m13; +void m14; +void m15; +void m16; +void m17; +void m18; +void m19; +void m20; +void m21; +void m22; +void m23; + +// These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) +import m24 = require("./"); +import m25 = require("./index"); +import m26 = require("./subfolder"); +import m27 = require("./subfolder/"); +import m28 = require("./subfolder/index"); +import m29 = require("./subfolder2"); +import m30 = require("./subfolder2/"); +import m31 = require("./subfolder2/index"); +import m32 = require("./subfolder2/another"); +import m33 = require("./subfolder2/another/"); +import m34 = require("./subfolder2/another/index"); +void m24; +void m25; +void m26; +void m27; +void m28; +void m29; +void m30; +void m31; +void m32; +void m33; +void m34; + +// These shouldn't work - dynamic `import()` always uses the esm resolver, which does not have extension resolution +const _m35 = import("./"); +const _m36 = import("./index"); +const _m37 = import("./subfolder"); +const _m38 = import("./subfolder/"); +const _m39 = import("./subfolder/index"); +const _m40 = import("./subfolder2"); +const _m41 = import("./subfolder2/"); +const _m42 = import("./subfolder2/index"); +const _m43 = import("./subfolder2/another"); +const _m44 = import("./subfolder2/another/"); +const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export {x}; diff --git a/tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts b/tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts new file mode 100644 index 0000000000000..07bf9d9724c34 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesConditionalPackageExports.ts @@ -0,0 +1,124 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// 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; +// @filename: index.mts +// 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; +// @filename: index.cts +// 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; +// @filename: node_modules/inner/index.d.ts +// 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; +// @filename: node_modules/inner/index.d.mts +// 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; +// @filename: node_modules/inner/index.d.cts +// 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; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "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/tests/cases/conformance/node/nodeModulesPackageExports.ts b/tests/cases/conformance/node/nodeModulesPackageExports.ts new file mode 100644 index 0000000000000..897d01b07d73b --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesPackageExports.ts @@ -0,0 +1,90 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// 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; +// @filename: index.mts +// 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; +// @filename: index.cts +// 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; +// @filename: node_modules/inner/index.d.ts +// 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 }; +// @filename: node_modules/inner/index.d.mts +// 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 }; +// @filename: node_modules/inner/index.d.cts +// 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 }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodeModulesPackageImports.ts b/tests/cases/conformance/node/nodeModulesPackageImports.ts new file mode 100644 index 0000000000000..cccf930098ec7 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesPackageImports.ts @@ -0,0 +1,38 @@ +// @module: node12,nodenext +// @declaration: true +// @filename: index.ts +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: index.mts +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: index.cts +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; +// @filename: package.json +{ + "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/tests/cases/conformance/node/nodeModulesPackagePatternExports.ts b/tests/cases/conformance/node/nodeModulesPackagePatternExports.ts new file mode 100644 index 0000000000000..e22e497a94207 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesPackagePatternExports.ts @@ -0,0 +1,67 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: index.mts +// esm format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: index.cts +// cjs format file +import * as cjsi from "inner/cjs/index"; +import * as mjsi from "inner/mjs/index"; +import * as typei from "inner/js/index"; +cjsi; +mjsi; +typei; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./mjs/*": "./*.mjs", + "./js/*": "./*.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts b/tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts new file mode 100644 index 0000000000000..3abe36e0d691e --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesPackagePatternExportsTrailers.ts @@ -0,0 +1,67 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: index.mts +// esm format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: index.cts +// cjs format file +import * as cjsi from "inner/cjs/index.cjs"; +import * as mjsi from "inner/mjs/index.mjs"; +import * as typei from "inner/js/index.js"; +cjsi; +mjsi; +typei; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/index.cjs"; +import * as mjs from "inner/mjs/index.mjs"; +import * as type from "inner/js/index.js"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*.cjs": "./*.cjs", + "./mjs/*.mjs": "./*.mjs", + "./js/*.js": "./*.js" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodePackageSelfName.ts b/tests/cases/conformance/node/nodePackageSelfName.ts new file mode 100644 index 0000000000000..099d9c424e13e --- /dev/null +++ b/tests/cases/conformance/node/nodePackageSelfName.ts @@ -0,0 +1,21 @@ +// @module: node12,nodenext +// @declaration: true +// @filename: index.ts +// esm format file +import * as self from "package"; +self; +// @filename: index.mts +// esm format file +import * as self from "package"; +self; +// @filename: index.cts +// esm format file +import * as self from "package"; +self; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.js" +} \ No newline at end of file From c21cb4821cf664bb44a889725fa6bf22036198f0 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 15 Sep 2021 14:34:35 -0700 Subject: [PATCH 02/12] TypesVersions support in export/import map conditions --- src/compiler/moduleNameResolver.ts | 21 +++- ...pesVersionPackageExports(module=node12).js | 107 ++++++++++++++++++ ...rsionPackageExports(module=node12).symbols | 57 ++++++++++ ...VersionPackageExports(module=node12).types | 63 +++++++++++ ...sVersionPackageExports(module=nodenext).js | 107 ++++++++++++++++++ ...ionPackageExports(module=nodenext).symbols | 57 ++++++++++ ...rsionPackageExports(module=nodenext).types | 63 +++++++++++ .../nodeModulesTypesVersionPackageExports.ts | 53 +++++++++ 8 files changed, 526 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).types create mode 100644 tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 83355697485e3..fdfe10c7d70a1 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1412,6 +1412,15 @@ namespace ts { } } + function loadJSOrExactTSFileName(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined { + if ((extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) && fileExtensionIsOneOf(candidate, [Extension.Dts, Extension.Dcts, Extension.Dmts])) { + const result = tryFile(candidate, onlyRecordFailures, state); + return result !== undefined ? { path: candidate, ext: forEach([Extension.Dts, Extension.Dcts, Extension.Dmts], e => fileExtensionIs(candidate, e) ? e : undefined)! } : undefined; + } + + return loadModuleFromFileNoImplicitExtensions(extensions, candidate, onlyRecordFailures, state); + } + /** Try to return an existing file that adds one of the `extensions` to `candidate`. */ function tryAddingExtensions(candidate: string, extensions: Extensions, originalExtension: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined { if (!onlyRecordFailures) { @@ -1859,12 +1868,12 @@ namespace ts { } const finalPath = getNormalizedAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath, state.host.getCurrentDirectory?.()); - return toSearchResult(withPackageId(scope, loadModuleFromFileNoImplicitExtensions(extensions, finalPath, /*onlyRecordFailures*/ false, state))); + return toSearchResult(withPackageId(scope, loadJSOrExactTSFileName(extensions, finalPath, /*onlyRecordFailures*/ false, state))); } else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null if (!Array.isArray(target)) { for (const key of getOwnKeys(target as MapLike)) { - if (key === "default" || state.conditions.indexOf(key) >= 0) { + if (key === "default" || state.conditions.indexOf(key) >= 0 || isApplicableVersionedTypesKey(state.conditions, key)) { const subTarget = (target as MapLike)[key]; const result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern); if (result) { @@ -1900,6 +1909,14 @@ namespace ts { } return toSearchResult(/*value*/ undefined); } + + function isApplicableVersionedTypesKey(conditions: string[], key: string) { + if (conditions.indexOf("types") === -1) return false; // only apply versioned types conditions if the types condition is applied + if (!startsWith(key, "types@")) return false; + const range = VersionRange.tryParse(key.substring("types@".length)); + if (!range) return false; + return range.test(version); + } } function loadModuleFromNearestNodeModulesDirectory(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js new file mode 100644 index 0000000000000..22521556ef6be --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js @@ -0,0 +1,107 @@ +//// [tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts] //// + +//// [index.ts] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.mts] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.cts] +// cjs format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.d.ts] +// cjs format file +export const noConditionsApplied = true; +//// [index.d.mts] +// esm format file +export const importConditionApplied = true; +//// [index.d.cts] +// cjs format file +export const wrongConditionApplied = true; +//// [old-types.d.ts] +export const noVersionApplied = true; +//// [new-types.d.ts] +export const correctVersionApplied = true; +//// [future-types.d.ts] +export const futureVersionApplied = true; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + ".": { + "types@>=10000": "./future-types.d.ts", + "types@>=1": "./new-types.d.ts", + "types": "./old-types.d.ts", + "import": "./index.mjs", + "node": "./index.js" + }, + } +} + +//// [index.js] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; +//// [index.mjs] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const mod = __importStar(require("inner")); +mod.correctVersionApplied; +//// [index.mjs] +// esm format file +export const importConditionApplied = true; +//// [index.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.wrongConditionApplied = void 0; +// cjs format file +exports.wrongConditionApplied = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +export declare const importConditionApplied = true; +//// [index.d.cts] +export declare const wrongConditionApplied = true; diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..a9d7f0b89eedb --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).symbols @@ -0,0 +1,57 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.ts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.ts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.mts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.mts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.cts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.cts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const noConditionsApplied = true; +>noConditionsApplied : Symbol(noConditionsApplied, Decl(index.d.ts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const importConditionApplied = true; +>importConditionApplied : Symbol(importConditionApplied, Decl(index.d.mts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const wrongConditionApplied = true; +>wrongConditionApplied : Symbol(wrongConditionApplied, Decl(index.d.cts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/old-types.d.ts === +export const noVersionApplied = true; +>noVersionApplied : Symbol(noVersionApplied, Decl(old-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/new-types.d.ts === +export const correctVersionApplied = true; +>correctVersionApplied : Symbol(correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/future-types.d.ts === +export const futureVersionApplied = true; +>futureVersionApplied : Symbol(futureVersionApplied, Decl(future-types.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).types new file mode 100644 index 0000000000000..fe286fd667465 --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).types @@ -0,0 +1,63 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const noConditionsApplied = true; +>noConditionsApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const importConditionApplied = true; +>importConditionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const wrongConditionApplied = true; +>wrongConditionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/old-types.d.ts === +export const noVersionApplied = true; +>noVersionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/new-types.d.ts === +export const correctVersionApplied = true; +>correctVersionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/future-types.d.ts === +export const futureVersionApplied = true; +>futureVersionApplied : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..22521556ef6be --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js @@ -0,0 +1,107 @@ +//// [tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts] //// + +//// [index.ts] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.mts] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.cts] +// cjs format file +import * as mod from "inner"; +mod.correctVersionApplied; + +//// [index.d.ts] +// cjs format file +export const noConditionsApplied = true; +//// [index.d.mts] +// esm format file +export const importConditionApplied = true; +//// [index.d.cts] +// cjs format file +export const wrongConditionApplied = true; +//// [old-types.d.ts] +export const noVersionApplied = true; +//// [new-types.d.ts] +export const correctVersionApplied = true; +//// [future-types.d.ts] +export const futureVersionApplied = true; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + ".": { + "types@>=10000": "./future-types.d.ts", + "types@>=1": "./new-types.d.ts", + "types": "./old-types.d.ts", + "import": "./index.mjs", + "node": "./index.js" + }, + } +} + +//// [index.js] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; +//// [index.mjs] +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const mod = __importStar(require("inner")); +mod.correctVersionApplied; +//// [index.mjs] +// esm format file +export const importConditionApplied = true; +//// [index.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.wrongConditionApplied = void 0; +// cjs format file +exports.wrongConditionApplied = true; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [index.d.mts] +export declare const importConditionApplied = true; +//// [index.d.cts] +export declare const wrongConditionApplied = true; diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..a9d7f0b89eedb --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).symbols @@ -0,0 +1,57 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.ts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.ts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.mts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.mts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as mod from "inner"; +>mod : Symbol(mod, Decl(index.cts, 1, 6)) + +mod.correctVersionApplied; +>mod.correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) +>mod : Symbol(mod, Decl(index.cts, 1, 6)) +>correctVersionApplied : Symbol(mod.correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const noConditionsApplied = true; +>noConditionsApplied : Symbol(noConditionsApplied, Decl(index.d.ts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const importConditionApplied = true; +>importConditionApplied : Symbol(importConditionApplied, Decl(index.d.mts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const wrongConditionApplied = true; +>wrongConditionApplied : Symbol(wrongConditionApplied, Decl(index.d.cts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/old-types.d.ts === +export const noVersionApplied = true; +>noVersionApplied : Symbol(noVersionApplied, Decl(old-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/new-types.d.ts === +export const correctVersionApplied = true; +>correctVersionApplied : Symbol(correctVersionApplied, Decl(new-types.d.ts, 0, 12)) + +=== tests/cases/conformance/node/node_modules/inner/future-types.d.ts === +export const futureVersionApplied = true; +>futureVersionApplied : Symbol(futureVersionApplied, Decl(future-types.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..fe286fd667465 --- /dev/null +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).types @@ -0,0 +1,63 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as mod from "inner"; +>mod : typeof mod + +mod.correctVersionApplied; +>mod.correctVersionApplied : true +>mod : typeof mod +>correctVersionApplied : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const noConditionsApplied = true; +>noConditionsApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const importConditionApplied = true; +>importConditionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const wrongConditionApplied = true; +>wrongConditionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/old-types.d.ts === +export const noVersionApplied = true; +>noVersionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/new-types.d.ts === +export const correctVersionApplied = true; +>correctVersionApplied : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/future-types.d.ts === +export const futureVersionApplied = true; +>futureVersionApplied : true +>true : true + diff --git a/tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts b/tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts new file mode 100644 index 0000000000000..52cda091b3276 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesTypesVersionPackageExports.ts @@ -0,0 +1,53 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +// @filename: index.mts +// esm format file +import * as mod from "inner"; +mod.correctVersionApplied; + +// @filename: index.cts +// cjs format file +import * as mod from "inner"; +mod.correctVersionApplied; + +// @filename: node_modules/inner/index.d.ts +// cjs format file +export const noConditionsApplied = true; +// @filename: node_modules/inner/index.d.mts +// esm format file +export const importConditionApplied = true; +// @filename: node_modules/inner/index.d.cts +// cjs format file +export const wrongConditionApplied = true; +// @filename: node_modules/inner/old-types.d.ts +export const noVersionApplied = true; +// @filename: node_modules/inner/new-types.d.ts +export const correctVersionApplied = true; +// @filename: node_modules/inner/future-types.d.ts +export const futureVersionApplied = true; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + ".": { + "types@>=10000": "./future-types.d.ts", + "types@>=1": "./new-types.d.ts", + "types": "./old-types.d.ts", + "import": "./index.mjs", + "node": "./index.js" + }, + } +} \ No newline at end of file From 9294633ae63fca28e0bdf0b0fcff76bf02170d13 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 13:32:08 -0700 Subject: [PATCH 03/12] Fix import suggestion and autoimport default extensions under new resolution modes --- src/compiler/checker.ts | 2 +- src/compiler/moduleSpecifiers.ts | 33 +++++++++++++++---- src/harness/fourslashImpl.ts | 5 +-- .../moduleNodeNextImportFix.baseline | 24 ++++++++++++++ .../fourslash/moduleNodeNextAutoImport1.ts | 21 ++++++++++++ .../fourslash/moduleNodeNextAutoImport2.ts | 21 ++++++++++++ .../fourslash/moduleNodeNextAutoImport3.ts | 21 ++++++++++++ .../fourslash/moduleNodeNextImportFix.ts | 27 +++++++++++++++ 8 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/moduleNodeNextImportFix.baseline create mode 100644 tests/cases/fourslash/moduleNodeNextAutoImport1.ts create mode 100644 tests/cases/fourslash/moduleNodeNextAutoImport2.ts create mode 100644 tests/cases/fourslash/moduleNodeNextAutoImport3.ts create mode 100644 tests/cases/fourslash/moduleNodeNextImportFix.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8b6b086937c18..33b71ae94087b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3458,7 +3458,7 @@ namespace ts { * @see https://github.com/microsoft/TypeScript/issues/42151 */ if (moduleKind >= ModuleKind.ES2015) { - replacedImportSource += ".js"; + replacedImportSource += tsExtension === Extension.Mts ? ".mjs" : tsExtension === Extension.Cts ? ".cjs" : ".js"; } error(errorNode, diag, tsExtension, replacedImportSource); } diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 8bfffcffb82ef..95d50ee3ea8b6 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -11,7 +11,7 @@ namespace ts.moduleSpecifiers { readonly ending: Ending; } - function getPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }: UserPreferences, compilerOptions: CompilerOptions, importingSourceFile: SourceFile): Preferences { + function getPreferences(host: ModuleSpecifierResolutionHost, { importModuleSpecifierPreference, importModuleSpecifierEnding }: UserPreferences, compilerOptions: CompilerOptions, importingSourceFile: SourceFile): Preferences { return { relativePreference: importModuleSpecifierPreference === "relative" ? RelativePreference.Relative : @@ -25,21 +25,40 @@ namespace ts.moduleSpecifiers { case "minimal": return Ending.Minimal; case "index": return Ending.Index; case "js": return Ending.JsExtension; - default: return usesJsExtensionOnImports(importingSourceFile) ? Ending.JsExtension + default: return usesJsExtensionOnImports(importingSourceFile) || isFormatRequiringExtensions(compilerOptions, importingSourceFile.path, host) ? Ending.JsExtension : getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeJs ? Ending.Index : Ending.Minimal; } } } - function getPreferencesForUpdate(compilerOptions: CompilerOptions, oldImportSpecifier: string): Preferences { + function getPreferencesForUpdate(compilerOptions: CompilerOptions, oldImportSpecifier: string, importingSourceFileName: Path, host: ModuleSpecifierResolutionHost): Preferences { return { relativePreference: isExternalModuleNameRelative(oldImportSpecifier) ? RelativePreference.Relative : RelativePreference.NonRelative, - ending: hasJSFileExtension(oldImportSpecifier) ? + ending: hasJSFileExtension(oldImportSpecifier) || isFormatRequiringExtensions(compilerOptions, importingSourceFileName, host) ? Ending.JsExtension : getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeJs || endsWith(oldImportSpecifier, "index") ? Ending.Index : Ending.Minimal, }; } + function isFormatRequiringExtensions(compilerOptions: CompilerOptions, importingSourceFileName: Path, host: ModuleSpecifierResolutionHost) { + if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node12 + && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { + return false; + } + return getImpliedNodeFormatForFile(importingSourceFileName, /*packageJsonInfoCache*/ undefined, getModuleResolutionHost(host), compilerOptions) !== ModuleKind.CommonJS; + } + + function getModuleResolutionHost(host: ModuleSpecifierResolutionHost): ModuleResolutionHost { + return { + fileExists: host.fileExists, + readFile: Debug.checkDefined(host.readFile), + directoryExists: host.directoryExists, + getCurrentDirectory: host.getCurrentDirectory, + realpath: host.realpath, + useCaseSensitiveFileNames: host.useCaseSensitiveFileNames?.(), + }; + } + export function updateModuleSpecifier( compilerOptions: CompilerOptions, importingSourceFileName: Path, @@ -47,7 +66,7 @@ namespace ts.moduleSpecifiers { host: ModuleSpecifierResolutionHost, oldImportSpecifier: string, ): string | undefined { - const res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier), {}); + const res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {}); if (res === oldImportSpecifier) return undefined; return res; } @@ -60,7 +79,7 @@ namespace ts.moduleSpecifiers { toFileName: string, host: ModuleSpecifierResolutionHost, ): string { - return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences({}, compilerOptions, importingSourceFile), {}); + return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {}); } export function getNodeModulesPackageName( @@ -175,7 +194,7 @@ namespace ts.moduleSpecifiers { userPreferences: UserPreferences, ): readonly string[] { const info = getInfo(importingSourceFile.path, host); - const preferences = getPreferences(userPreferences, compilerOptions, importingSourceFile); + const preferences = getPreferences(host, userPreferences, compilerOptions, importingSourceFile); const existingSpecifier = forEach(modulePaths, modulePath => forEach( host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)), reason => { diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 7993eb63d3c7c..9d3dbfb8a8075 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -637,7 +637,8 @@ namespace FourSlash { ts.forEachKey(this.inputFiles, fileName => { if (!ts.isAnySupportedFileExtension(fileName) || Harness.getConfigNameFromFileName(fileName) - || !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return; + || !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName)) + || ts.getBaseFileName(fileName) === "package.json") return; const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion); if (errors.length) { this.printErrorLog(/*expectErrors*/ false, errors); @@ -1928,7 +1929,7 @@ namespace FourSlash { } public baselineSyntacticAndSemanticDiagnostics() { - const files = this.getCompilerTestFiles(); + const files = ts.filter(this.getCompilerTestFiles(), f => !ts.endsWith(f.unitName, ".json")); const result = this.getSyntacticDiagnosticBaselineText(files) + Harness.IO.newLine() + Harness.IO.newLine() diff --git a/tests/baselines/reference/moduleNodeNextImportFix.baseline b/tests/baselines/reference/moduleNodeNextImportFix.baseline new file mode 100644 index 0000000000000..5f000f3f10fa1 --- /dev/null +++ b/tests/baselines/reference/moduleNodeNextImportFix.baseline @@ -0,0 +1,24 @@ +Syntactic Diagnostics for file '/tests/cases/fourslash/moduleNodeNextImportFix.ts': + + +==== /tests/cases/fourslash/src/index.mts (0 errors) ==== + import { util } from './deps.mts' + export function main() { + util() + } +==== /tests/cases/fourslash/src/deps.mts (0 errors) ==== + export function util() {} + +Semantic Diagnostics for file '/tests/cases/fourslash/moduleNodeNextImportFix.ts': +/tests/cases/fourslash/src/index.mts(1,22): error TS2691: An import path cannot end with a '.mts' extension. Consider importing './deps.mjs' instead. + + +==== /tests/cases/fourslash/src/index.mts (1 errors) ==== + import { util } from './deps.mts' + ~~~~~~~~~~~~ +!!! error TS2691: An import path cannot end with a '.mts' extension. Consider importing './deps.mjs' instead. + export function main() { + util() + } +==== /tests/cases/fourslash/src/deps.mts (0 errors) ==== + export function util() {} \ No newline at end of file diff --git a/tests/cases/fourslash/moduleNodeNextAutoImport1.ts b/tests/cases/fourslash/moduleNodeNextAutoImport1.ts new file mode 100644 index 0000000000000..1d951ae07cd58 --- /dev/null +++ b/tests/cases/fourslash/moduleNodeNextAutoImport1.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: /tsconfig.json +//// { "compilerOptions": { "module": "nodenext" } } + +// @Filename: /package.json +//// { "type": "module" } + +// @Filename: /mobx.d.ts +//// export declare function autorun(): void; + +// @Filename: /index.ts +//// autorun/**/ + +// @Filename: /utils.ts +//// import "./mobx.js"; + +goTo.marker(""); +verify.importFixAtPosition([`import { autorun } from "./mobx.js"; + +autorun`]); diff --git a/tests/cases/fourslash/moduleNodeNextAutoImport2.ts b/tests/cases/fourslash/moduleNodeNextAutoImport2.ts new file mode 100644 index 0000000000000..66346f8e88ab7 --- /dev/null +++ b/tests/cases/fourslash/moduleNodeNextAutoImport2.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: /tsconfig.json +//// { "compilerOptions": { "module": "nodenext" } } + +// @Filename: /package.json +//// { "type": "module" } + +// @Filename: /mobx.d.cts +//// export declare function autorun(): void; + +// @Filename: /index.ts +//// autorun/**/ + +// @Filename: /utils.ts +//// import "./mobx.cjs"; + +goTo.marker(""); +verify.importFixAtPosition([`import { autorun } from "./mobx.cjs"; + +autorun`]); diff --git a/tests/cases/fourslash/moduleNodeNextAutoImport3.ts b/tests/cases/fourslash/moduleNodeNextAutoImport3.ts new file mode 100644 index 0000000000000..cf092bdc093d9 --- /dev/null +++ b/tests/cases/fourslash/moduleNodeNextAutoImport3.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: /tsconfig.json +//// { "compilerOptions": { "module": "nodenext" } } + +// @Filename: /package.json +//// { "type": "module" } + +// @Filename: /mobx.d.mts +//// export declare function autorun(): void; + +// @Filename: /index.ts +//// autorun/**/ + +// @Filename: /utils.ts +//// import "./mobx.mjs"; + +goTo.marker(""); +verify.importFixAtPosition([`import { autorun } from "./mobx.mjs"; + +autorun`]); diff --git a/tests/cases/fourslash/moduleNodeNextImportFix.ts b/tests/cases/fourslash/moduleNodeNextImportFix.ts new file mode 100644 index 0000000000000..74edf7daff314 --- /dev/null +++ b/tests/cases/fourslash/moduleNodeNextImportFix.ts @@ -0,0 +1,27 @@ +/// + +// @Filename: package.json +////{ +//// "type": "module" +////} +// @Filename: tsconfig.json +////{ +//// "compilerOptions": { +//// "outDir": "./dist", +//// "module": "node12", +//// "target": "esnext" +//// }, +//// "include": ["./src"] +////} +// @Filename: src/index.mts +////import { util } from /*import*/'./deps.mts' +////export function main() { +//// util() +////} +// @Filename: src/deps.mts +////export function util() {} + +verify.baselineSyntacticAndSemanticDiagnostics(); +goTo.marker("import"); +edit.replace(test.markers()[0].position, "'./deps.mts'".length, "'./deps.mjs'"); +verify.noErrors(); \ No newline at end of file From c7764530cc6f793aba227c7a933c95b8ecf33528 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 13:50:47 -0700 Subject: [PATCH 04/12] Add tests for import maps non-relative name lookup feature --- ...portResolutionIntoExport(module=node12).js | 66 +++++++++++++++++++ ...esolutionIntoExport(module=node12).symbols | 24 +++++++ ...tResolutionIntoExport(module=node12).types | 24 +++++++ ...rtResolutionIntoExport(module=nodenext).js | 66 +++++++++++++++++++ ...olutionIntoExport(module=nodenext).symbols | 24 +++++++ ...esolutionIntoExport(module=nodenext).types | 24 +++++++ ...esolutionNoCycle(module=node12).errors.txt | 33 ++++++++++ ...sImportResolutionNoCycle(module=node12).js | 66 +++++++++++++++++++ ...rtResolutionNoCycle(module=node12).symbols | 24 +++++++ ...portResolutionNoCycle(module=node12).types | 24 +++++++ ...olutionNoCycle(module=nodenext).errors.txt | 33 ++++++++++ ...mportResolutionNoCycle(module=nodenext).js | 66 +++++++++++++++++++ ...ResolutionNoCycle(module=nodenext).symbols | 24 +++++++ ...rtResolutionNoCycle(module=nodenext).types | 24 +++++++ .../nodeModulesImportResolutionIntoExport.ts | 24 +++++++ .../nodeModulesImportResolutionNoCycle.ts | 24 +++++++ 16 files changed, 570 insertions(+) create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).types create mode 100644 tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts create mode 100644 tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js new file mode 100644 index 0000000000000..8ba8057d431c1 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts] //// + +//// [index.ts] +// esm format file +import * as type from "#type"; +type; +//// [index.mts] +// esm format file +import * as type from "#type"; +type; +//// [index.cts] +// esm format file +import * as type from "#type"; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.cjs", + "imports": { + "#type": "package" + } +} + +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const type = __importStar(require("#type")); +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).symbols b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).symbols new file mode 100644 index 0000000000000..1a0ad59fc81c0 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).types b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).types new file mode 100644 index 0000000000000..cb05ede987ec9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js new file mode 100644 index 0000000000000..8ba8057d431c1 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts] //// + +//// [index.ts] +// esm format file +import * as type from "#type"; +type; +//// [index.mts] +// esm format file +import * as type from "#type"; +type; +//// [index.cts] +// esm format file +import * as type from "#type"; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.cjs", + "imports": { + "#type": "package" + } +} + +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const type = __importStar(require("#type")); +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).symbols new file mode 100644 index 0000000000000..1a0ad59fc81c0 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).types b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).types new file mode 100644 index 0000000000000..cb05ede987ec9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : typeof type + +type; +>type : typeof type + diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).errors.txt b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).errors.txt new file mode 100644 index 0000000000000..c73a7a7885f63 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/node/index.cts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. + + +==== tests/cases/conformance/node/index.ts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/index.mts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "package", + "imports": { + "#type": "package" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).js b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).js new file mode 100644 index 0000000000000..ccdc459ab1a08 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts] //// + +//// [index.ts] +// esm format file +import * as type from "#type"; +type; +//// [index.mts] +// esm format file +import * as type from "#type"; +type; +//// [index.cts] +// esm format file +import * as type from "#type"; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "package", + "imports": { + "#type": "package" + } +} + +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const type = __importStar(require("#type")); +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).symbols b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).symbols new file mode 100644 index 0000000000000..1a0ad59fc81c0 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).types b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).types new file mode 100644 index 0000000000000..8bfd3afd06e6a --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=node12).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).errors.txt new file mode 100644 index 0000000000000..c73a7a7885f63 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/node/index.cts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module '#type' or its corresponding type declarations. + + +==== tests/cases/conformance/node/index.ts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/index.mts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/index.cts (1 errors) ==== + // esm format file + import * as type from "#type"; + ~~~~~~~ +!!! error TS2307: Cannot find module '#type' or its corresponding type declarations. + type; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": "package", + "imports": { + "#type": "package" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).js b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).js new file mode 100644 index 0000000000000..ccdc459ab1a08 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts] //// + +//// [index.ts] +// esm format file +import * as type from "#type"; +type; +//// [index.mts] +// esm format file +import * as type from "#type"; +type; +//// [index.cts] +// esm format file +import * as type from "#type"; +type; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": "package", + "imports": { + "#type": "package" + } +} + +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// esm format file +const type = __importStar(require("#type")); +type; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).symbols b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).symbols new file mode 100644 index 0000000000000..1a0ad59fc81c0 --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.mts, 1, 6)) + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : Symbol(type, Decl(index.cts, 1, 6)) + +type; +>type : Symbol(type, Decl(index.cts, 1, 6)) + diff --git a/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).types b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).types new file mode 100644 index 0000000000000..8bfd3afd06e6a --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportResolutionNoCycle(module=nodenext).types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + +=== tests/cases/conformance/node/index.cts === +// esm format file +import * as type from "#type"; +>type : any + +type; +>type : any + diff --git a/tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts b/tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts new file mode 100644 index 0000000000000..2a407b2bc680f --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportResolutionIntoExport.ts @@ -0,0 +1,24 @@ +// @module: node12,nodenext +// @declaration: true +// @filename: index.ts +// esm format file +import * as type from "#type"; +type; +// @filename: index.mts +// esm format file +import * as type from "#type"; +type; +// @filename: index.cts +// esm format file +import * as type from "#type"; +type; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": "./index.cjs", + "imports": { + "#type": "package" + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts b/tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts new file mode 100644 index 0000000000000..c0482c86ec292 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesImportResolutionNoCycle.ts @@ -0,0 +1,24 @@ +// @module: node12,nodenext +// @declaration: true +// @filename: index.ts +// esm format file +import * as type from "#type"; +type; +// @filename: index.mts +// esm format file +import * as type from "#type"; +type; +// @filename: index.cts +// esm format file +import * as type from "#type"; +type; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": "package", + "imports": { + "#type": "package" + } +} \ No newline at end of file From ae83938b3f14f68138b86e2e44ffd2ee0c9c2f1f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 14:10:39 -0700 Subject: [PATCH 05/12] Fix isDeclarationFileName for .d.mts and .d.cts --- src/compiler/parser.ts | 2 +- ...onditionalPackageExports(module=node12).js | 64 ------ ...ditionalPackageExports(module=nodenext).js | 64 ------ ...lesAllowJsPackageExports(module=node12).js | 52 ----- ...sAllowJsPackageExports(module=nodenext).js | 52 ----- ...wJsPackagePatternExports(module=node12).js | 52 ----- ...sPackagePatternExports(module=nodenext).js | 52 ----- ...gePatternExportsTrailers(module=node12).js | 52 ----- ...PatternExportsTrailers(module=nodenext).js | 52 ----- ...onditionalPackageExports(module=node12).js | 64 ------ ...ditionalPackageExports(module=nodenext).js | 64 ------ ...thPackageExports(module=node12).errors.txt | 116 ++++++++++ ...onEmitWithPackageExports(module=node12).js | 198 +++++++++++++++++ ...tWithPackageExports(module=node12).symbols | 201 +++++++++++++++++ ...mitWithPackageExports(module=node12).types | 204 ++++++++++++++++++ ...PackageExports(module=nodenext).errors.txt | 116 ++++++++++ ...EmitWithPackageExports(module=nodenext).js | 198 +++++++++++++++++ ...ithPackageExports(module=nodenext).symbols | 201 +++++++++++++++++ ...tWithPackageExports(module=nodenext).types | 204 ++++++++++++++++++ ...odeModulesPackageExports(module=node12).js | 52 ----- ...eModulesPackageExports(module=nodenext).js | 52 ----- ...lesPackagePatternExports(module=node12).js | 52 ----- ...sPackagePatternExports(module=nodenext).js | 52 ----- ...gePatternExportsTrailers(module=node12).js | 52 ----- ...PatternExportsTrailers(module=nodenext).js | 52 ----- ...pesVersionPackageExports(module=node12).js | 13 -- ...sVersionPackageExports(module=nodenext).js | 13 -- ...odulesDeclarationEmitWithPackageExports.ts | 93 ++++++++ 28 files changed, 1532 insertions(+), 907 deletions(-) create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).symbols create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).types create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types create mode 100644 tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dbe5394908d48..b99bbd9e0ec04 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -9164,7 +9164,7 @@ namespace ts { /** @internal */ export function isDeclarationFileName(fileName: string): boolean { - return fileExtensionIs(fileName, Extension.Dts); + return fileExtensionIsOneOf(fileName, [Extension.Dts, Extension.Dmts, Extension.Dcts]); } /*@internal*/ diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js index 140980f9624de..77df1469fbf62 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).js @@ -191,50 +191,6 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.mjs] -// 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; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/a")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/b")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; -const ts = __importStar(require("inner/types")); -exports.ts = ts; -exports.cjsSource = true; //// [index.d.ts] @@ -243,23 +199,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -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 declare const mjsSource = true; -//// [index.d.cts] -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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js index 140980f9624de..77df1469fbf62 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js @@ -191,50 +191,6 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.mjs] -// 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; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/a")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/b")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; -const ts = __importStar(require("inner/types")); -exports.ts = ts; -exports.cjsSource = true; //// [index.d.ts] @@ -243,23 +199,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -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 declare const mjsSource = true; -//// [index.d.cts] -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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js index aaac0fe09c108..dfb76ab777867 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).js @@ -151,44 +151,6 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.mjs] -// 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 }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; //// [index.d.ts] @@ -197,17 +159,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js index aaac0fe09c108..dfb76ab777867 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js @@ -151,44 +151,6 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.mjs] -// 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 }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; //// [index.d.ts] @@ -197,17 +159,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js index 65b383a70ec7c..b2ef85d6e5f97 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js index 65b383a70ec7c..b2ef85d6e5f97 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js index 825b1371c4a14..9627f89af2bb1 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=node12).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index.js")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index.cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index.mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index.js")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js index 825b1371c4a14..9627f89af2bb1 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index.js")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index.cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index.mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index.js")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js index 5154e5ea3e670..fa4dc561343ac 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js @@ -191,50 +191,6 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.mjs] -// 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; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/a")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/b")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; -const ts = __importStar(require("inner/types")); -exports.ts = ts; -exports.cjsSource = true; //// [index.d.ts] @@ -243,23 +199,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -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 declare const mjsSource = true; -//// [index.d.cts] -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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js index 5154e5ea3e670..fa4dc561343ac 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js @@ -191,50 +191,6 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; -//// [index.mjs] -// 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; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cjsSource = exports.ts = exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/a")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/b")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; -const ts = __importStar(require("inner/types")); -exports.ts = ts; -exports.cjsSource = true; //// [index.d.ts] @@ -243,23 +199,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -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 declare const mjsSource = true; -//// [index.d.cts] -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 declare const cjsSource = true; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt new file mode 100644 index 0000000000000..693d2dc59072a --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt @@ -0,0 +1,116 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/node/node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + export const a = cjs; + export const b = mjs; + export const c = type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + export const d = cjsi; + export const e = mjsi; + export const f = typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const cjsMain = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (1 errors) ==== + // esm format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const esm = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const cjsNonmain = true; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js new file mode 100644 index 0000000000000..92989a9705a3a --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js @@ -0,0 +1,198 @@ +//// [tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// cjs 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.ts] +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsMain = true; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const esm = true; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsNonmain = true; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.f = exports.e = exports.d = exports.c = exports.b = exports.a = void 0; +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +exports.a = cjs; +exports.b = mjs; +exports.c = type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +exports.d = cjsi; +exports.e = mjsi; +exports.f = 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; +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.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; +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] +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; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).symbols new file mode 100644 index 0000000000000..3af13052d296b --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).symbols @@ -0,0 +1,201 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +export const a = cjs; +>a : Symbol(type.a, Decl(index.ts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +export const b = mjs; +>b : Symbol(type.b, Decl(index.ts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +export const c = type; +>c : Symbol(type.c, Decl(index.ts, 6, 12)) +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +export const d = cjsi; +>d : Symbol(type.d, Decl(index.ts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +export const e = mjsi; +>e : Symbol(type.e, Decl(index.ts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +export const f = typei; +>f : Symbol(type.f, Decl(index.ts, 12, 12)) +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +export const a = cjs; +>a : Symbol(mjs.a, Decl(index.mts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +export const b = mjs; +>b : Symbol(mjs.b, Decl(index.mts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +export const c = type; +>c : Symbol(mjs.c, Decl(index.mts, 6, 12)) +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +export const d = cjsi; +>d : Symbol(mjs.d, Decl(index.mts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +export const e = mjsi; +>e : Symbol(mjs.e, Decl(index.mts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +export const f = typei; +>f : Symbol(mjs.f, Decl(index.mts, 12, 12)) +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +export const a = cjs; +>a : Symbol(cjs.a, Decl(index.cts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +export const b = mjs; +>b : Symbol(cjs.b, Decl(index.cts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +export const c = type; +>c : Symbol(cjs.c, Decl(index.cts, 6, 12)) +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +export const d = cjsi; +>d : Symbol(cjs.d, Decl(index.cts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +export const e = mjsi; +>e : Symbol(cjs.e, Decl(index.cts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +export const f = typei; +>f : Symbol(cjs.f, Decl(index.cts, 12, 12)) +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export const cjsMain = true; +>cjsMain : Symbol(type.cjsMain, Decl(index.d.ts, 7, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export const esm = true; +>esm : Symbol(mjs.esm, Decl(index.d.mts, 7, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export const cjsNonmain = true; +>cjsNonmain : Symbol(cjs.cjsNonmain, Decl(index.d.cts, 7, 12)) + diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).types new file mode 100644 index 0000000000000..5db63226d0814 --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const cjsMain = true; +>cjsMain : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const esm = true; +>esm : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const cjsNonmain = true; +>cjsNonmain : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt new file mode 100644 index 0000000000000..693d2dc59072a --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt @@ -0,0 +1,116 @@ +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/node/node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. + + +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/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; +==== tests/cases/conformance/node/index.cts (3 errors) ==== + // cjs format file + import * as cjs from "package/cjs"; + import * as mjs from "package/mjs"; + ~~~~~~~~~~~~~ +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "package"; + ~~~~~~~~~ +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + export const a = cjs; + export const b = mjs; + export const c = type; + import * as cjsi from "inner/cjs"; + import * as mjsi from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei from "inner"; + export const d = cjsi; + export const e = mjsi; + export const f = typei; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const cjsMain = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (1 errors) ==== + // esm format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const esm = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs"; + import * as mjs from "inner/mjs"; + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner"; + cjs; + ~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + mjs; + type; + export const cjsNonmain = true; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js new file mode 100644 index 0000000000000..92989a9705a3a --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js @@ -0,0 +1,198 @@ +//// [tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts] //// + +//// [index.ts] +// 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] +// 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] +// cjs 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.ts] +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsMain = true; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const esm = true; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsNonmain = true; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [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"; +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.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.f = exports.e = exports.d = exports.c = exports.b = exports.a = void 0; +// cjs format file +const cjs = __importStar(require("package/cjs")); +const mjs = __importStar(require("package/mjs")); +const type = __importStar(require("package")); +exports.a = cjs; +exports.b = mjs; +exports.c = type; +const cjsi = __importStar(require("inner/cjs")); +const mjsi = __importStar(require("inner/mjs")); +const typei = __importStar(require("inner")); +exports.d = cjsi; +exports.e = mjsi; +exports.f = 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; +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.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; +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] +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; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).symbols new file mode 100644 index 0000000000000..3af13052d296b --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).symbols @@ -0,0 +1,201 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.ts, 3, 6)) + +export const a = cjs; +>a : Symbol(type.a, Decl(index.ts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.ts, 1, 6)) + +export const b = mjs; +>b : Symbol(type.b, Decl(index.ts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.ts, 2, 6)) + +export const c = type; +>c : Symbol(type.c, Decl(index.ts, 6, 12)) +>type : Symbol(type, Decl(index.ts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +export const d = cjsi; +>d : Symbol(type.d, Decl(index.ts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.ts, 7, 6)) + +export const e = mjsi; +>e : Symbol(type.e, Decl(index.ts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.ts, 8, 6)) + +export const f = typei; +>f : Symbol(type.f, Decl(index.ts, 12, 12)) +>typei : Symbol(typei, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.mts, 3, 6)) + +export const a = cjs; +>a : Symbol(mjs.a, Decl(index.mts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.mts, 1, 6)) + +export const b = mjs; +>b : Symbol(mjs.b, Decl(index.mts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.mts, 2, 6)) + +export const c = type; +>c : Symbol(mjs.c, Decl(index.mts, 6, 12)) +>type : Symbol(type, Decl(index.mts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +export const d = cjsi; +>d : Symbol(mjs.d, Decl(index.mts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.mts, 7, 6)) + +export const e = mjsi; +>e : Symbol(mjs.e, Decl(index.mts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.mts, 8, 6)) + +export const f = typei; +>f : Symbol(mjs.f, Decl(index.mts, 12, 12)) +>typei : Symbol(typei, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +import * as mjs from "package/mjs"; +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +import * as type from "package"; +>type : Symbol(type, Decl(index.cts, 3, 6)) + +export const a = cjs; +>a : Symbol(cjs.a, Decl(index.cts, 4, 12)) +>cjs : Symbol(cjs, Decl(index.cts, 1, 6)) + +export const b = mjs; +>b : Symbol(cjs.b, Decl(index.cts, 5, 12)) +>mjs : Symbol(mjs, Decl(index.cts, 2, 6)) + +export const c = type; +>c : Symbol(cjs.c, Decl(index.cts, 6, 12)) +>type : Symbol(type, Decl(index.cts, 3, 6)) + +import * as cjsi from "inner/cjs"; +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +import * as mjsi from "inner/mjs"; +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +import * as typei from "inner"; +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +export const d = cjsi; +>d : Symbol(cjs.d, Decl(index.cts, 10, 12)) +>cjsi : Symbol(cjsi, Decl(index.cts, 7, 6)) + +export const e = mjsi; +>e : Symbol(cjs.e, Decl(index.cts, 11, 12)) +>mjsi : Symbol(mjsi, Decl(index.cts, 8, 6)) + +export const f = typei; +>f : Symbol(cjs.f, Decl(index.cts, 12, 12)) +>typei : Symbol(typei, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export const cjsMain = true; +>cjsMain : Symbol(type.cjsMain, Decl(index.d.ts, 7, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export const esm = true; +>esm : Symbol(mjs.esm, Decl(index.d.mts, 7, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +cjs; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +mjs; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +type; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export const cjsNonmain = true; +>cjsNonmain : Symbol(cjs.cjsNonmain, Decl(index.d.cts, 7, 12)) + diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types new file mode 100644 index 0000000000000..5db63226d0814 --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjs from "package/cjs"; +>cjs : typeof cjs + +import * as mjs from "package/mjs"; +>mjs : typeof mjs + +import * as type from "package"; +>type : typeof type + +export const a = cjs; +>a : typeof cjs +>cjs : typeof cjs + +export const b = mjs; +>b : typeof mjs +>mjs : typeof mjs + +export const c = type; +>c : typeof type +>type : typeof type + +import * as cjsi from "inner/cjs"; +>cjsi : typeof cjsi + +import * as mjsi from "inner/mjs"; +>mjsi : typeof mjsi + +import * as typei from "inner"; +>typei : typeof typei + +export const d = cjsi; +>d : typeof cjsi +>cjsi : typeof cjsi + +export const e = mjsi; +>e : typeof mjsi +>mjsi : typeof mjsi + +export const f = typei; +>f : typeof typei +>typei : typeof typei + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const cjsMain = true; +>cjsMain : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const esm = true; +>esm : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs"; +>mjs : typeof mjs + +import * as type from "inner"; +>type : typeof type + +cjs; +>cjs : typeof cjs + +mjs; +>mjs : typeof mjs + +type; +>type : typeof type + +export const cjsNonmain = true; +>cjsNonmain : true +>true : true + diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js index 120273188d958..3aebb7f0fc7b4 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js @@ -151,44 +151,6 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.mjs] -// 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 }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; //// [index.d.ts] @@ -197,17 +159,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js index 120273188d958..3aebb7f0fc7b4 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js @@ -151,44 +151,6 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; -//// [index.mjs] -// 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 }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner")); -exports.type = type; //// [index.d.ts] @@ -197,17 +159,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs"; -import * as mjs from "inner/mjs"; -import * as type from "inner"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js index d7d5f415e1c9c..982cd292396a5 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js index d7d5f415e1c9c..982cd292396a5 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index"; -import * as mjs from "inner/mjs/index"; -import * as type from "inner/js/index"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js index b96800f1159b4..0e0b80d540422 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node12).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index.js")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index.cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index.mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index.js")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js index b96800f1159b4..0e0b80d540422 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).js @@ -110,44 +110,6 @@ const typei = __importStar(require("inner/js/index.js")); cjsi; mjsi; typei; -//// [index.mjs] -// esm format file -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.type = exports.mjs = exports.cjs = void 0; -// cjs format file -const cjs = __importStar(require("inner/cjs/index.cjs")); -exports.cjs = cjs; -const mjs = __importStar(require("inner/mjs/index.mjs")); -exports.mjs = mjs; -const type = __importStar(require("inner/js/index.js")); -exports.type = type; //// [index.d.ts] @@ -156,17 +118,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; -//// [index.d.cts] -import * as cjs from "inner/cjs/index.cjs"; -import * as mjs from "inner/mjs/index.mjs"; -import * as type from "inner/js/index.js"; -export { cjs }; -export { mjs }; -export { type }; diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js index 22521556ef6be..8cb62238370ee 100644 --- a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=node12).js @@ -84,15 +84,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); // cjs format file const mod = __importStar(require("inner")); mod.correctVersionApplied; -//// [index.mjs] -// esm format file -export const importConditionApplied = true; -//// [index.cjs] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.wrongConditionApplied = void 0; -// cjs format file -exports.wrongConditionApplied = true; //// [index.d.ts] @@ -101,7 +92,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -export declare const importConditionApplied = true; -//// [index.d.cts] -export declare const wrongConditionApplied = true; diff --git a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js index 22521556ef6be..8cb62238370ee 100644 --- a/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesTypesVersionPackageExports(module=nodenext).js @@ -84,15 +84,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); // cjs format file const mod = __importStar(require("inner")); mod.correctVersionApplied; -//// [index.mjs] -// esm format file -export const importConditionApplied = true; -//// [index.cjs] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.wrongConditionApplied = void 0; -// cjs format file -exports.wrongConditionApplied = true; //// [index.d.ts] @@ -101,7 +92,3 @@ export {}; export {}; //// [index.d.cts] export {}; -//// [index.d.mts] -export declare const importConditionApplied = true; -//// [index.d.cts] -export declare const wrongConditionApplied = true; diff --git a/tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts b/tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts new file mode 100644 index 0000000000000..2599ff429ff93 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesDeclarationEmitWithPackageExports.ts @@ -0,0 +1,93 @@ +// @module: node12,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// 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; +// @filename: index.mts +// 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; +// @filename: index.cts +// cjs 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; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsMain = true; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const esm = true; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs"; +import * as mjs from "inner/mjs"; +import * as type from "inner"; +cjs; +mjs; +type; +export const cjsNonmain = true; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} \ No newline at end of file From 8ab7517babc75fbdb9b7282f5ea5b0d356fc2fb8 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 14:59:25 -0700 Subject: [PATCH 06/12] Preserve new extensions when generating module specifiers --- src/compiler/moduleSpecifiers.ts | 3 +- ...DynamicImportWithPackageExports.errors.txt | 89 +++++++++++ ...tionEmitDynamicImportWithPackageExports.js | 147 ++++++++++++++++++ ...mitDynamicImportWithPackageExports.symbols | 108 +++++++++++++ ...nEmitDynamicImportWithPackageExports.types | 141 +++++++++++++++++ ...tionEmitDynamicImportWithPackageExports.ts | 72 +++++++++ 6 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.symbols create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types create mode 100644 tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 95d50ee3ea8b6..620e28c984baa 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -752,8 +752,9 @@ namespace ts.moduleSpecifiers { } function removeExtensionAndIndexPostFix(fileName: string, ending: Ending, options: CompilerOptions): string { - if (fileExtensionIs(fileName, Extension.Json)) return fileName; + if (fileExtensionIsOneOf(fileName, [Extension.Json, Extension.Mjs, Extension.Cjs])) return fileName; const noExtension = removeFileExtension(fileName); + if (fileExtensionIsOneOf(fileName, [Extension.Dmts, Extension.Mts, Extension.Dcts, Extension.Cts])) return noExtension + getJSExtensionForFile(fileName, options); switch (ending) { case Ending.Minimal: return removeSuffix(noExtension, "/index"); diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt new file mode 100644 index 0000000000000..ff4732909567d --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt @@ -0,0 +1,89 @@ +tests/cases/conformance/node/other2.cts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. +tests/cases/conformance/node/other2.cts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. +tests/cases/conformance/node/other2.mts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. +tests/cases/conformance/node/other2.mts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. +tests/cases/conformance/node/other2.ts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. +tests/cases/conformance/node/other2.ts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + export {}; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + export {}; +==== tests/cases/conformance/node/index.cts (0 errors) ==== + // cjs format file + export {}; +==== tests/cases/conformance/node/other.ts (0 errors) ==== + // esm format file + export const a = await import("package/cjs"); + export const b = await import("package/mjs"); + export const c = await import("package"); + export const f = await import("inner"); +==== tests/cases/conformance/node/other2.ts (2 errors) ==== + // esm format file + export const d = await import("inner/cjs"); + ~ +!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. + export const e = await import("inner/mjs"); + ~ +!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. +==== tests/cases/conformance/node/other.mts (0 errors) ==== + // esm format file + export const a = await import("package/cjs"); + export const b = await import("package/mjs"); + export const c = await import("package"); + export const f = await import("inner"); +==== tests/cases/conformance/node/other2.mts (2 errors) ==== + // esm format file + export const d = await import("inner/cjs"); + ~ +!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. + export const e = await import("inner/mjs"); + ~ +!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. +==== tests/cases/conformance/node/other.cts (0 errors) ==== + // cjs format file, no TLA + export const a = import("package/cjs"); + export const b = import("package/mjs"); + export const c = import("package"); + export const f = import("inner"); +==== tests/cases/conformance/node/other2.cts (2 errors) ==== + // cjs format file, no TLA + export const d = import("inner/cjs"); + ~ +!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. + export const e = import("inner/mjs"); + ~ +!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + export const cjsMain = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + export const esm = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + export const cjsNonmain = true; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js new file mode 100644 index 0000000000000..64cca2d68b045 --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js @@ -0,0 +1,147 @@ +//// [tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts] //// + +//// [index.ts] +// esm format file +export {}; +//// [index.mts] +// esm format file +export {}; +//// [index.cts] +// cjs format file +export {}; +//// [other.ts] +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +//// [other2.ts] +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +//// [other.mts] +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +//// [other2.mts] +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +//// [other.cts] +// cjs format file, no TLA +export const a = import("package/cjs"); +export const b = import("package/mjs"); +export const c = import("package"); +export const f = import("inner"); +//// [other2.cts] +// cjs format file, no TLA +export const d = import("inner/cjs"); +export const e = import("inner/mjs"); +//// [index.d.ts] +// cjs format file +export const cjsMain = true; +//// [index.d.mts] +// esm format file +export const esm = true; +//// [index.d.cts] +// cjs format file +export const cjsNonmain = true; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} + +//// [index.js] +export {}; +//// [index.mjs] +export {}; +//// [index.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [other.js] +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +//// [other2.js] +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +//// [other.mjs] +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +//// [other2.mjs] +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +//// [other.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.f = exports.c = exports.b = exports.a = void 0; +// cjs format file, no TLA +exports.a = import("package/cjs"); +exports.b = import("package/mjs"); +exports.c = import("package"); +exports.f = import("inner"); +//// [other2.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.e = exports.d = void 0; +// cjs format file, no TLA +exports.d = import("inner/cjs"); +exports.e = import("inner/mjs"); + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; +//// [other.d.ts] +export declare const a: typeof import("./index.cjs"); +export declare const b: typeof import("./index.mjs"); +export declare const c: typeof import("package"); +export declare const f: { + default: typeof import("inner"); + cjsMain: true; +}; +//// [other.d.mts] +export declare const a: typeof import("./index.cjs"); +export declare const b: typeof import("./index.mjs"); +export declare const c: typeof import("package"); +export declare const f: { + default: typeof import("inner"); + cjsMain: true; +}; +//// [other.d.cts] +export declare const a: Promise; +export declare const b: Promise; +export declare const c: Promise; +export declare const f: Promise<{ + default: typeof import("inner"); + cjsMain: true; +}>; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.symbols b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.symbols new file mode 100644 index 0000000000000..67841b1be5adf --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.symbols @@ -0,0 +1,108 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/index.mts === +// esm format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/index.cts === +// cjs format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/other.ts === +// esm format file +export const a = await import("package/cjs"); +>a : Symbol(a, Decl(other.ts, 1, 12)) +>"package/cjs" : Symbol("tests/cases/conformance/node/index", Decl(index.cts, 0, 0)) + +export const b = await import("package/mjs"); +>b : Symbol(b, Decl(other.ts, 2, 12)) +>"package/mjs" : Symbol("tests/cases/conformance/node/index", Decl(index.mts, 0, 0)) + +export const c = await import("package"); +>c : Symbol(c, Decl(other.ts, 3, 12)) +>"package" : Symbol("tests/cases/conformance/node/index", Decl(index.ts, 0, 0)) + +export const f = await import("inner"); +>f : Symbol(f, Decl(other.ts, 4, 12)) +>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.ts, 0, 0)) + +=== tests/cases/conformance/node/other2.ts === +// esm format file +export const d = await import("inner/cjs"); +>d : Symbol(d, Decl(other2.ts, 1, 12)) +>"inner/cjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.cts, 0, 0)) + +export const e = await import("inner/mjs"); +>e : Symbol(e, Decl(other2.ts, 2, 12)) +>"inner/mjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.mts, 0, 0)) + +=== tests/cases/conformance/node/other.mts === +// esm format file +export const a = await import("package/cjs"); +>a : Symbol(a, Decl(other.mts, 1, 12)) +>"package/cjs" : Symbol("tests/cases/conformance/node/index", Decl(index.cts, 0, 0)) + +export const b = await import("package/mjs"); +>b : Symbol(b, Decl(other.mts, 2, 12)) +>"package/mjs" : Symbol("tests/cases/conformance/node/index", Decl(index.mts, 0, 0)) + +export const c = await import("package"); +>c : Symbol(c, Decl(other.mts, 3, 12)) +>"package" : Symbol("tests/cases/conformance/node/index", Decl(index.ts, 0, 0)) + +export const f = await import("inner"); +>f : Symbol(f, Decl(other.mts, 4, 12)) +>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.ts, 0, 0)) + +=== tests/cases/conformance/node/other2.mts === +// esm format file +export const d = await import("inner/cjs"); +>d : Symbol(d, Decl(other2.mts, 1, 12)) +>"inner/cjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.cts, 0, 0)) + +export const e = await import("inner/mjs"); +>e : Symbol(e, Decl(other2.mts, 2, 12)) +>"inner/mjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.mts, 0, 0)) + +=== tests/cases/conformance/node/other.cts === +// cjs format file, no TLA +export const a = import("package/cjs"); +>a : Symbol(a, Decl(other.cts, 1, 12)) +>"package/cjs" : Symbol("tests/cases/conformance/node/index", Decl(index.cts, 0, 0)) + +export const b = import("package/mjs"); +>b : Symbol(b, Decl(other.cts, 2, 12)) +>"package/mjs" : Symbol("tests/cases/conformance/node/index", Decl(index.mts, 0, 0)) + +export const c = import("package"); +>c : Symbol(c, Decl(other.cts, 3, 12)) +>"package" : Symbol("tests/cases/conformance/node/index", Decl(index.ts, 0, 0)) + +export const f = import("inner"); +>f : Symbol(f, Decl(other.cts, 4, 12)) +>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.ts, 0, 0)) + +=== tests/cases/conformance/node/other2.cts === +// cjs format file, no TLA +export const d = import("inner/cjs"); +>d : Symbol(d, Decl(other2.cts, 1, 12)) +>"inner/cjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.cts, 0, 0)) + +export const e = import("inner/mjs"); +>e : Symbol(e, Decl(other2.cts, 2, 12)) +>"inner/mjs" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.d.mts, 0, 0)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const cjsMain = true; +>cjsMain : Symbol(cjsMain, Decl(index.d.ts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const esm = true; +>esm : Symbol(esm, Decl(index.d.mts, 1, 12)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const cjsNonmain = true; +>cjsNonmain : Symbol(cjsNonmain, Decl(index.d.cts, 1, 12)) + diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types new file mode 100644 index 0000000000000..5a8030b43bb26 --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.types @@ -0,0 +1,141 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/index.mts === +// esm format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/index.cts === +// cjs format file +No type information for this code.export {}; +No type information for this code.=== tests/cases/conformance/node/other.ts === +// esm format file +export const a = await import("package/cjs"); +>a : typeof import("tests/cases/conformance/node/index") +>await import("package/cjs") : typeof import("tests/cases/conformance/node/index") +>import("package/cjs") : Promise +>"package/cjs" : "package/cjs" + +export const b = await import("package/mjs"); +>b : typeof import("tests/cases/conformance/node/index") +>await import("package/mjs") : typeof import("tests/cases/conformance/node/index") +>import("package/mjs") : Promise +>"package/mjs" : "package/mjs" + +export const c = await import("package"); +>c : typeof import("tests/cases/conformance/node/index") +>await import("package") : typeof import("tests/cases/conformance/node/index") +>import("package") : Promise +>"package" : "package" + +export const f = await import("inner"); +>f : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; } +>await import("inner") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; } +>import("inner") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; }> +>"inner" : "inner" + +=== tests/cases/conformance/node/other2.ts === +// esm format file +export const d = await import("inner/cjs"); +>d : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; } +>await import("inner/cjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; } +>import("inner/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; }> +>"inner/cjs" : "inner/cjs" + +export const e = await import("inner/mjs"); +>e : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; } +>await import("inner/mjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; } +>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }> +>"inner/mjs" : "inner/mjs" + +=== tests/cases/conformance/node/other.mts === +// esm format file +export const a = await import("package/cjs"); +>a : typeof import("tests/cases/conformance/node/index") +>await import("package/cjs") : typeof import("tests/cases/conformance/node/index") +>import("package/cjs") : Promise +>"package/cjs" : "package/cjs" + +export const b = await import("package/mjs"); +>b : typeof import("tests/cases/conformance/node/index") +>await import("package/mjs") : typeof import("tests/cases/conformance/node/index") +>import("package/mjs") : Promise +>"package/mjs" : "package/mjs" + +export const c = await import("package"); +>c : typeof import("tests/cases/conformance/node/index") +>await import("package") : typeof import("tests/cases/conformance/node/index") +>import("package") : Promise +>"package" : "package" + +export const f = await import("inner"); +>f : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; } +>await import("inner") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; } +>import("inner") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; }> +>"inner" : "inner" + +=== tests/cases/conformance/node/other2.mts === +// esm format file +export const d = await import("inner/cjs"); +>d : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; } +>await import("inner/cjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; } +>import("inner/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; }> +>"inner/cjs" : "inner/cjs" + +export const e = await import("inner/mjs"); +>e : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; } +>await import("inner/mjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; } +>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }> +>"inner/mjs" : "inner/mjs" + +=== tests/cases/conformance/node/other.cts === +// cjs format file, no TLA +export const a = import("package/cjs"); +>a : Promise +>import("package/cjs") : Promise +>"package/cjs" : "package/cjs" + +export const b = import("package/mjs"); +>b : Promise +>import("package/mjs") : Promise +>"package/mjs" : "package/mjs" + +export const c = import("package"); +>c : Promise +>import("package") : Promise +>"package" : "package" + +export const f = import("inner"); +>f : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; }> +>import("inner") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsMain: true; }> +>"inner" : "inner" + +=== tests/cases/conformance/node/other2.cts === +// cjs format file, no TLA +export const d = import("inner/cjs"); +>d : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; }> +>import("inner/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); cjsNonmain: true; }> +>"inner/cjs" : "inner/cjs" + +export const e = import("inner/mjs"); +>e : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }> +>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }> +>"inner/mjs" : "inner/mjs" + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +export const cjsMain = true; +>cjsMain : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +export const esm = true; +>esm : true +>true : true + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +export const cjsNonmain = true; +>cjsNonmain : true +>true : true + diff --git a/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts b/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts new file mode 100644 index 0000000000000..23c8824780793 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts @@ -0,0 +1,72 @@ +// @module: nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// esm format file +export {}; +// @filename: index.mts +// esm format file +export {}; +// @filename: index.cts +// cjs format file +export {}; +// @filename: other.ts +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +// @filename: other2.ts +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +// @filename: other.mts +// esm format file +export const a = await import("package/cjs"); +export const b = await import("package/mjs"); +export const c = await import("package"); +export const f = await import("inner"); +// @filename: other2.mts +// esm format file +export const d = await import("inner/cjs"); +export const e = await import("inner/mjs"); +// @filename: other.cts +// cjs format file, no TLA +export const a = import("package/cjs"); +export const b = import("package/mjs"); +export const c = import("package"); +export const f = import("inner"); +// @filename: other2.cts +// cjs format file, no TLA +export const d = import("inner/cjs"); +export const e = import("inner/mjs"); +// @filename: node_modules/inner/index.d.ts +// cjs format file +export const cjsMain = true; +// @filename: node_modules/inner/index.d.mts +// esm format file +export const esm = true; +// @filename: node_modules/inner/index.d.cts +// cjs format file +export const cjsNonmain = true; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } +} \ No newline at end of file From 222ba00fd849c46ee7e57b29f63bf12553de41a4 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 17:56:04 -0700 Subject: [PATCH 07/12] Fix spurious implict any suggestion caused by file ordering bug and optimize import name format detection by relying on parents being set --- src/compiler/checker.ts | 4 +- src/compiler/program.ts | 60 ++--- src/compiler/utilities.ts | 2 +- src/harness/compilerImpl.ts | 6 +- src/harness/harnessIO.ts | 2 +- src/services/getEditsForFileRename.ts | 2 +- .../reference/nodeModules1(module=node12).js | 212 +++++++++--------- .../nodeModules1(module=nodenext).js | 212 +++++++++--------- ...alPackageExports(module=node12).errors.txt | 5 +- ...ionalPackageExports(module=node12).symbols | 10 +- ...itionalPackageExports(module=node12).types | 16 +- ...PackageExports(module=nodenext).errors.txt | 5 +- ...nalPackageExports(module=nodenext).symbols | 10 +- ...ionalPackageExports(module=nodenext).types | 16 +- ...alPackageExports(module=node12).errors.txt | 5 +- ...onditionalPackageExports(module=node12).js | 36 +-- ...ionalPackageExports(module=node12).symbols | 10 +- ...itionalPackageExports(module=node12).types | 16 +- ...PackageExports(module=nodenext).errors.txt | 5 +- ...ditionalPackageExports(module=nodenext).js | 36 +-- ...nalPackageExports(module=nodenext).symbols | 10 +- ...ionalPackageExports(module=nodenext).types | 16 +- ...DynamicImportWithPackageExports.errors.txt | 89 -------- ...tionEmitDynamicImportWithPackageExports.js | 151 ++++++++++++- ...onEmitWithPackageExports(module=node12).js | 34 +-- ...EmitWithPackageExports(module=nodenext).js | 34 +-- ...portResolutionIntoExport(module=node12).js | 20 +- ...rtResolutionIntoExport(module=nodenext).js | 20 +- ...odeModulesPackageExports(module=node12).js | 32 +-- ...eModulesPackageExports(module=nodenext).js | 32 +-- ...odeModulesPackageImports(module=node12).js | 20 +- ...eModulesPackageImports(module=nodenext).js | 20 +- ...t-correctly-with-cts-and-mts-extensions.js | 6 + ...tionEmitDynamicImportWithPackageExports.ts | 1 - ...lesFileEditStillAllowsResolutionsToWork.ts | 19 ++ 35 files changed, 624 insertions(+), 550 deletions(-) delete mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt create mode 100644 tests/cases/fourslash/nodeModulesFileEditStillAllowsResolutionsToWork.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33b71ae94087b..a57d2f6a1aa9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3381,7 +3381,9 @@ namespace ts { : (isImportCall(location) ? location : findAncestor(location, isImportCall))?.arguments[0] || (isImportDeclaration(location) ? location : findAncestor(location, isImportDeclaration))?.moduleSpecifier || (isExternalModuleImportEqualsDeclaration(location) ? location : findAncestor(location, isExternalModuleImportEqualsDeclaration))?.moduleReference.expression || - (isExportDeclaration(location) ? location : findAncestor(location, isExportDeclaration))?.moduleSpecifier; + (isExportDeclaration(location) ? location : findAncestor(location, isExportDeclaration))?.moduleSpecifier || + (isModuleDeclaration(location) ? location : location.parent && isModuleDeclaration(location.parent) && location.parent.name === location ? location.parent : undefined)?.name || + (isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal; const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : undefined)!; // TODO: GH#18217 const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule); const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5af5e3f1a9cca..bb4a0b7fd54a3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -530,52 +530,31 @@ namespace ts { } /* @internal */ - /** - * Are you sure you want to use this? If you have a bound and parent pointer'd sourcefile, as in the checker, getModeForUsageLocation is much more ergonomic - */ - export function getModeForResolutionAtIndex(file: { statements: readonly Statement[], imports: readonly StringLiteralLike[], moduleAugmentations: readonly (StringLiteral | Identifier)[], impliedNodeFormat?: ModuleKind.CommonJS | ModuleKind.ESNext}, index: number) { + interface SourceFileImportsList { + imports: SourceFile["imports"]; + moduleAugmentations: SourceFile["moduleAugmentations"]; + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }; + + /* @internal */ + export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number) { if (file.impliedNodeFormat === undefined) return undefined; - if (file.impliedNodeFormat !== ModuleKind.ESNext) { - const usage = getModuleNameStringLiteralAt(file, index); - if (usage.parent) { - // parent pointers are set - do the fast thing and just check if the parent is an import call expression - return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS; - } - // We can't rely on parent pointers being set - so instead we search for the usage in the top-level statements in the file, - // since that's the only place (module) import declarations and module augmentations (or definitions) are allowed. - // If the usage is anywhere else, by process of elimination, it must be an import call usage. - if (some(file.statements, s => - (isImportDeclaration(s) && s.moduleSpecifier === usage) || - (isImportEqualsDeclaration(s) && isExternalModuleReference(s.moduleReference) && skipParentheses(s.moduleReference.expression) === usage) || - (isModuleDeclaration(s) && s.name === usage) || - (isExportDeclaration(s) && s.moduleSpecifier === usage) - )) { - return ModuleKind.CommonJS; - } - return ModuleKind.ESNext; - } - // in an esnext format file, import require statements desugar to `require` calls, so should follow cjs resolution rules - const usage = getModuleNameStringLiteralAt(file, index); - if (usage.parent) { - // parent pointers are set - do the fast thing and just check if the parent is an import require statement - return isImportEqualsDeclaration(walkUpParenthesizedExpressions(usage.parent).parent) ? ModuleKind.CommonJS : ModuleKind.ESNext; - } - // parent pointers are unset - check to see if the usage is refered to in any of the top-level import require statements, as that's the only place they should be valid - if (some(file.statements, s => isImportEqualsDeclaration(s) && isExternalModuleReference(s.moduleReference) && skipParentheses(s.moduleReference.expression) === usage)) { - return ModuleKind.CommonJS; - } - return ModuleKind.ESNext; + // we ensure all elements of file.imports and file.moduleAugmentations have the relevant parent pointers set during program setup, + // so it's safe to use them even pre-bind + return getModeForUsageLocation(file, getModuleNameStringLiteralAt(file, index)); } /* @internal */ - export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike) { + export function getModeForUsageLocation(file: {impliedNodeFormat?: SourceFile["impliedNodeFormat"]}, usage: StringLiteralLike) { if (file.impliedNodeFormat === undefined) return undefined; if (file.impliedNodeFormat !== ModuleKind.ESNext) { // in cjs files, import call expressions are esm format, otherwise everything is cjs return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS; } // in esm files, import=require statements are cjs format, otherwise everything is esm - return isImportEqualsDeclaration(walkUpParenthesizedExpressions(usage.parent).parent) ? ModuleKind.CommonJS : ModuleKind.ESNext; + // imports are only parent'd up to their containing declaration/expression, so access farther parents with care + const exprParentParent = walkUpParenthesizedExpressions(usage.parent)?.parent; + return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? ModuleKind.CommonJS : ModuleKind.ESNext; } /* @internal */ @@ -1261,7 +1240,7 @@ namespace ts { function getRedirectReferenceForResolution(file: SourceFile) { const redirect = getResolvedProjectReferenceToRedirect(file.originalFileName); - if (redirect || !fileExtensionIs(file.originalFileName, Extension.Dts)) return redirect; + if (redirect || !fileExtensionIsOneOf(file.originalFileName, [Extension.Dts, Extension.Dcts, Extension.Dmts])) return redirect; // The originalFileName could not be actual source file name if file found was d.ts from referecned project // So in this case try to look up if this is output from referenced project, if it is use the redirected project in that case @@ -2432,6 +2411,7 @@ namespace ts { // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules // only through top - level external module names. Relative external module names are not permitted. if (moduleNameExpr && isStringLiteral(moduleNameExpr) && moduleNameExpr.text && (!inAmbientModule || !isExternalModuleNameRelative(moduleNameExpr.text))) { + setParentRecursive(node, /*incremental*/ false); // we need parent data on imports before the program is fully bound, so we ensure it's set here imports = append(imports, moduleNameExpr); if (!usesUriStyleNodeCoreModules && currentNodeModulesDepth === 0 && !file.isDeclarationFile) { usesUriStyleNodeCoreModules = startsWith(moduleNameExpr.text, "node:"); @@ -2440,6 +2420,7 @@ namespace ts { } else if (isModuleDeclaration(node)) { if (isAmbientModule(node) && (inAmbientModule || hasSyntacticModifier(node, ModifierFlags.Ambient) || file.isDeclarationFile)) { + (node.name as Mutable).parent = node; const nameText = getTextOfIdentifierOrLiteral(node.name); // Ambient module declarations can be interpreted as augmentations for some existing external modules. // This will happen in two cases: @@ -2476,13 +2457,16 @@ namespace ts { while (r.exec(file.text) !== null) { // eslint-disable-line no-null/no-null const node = getNodeAtPosition(file, r.lastIndex); if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true)) { + setParentRecursive(node, /*incremental*/ false); // we need parent data on imports before the program is fully bound, so we ensure it's set here imports = append(imports, node.arguments[0]); } // we have to check the argument list has length of 1. We will still have to process these even though we have parsing error. else if (isImportCall(node) && node.arguments.length === 1 && isStringLiteralLike(node.arguments[0])) { + setParentRecursive(node, /*incremental*/ false); // we need parent data on imports before the program is fully bound, so we ensure it's set here imports = append(imports, node.arguments[0]); } else if (isLiteralImportTypeNode(node)) { + setParentRecursive(node, /*incremental*/ false); // we need parent data on imports before the program is fully bound, so we ensure it's set here imports = append(imports, node.argument.literal); } } @@ -4123,7 +4107,7 @@ namespace ts { } /* @internal */ - export function getModuleNameStringLiteralAt({ imports, moduleAugmentations }: {imports: readonly StringLiteralLike[], moduleAugmentations: readonly (StringLiteral | Identifier)[]}, index: number): StringLiteralLike { + export function getModuleNameStringLiteralAt({ imports, moduleAugmentations }: SourceFileImportsList, index: number): StringLiteralLike { if (index < imports.length) return imports[index]; let augIndex = imports.length; for (const aug of moduleAugmentations) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4b31fefe6a0d9..0873aba6a933b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6879,7 +6879,7 @@ namespace ts { /** True if an extension is one of the supported TypeScript extensions. */ export function extensionIsTS(ext: Extension): boolean { - return ext === Extension.Ts || ext === Extension.Tsx || ext === Extension.Dts; + return ext === Extension.Ts || ext === Extension.Tsx || ext === Extension.Dts || ext === Extension.Cts || ext === Extension.Mts || ext === Extension.Dmts || ext === Extension.Dcts; } export function resolutionExtensionIsTSOrJson(ext: Extension) { diff --git a/src/harness/compilerImpl.ts b/src/harness/compilerImpl.ts index 9f7c1503ae8fb..40e3994b1c9bd 100644 --- a/src/harness/compilerImpl.ts +++ b/src/harness/compilerImpl.ts @@ -264,7 +264,9 @@ namespace compiler { const program = ts.createProgram(rootFiles || [], compilerOptions, host); const emitResult = program.emit(); const postErrors = ts.getPreEmitDiagnostics(program); - const errors = preErrors && (preErrors.length !== postErrors.length) ? [...postErrors, + const longerErrors = ts.length(preErrors) > postErrors.length ? preErrors : postErrors; + const shorterErrors = longerErrors === preErrors ? postErrors : preErrors; + const errors = preErrors && (preErrors.length !== postErrors.length) ? [...shorterErrors!, ts.addRelatedInfo( ts.createCompilerDiagnostic({ category: ts.DiagnosticCategory.Error, @@ -278,7 +280,7 @@ namespace compiler { key: "-1", message: `The excess diagnostics are:` }), - ...ts.filter(postErrors, p => !ts.some(preErrors, p2 => ts.compareDiagnostics(p, p2) === ts.Comparison.EqualTo)) + ...ts.filter(longerErrors!, p => !ts.some(shorterErrors, p2 => ts.compareDiagnostics(p, p2) === ts.Comparison.EqualTo)) ) ] : postErrors; return new CompilationResult(host, compilerOptions, program, emitResult, errors); diff --git a/src/harness/harnessIO.ts b/src/harness/harnessIO.ts index 3f817ebe8d6d6..450ed9f6174f6 100644 --- a/src/harness/harnessIO.ts +++ b/src/harness/harnessIO.ts @@ -505,7 +505,7 @@ namespace Harness { sourceFileName = outFile; } - const dTsFileName = ts.removeFileExtension(sourceFileName) + ts.Extension.Dts; + const dTsFileName = ts.removeFileExtension(sourceFileName) + ts.getDeclarationEmitExtensionForPath(sourceFileName); return result.dts.get(dTsFileName); } diff --git a/src/services/getEditsForFileRename.ts b/src/services/getEditsForFileRename.ts index a12283dddeea9..fa0749df0cecc 100644 --- a/src/services/getEditsForFileRename.ts +++ b/src/services/getEditsForFileRename.ts @@ -189,7 +189,7 @@ namespace ts { return newFileName === undefined ? { newFileName: oldFileName, updated: false } : { newFileName, updated: true }; } else { - const mode = getModeForResolutionAtIndex({ statements: importingSourceFile.statements, imports: [importLiteral], moduleAugmentations: [], impliedNodeFormat: importingSourceFile.impliedNodeFormat }, 0); + const mode = getModeForUsageLocation(importingSourceFile, importLiteral); const resolved = host.resolveModuleNames ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode) : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName, mode); diff --git a/tests/baselines/reference/nodeModules1(module=node12).js b/tests/baselines/reference/nodeModules1(module=node12).js index 0f3e1bb74d782..46163abc085d0 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).js +++ b/tests/baselines/reference/nodeModules1(module=node12).js @@ -371,33 +371,54 @@ exports.x = void 0; // cjs format file const x = 1; exports.x = x; -//// [index.js] -import { createRequire as _createRequire } from "module"; -const __require = _createRequire(import.meta.url); -import * as m1 from "./index.js"; -import * as m2 from "./index.mjs"; -import * as m3 from "./index.cjs"; -import * as m4 from "./subfolder/index.js"; -import * as m5 from "./subfolder/index.mjs"; -import * as m6 from "./subfolder/index.cjs"; -import * as m7 from "./subfolder2/index.js"; -import * as m8 from "./subfolder2/index.mjs"; -import * as m9 from "./subfolder2/index.cjs"; -import * as m10 from "./subfolder2/another/index.js"; -import * as m11 from "./subfolder2/another/index.mjs"; -import * as m12 from "./subfolder2/another/index.cjs"; -// The next ones shouldn't all work - esm format files have no index resolution or extension resolution -import * as m13 from "./"; -import * as m14 from "./index"; -import * as m15 from "./subfolder"; -import * as m16 from "./subfolder/"; -import * as m17 from "./subfolder/index"; -import * as m18 from "./subfolder2"; -import * as m19 from "./subfolder2/"; -import * as m20 from "./subfolder2/index"; -import * as m21 from "./subfolder2/another"; -import * as m22 from "./subfolder2/another/"; -import * as m23 from "./subfolder2/another/index"; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.x = void 0; +// ESM-format imports below should issue errors +const m1 = __importStar(require("./index.js")); +const m2 = __importStar(require("./index.mjs")); +const m3 = __importStar(require("./index.cjs")); +const m4 = __importStar(require("./subfolder/index.js")); +const m5 = __importStar(require("./subfolder/index.mjs")); +const m6 = __importStar(require("./subfolder/index.cjs")); +const m7 = __importStar(require("./subfolder2/index.js")); +const m8 = __importStar(require("./subfolder2/index.mjs")); +const m9 = __importStar(require("./subfolder2/index.cjs")); +const m10 = __importStar(require("./subfolder2/another/index.js")); +const m11 = __importStar(require("./subfolder2/another/index.mjs")); +const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -422,17 +443,17 @@ void m21; void m22; void m23; // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) -const m24 = __require("./"); -const m25 = __require("./index"); -const m26 = __require("./subfolder"); -const m27 = __require("./subfolder/"); -const m28 = __require("./subfolder/index"); -const m29 = __require("./subfolder2"); -const m30 = __require("./subfolder2/"); -const m31 = __require("./subfolder2/index"); -const m32 = __require("./subfolder2/another"); -const m33 = __require("./subfolder2/another/"); -const m34 = __require("./subfolder2/another/index"); +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); void m24; void m25; void m26; @@ -456,10 +477,10 @@ const _m42 = import("./subfolder2/index"); const _m43 = import("./subfolder2/another"); const _m44 = import("./subfolder2/another/"); const _m45 = import("./subfolder2/another/index"); -// esm format file +// cjs format file const x = 1; -export { x }; -//// [index.mjs] +exports.x = x; +//// [index.js] import { createRequire as _createRequire } from "module"; const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; @@ -474,7 +495,7 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; -// The next ones should all fail - esm format files have no index resolution or extension resolution +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution import * as m13 from "./"; import * as m14 from "./index"; import * as m15 from "./subfolder"; @@ -547,54 +568,33 @@ const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.x = void 0; -// ESM-format imports below should issue errors -const m1 = __importStar(require("./index.js")); -const m2 = __importStar(require("./index.mjs")); -const m3 = __importStar(require("./index.cjs")); -const m4 = __importStar(require("./subfolder/index.js")); -const m5 = __importStar(require("./subfolder/index.mjs")); -const m6 = __importStar(require("./subfolder/index.cjs")); -const m7 = __importStar(require("./subfolder2/index.js")); -const m8 = __importStar(require("./subfolder2/index.mjs")); -const m9 = __importStar(require("./subfolder2/index.cjs")); -const m10 = __importStar(require("./subfolder2/another/index.js")); -const m11 = __importStar(require("./subfolder2/another/index.mjs")); -const m12 = __importStar(require("./subfolder2/another/index.cjs")); -// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) -const m13 = __importStar(require("./")); -const m14 = __importStar(require("./index")); -const m15 = __importStar(require("./subfolder")); -const m16 = __importStar(require("./subfolder/")); -const m17 = __importStar(require("./subfolder/index")); -const m18 = __importStar(require("./subfolder2")); -const m19 = __importStar(require("./subfolder2/")); -const m20 = __importStar(require("./subfolder2/index")); -const m21 = __importStar(require("./subfolder2/another")); -const m22 = __importStar(require("./subfolder2/another/")); -const m23 = __importStar(require("./subfolder2/another/index")); +//// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); +import * as m1 from "./index.js"; +import * as m2 from "./index.mjs"; +import * as m3 from "./index.cjs"; +import * as m4 from "./subfolder/index.js"; +import * as m5 from "./subfolder/index.mjs"; +import * as m6 from "./subfolder/index.cjs"; +import * as m7 from "./subfolder2/index.js"; +import * as m8 from "./subfolder2/index.mjs"; +import * as m9 from "./subfolder2/index.cjs"; +import * as m10 from "./subfolder2/another/index.js"; +import * as m11 from "./subfolder2/another/index.mjs"; +import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -619,17 +619,17 @@ void m21; void m22; void m23; // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) -const m24 = require("./"); -const m25 = require("./index"); -const m26 = require("./subfolder"); -const m27 = require("./subfolder/"); -const m28 = require("./subfolder/index"); -const m29 = require("./subfolder2"); -const m30 = require("./subfolder2/"); -const m31 = require("./subfolder2/index"); -const m32 = require("./subfolder2/another"); -const m33 = require("./subfolder2/another/"); -const m34 = require("./subfolder2/another/index"); +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); void m24; void m25; void m26; @@ -653,9 +653,9 @@ const _m42 = import("./subfolder2/index"); const _m43 = import("./subfolder2/another"); const _m44 = import("./subfolder2/another/"); const _m45 = import("./subfolder2/another/index"); -// cjs format file +// esm format file const x = 1; -exports.x = x; +export { x }; //// [index.d.ts] @@ -685,12 +685,12 @@ export { x }; //// [index.d.cts] declare const x = 1; export { x }; -//// [index.d.ts] +//// [index.d.cts] declare const x = 1; export { x }; -//// [index.d.mts] +//// [index.d.ts] declare const x = 1; export { x }; -//// [index.d.cts] +//// [index.d.mts] declare const x = 1; export { x }; diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).js b/tests/baselines/reference/nodeModules1(module=nodenext).js index 0f3e1bb74d782..46163abc085d0 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).js +++ b/tests/baselines/reference/nodeModules1(module=nodenext).js @@ -371,33 +371,54 @@ exports.x = void 0; // cjs format file const x = 1; exports.x = x; -//// [index.js] -import { createRequire as _createRequire } from "module"; -const __require = _createRequire(import.meta.url); -import * as m1 from "./index.js"; -import * as m2 from "./index.mjs"; -import * as m3 from "./index.cjs"; -import * as m4 from "./subfolder/index.js"; -import * as m5 from "./subfolder/index.mjs"; -import * as m6 from "./subfolder/index.cjs"; -import * as m7 from "./subfolder2/index.js"; -import * as m8 from "./subfolder2/index.mjs"; -import * as m9 from "./subfolder2/index.cjs"; -import * as m10 from "./subfolder2/another/index.js"; -import * as m11 from "./subfolder2/another/index.mjs"; -import * as m12 from "./subfolder2/another/index.cjs"; -// The next ones shouldn't all work - esm format files have no index resolution or extension resolution -import * as m13 from "./"; -import * as m14 from "./index"; -import * as m15 from "./subfolder"; -import * as m16 from "./subfolder/"; -import * as m17 from "./subfolder/index"; -import * as m18 from "./subfolder2"; -import * as m19 from "./subfolder2/"; -import * as m20 from "./subfolder2/index"; -import * as m21 from "./subfolder2/another"; -import * as m22 from "./subfolder2/another/"; -import * as m23 from "./subfolder2/another/index"; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.x = void 0; +// ESM-format imports below should issue errors +const m1 = __importStar(require("./index.js")); +const m2 = __importStar(require("./index.mjs")); +const m3 = __importStar(require("./index.cjs")); +const m4 = __importStar(require("./subfolder/index.js")); +const m5 = __importStar(require("./subfolder/index.mjs")); +const m6 = __importStar(require("./subfolder/index.cjs")); +const m7 = __importStar(require("./subfolder2/index.js")); +const m8 = __importStar(require("./subfolder2/index.mjs")); +const m9 = __importStar(require("./subfolder2/index.cjs")); +const m10 = __importStar(require("./subfolder2/another/index.js")); +const m11 = __importStar(require("./subfolder2/another/index.mjs")); +const m12 = __importStar(require("./subfolder2/another/index.cjs")); +// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) +const m13 = __importStar(require("./")); +const m14 = __importStar(require("./index")); +const m15 = __importStar(require("./subfolder")); +const m16 = __importStar(require("./subfolder/")); +const m17 = __importStar(require("./subfolder/index")); +const m18 = __importStar(require("./subfolder2")); +const m19 = __importStar(require("./subfolder2/")); +const m20 = __importStar(require("./subfolder2/index")); +const m21 = __importStar(require("./subfolder2/another")); +const m22 = __importStar(require("./subfolder2/another/")); +const m23 = __importStar(require("./subfolder2/another/index")); void m1; void m2; void m3; @@ -422,17 +443,17 @@ void m21; void m22; void m23; // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) -const m24 = __require("./"); -const m25 = __require("./index"); -const m26 = __require("./subfolder"); -const m27 = __require("./subfolder/"); -const m28 = __require("./subfolder/index"); -const m29 = __require("./subfolder2"); -const m30 = __require("./subfolder2/"); -const m31 = __require("./subfolder2/index"); -const m32 = __require("./subfolder2/another"); -const m33 = __require("./subfolder2/another/"); -const m34 = __require("./subfolder2/another/index"); +const m24 = require("./"); +const m25 = require("./index"); +const m26 = require("./subfolder"); +const m27 = require("./subfolder/"); +const m28 = require("./subfolder/index"); +const m29 = require("./subfolder2"); +const m30 = require("./subfolder2/"); +const m31 = require("./subfolder2/index"); +const m32 = require("./subfolder2/another"); +const m33 = require("./subfolder2/another/"); +const m34 = require("./subfolder2/another/index"); void m24; void m25; void m26; @@ -456,10 +477,10 @@ const _m42 = import("./subfolder2/index"); const _m43 = import("./subfolder2/another"); const _m44 = import("./subfolder2/another/"); const _m45 = import("./subfolder2/another/index"); -// esm format file +// cjs format file const x = 1; -export { x }; -//// [index.mjs] +exports.x = x; +//// [index.js] import { createRequire as _createRequire } from "module"; const __require = _createRequire(import.meta.url); import * as m1 from "./index.js"; @@ -474,7 +495,7 @@ import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; import * as m11 from "./subfolder2/another/index.mjs"; import * as m12 from "./subfolder2/another/index.cjs"; -// The next ones should all fail - esm format files have no index resolution or extension resolution +// The next ones shouldn't all work - esm format files have no index resolution or extension resolution import * as m13 from "./"; import * as m14 from "./index"; import * as m15 from "./subfolder"; @@ -547,54 +568,33 @@ const _m45 = import("./subfolder2/another/index"); // esm format file const x = 1; export { x }; -//// [index.cjs] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.x = void 0; -// ESM-format imports below should issue errors -const m1 = __importStar(require("./index.js")); -const m2 = __importStar(require("./index.mjs")); -const m3 = __importStar(require("./index.cjs")); -const m4 = __importStar(require("./subfolder/index.js")); -const m5 = __importStar(require("./subfolder/index.mjs")); -const m6 = __importStar(require("./subfolder/index.cjs")); -const m7 = __importStar(require("./subfolder2/index.js")); -const m8 = __importStar(require("./subfolder2/index.mjs")); -const m9 = __importStar(require("./subfolder2/index.cjs")); -const m10 = __importStar(require("./subfolder2/another/index.js")); -const m11 = __importStar(require("./subfolder2/another/index.mjs")); -const m12 = __importStar(require("./subfolder2/another/index.cjs")); -// The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) -const m13 = __importStar(require("./")); -const m14 = __importStar(require("./index")); -const m15 = __importStar(require("./subfolder")); -const m16 = __importStar(require("./subfolder/")); -const m17 = __importStar(require("./subfolder/index")); -const m18 = __importStar(require("./subfolder2")); -const m19 = __importStar(require("./subfolder2/")); -const m20 = __importStar(require("./subfolder2/index")); -const m21 = __importStar(require("./subfolder2/another")); -const m22 = __importStar(require("./subfolder2/another/")); -const m23 = __importStar(require("./subfolder2/another/index")); +//// [index.mjs] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); +import * as m1 from "./index.js"; +import * as m2 from "./index.mjs"; +import * as m3 from "./index.cjs"; +import * as m4 from "./subfolder/index.js"; +import * as m5 from "./subfolder/index.mjs"; +import * as m6 from "./subfolder/index.cjs"; +import * as m7 from "./subfolder2/index.js"; +import * as m8 from "./subfolder2/index.mjs"; +import * as m9 from "./subfolder2/index.cjs"; +import * as m10 from "./subfolder2/another/index.js"; +import * as m11 from "./subfolder2/another/index.mjs"; +import * as m12 from "./subfolder2/another/index.cjs"; +// The next ones should all fail - esm format files have no index resolution or extension resolution +import * as m13 from "./"; +import * as m14 from "./index"; +import * as m15 from "./subfolder"; +import * as m16 from "./subfolder/"; +import * as m17 from "./subfolder/index"; +import * as m18 from "./subfolder2"; +import * as m19 from "./subfolder2/"; +import * as m20 from "./subfolder2/index"; +import * as m21 from "./subfolder2/another"; +import * as m22 from "./subfolder2/another/"; +import * as m23 from "./subfolder2/another/index"; void m1; void m2; void m3; @@ -619,17 +619,17 @@ void m21; void m22; void m23; // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) -const m24 = require("./"); -const m25 = require("./index"); -const m26 = require("./subfolder"); -const m27 = require("./subfolder/"); -const m28 = require("./subfolder/index"); -const m29 = require("./subfolder2"); -const m30 = require("./subfolder2/"); -const m31 = require("./subfolder2/index"); -const m32 = require("./subfolder2/another"); -const m33 = require("./subfolder2/another/"); -const m34 = require("./subfolder2/another/index"); +const m24 = __require("./"); +const m25 = __require("./index"); +const m26 = __require("./subfolder"); +const m27 = __require("./subfolder/"); +const m28 = __require("./subfolder/index"); +const m29 = __require("./subfolder2"); +const m30 = __require("./subfolder2/"); +const m31 = __require("./subfolder2/index"); +const m32 = __require("./subfolder2/another"); +const m33 = __require("./subfolder2/another/"); +const m34 = __require("./subfolder2/another/index"); void m24; void m25; void m26; @@ -653,9 +653,9 @@ const _m42 = import("./subfolder2/index"); const _m43 = import("./subfolder2/another"); const _m44 = import("./subfolder2/another/"); const _m45 = import("./subfolder2/another/index"); -// cjs format file +// esm format file const x = 1; -exports.x = x; +export { x }; //// [index.d.ts] @@ -685,12 +685,12 @@ export { x }; //// [index.d.cts] declare const x = 1; export { x }; -//// [index.d.ts] +//// [index.d.cts] declare const x = 1; export { x }; -//// [index.d.mts] +//// [index.d.ts] declare const x = 1; export { x }; -//// [index.d.cts] +//// [index.d.mts] declare const x = 1; export { x }; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt index dc5a10a070863..f889f40e378cb 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -68,9 +69,11 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error export { type }; export { ts }; export const implicitCjsSource = true; -==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (0 errors) ==== +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (1 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"; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols index b1b4757000e77..ce8944196c089 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).symbols @@ -198,19 +198,19 @@ import * as ts from "inner/types"; >ts : Symbol(ts, Decl(index.d.mts, 4, 6)) export { cjs }; ->cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) +>cjs : Symbol(mjs.cjs, Decl(index.d.mts, 5, 8)) export { mjs }; ->mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) +>mjs : Symbol(mjs.mjs, Decl(index.d.mts, 6, 8)) export { type }; ->type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) +>type : Symbol(mjs.type, Decl(index.d.mts, 7, 8)) export { ts }; ->ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) +>ts : Symbol(mjs.ts, Decl(index.d.mts, 8, 8)) export const mjsSource = true; ->mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsSource : Symbol(mjs.mjsSource, Decl(index.d.mts, 9, 12)) === tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === // cjs format file diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types index 4df6899a8a148..7b1fe309bb0dd 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).types @@ -187,28 +187,28 @@ export const implicitCjsSource = true; === tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === // esm format file import * as cjs from "inner/a"; ->cjs : typeof cjs +>cjs : any import * as mjs from "inner/b"; ->mjs : typeof cjs +>mjs : typeof mjs import * as type from "inner"; ->type : typeof cjs +>type : typeof mjs import * as ts from "inner/types"; ->ts : typeof cjs +>ts : typeof mjs export { cjs }; ->cjs : typeof cjs +>cjs : any export { mjs }; ->mjs : typeof cjs +>mjs : typeof mjs export { type }; ->type : typeof cjs +>type : typeof mjs export { ts }; ->ts : typeof cjs +>ts : typeof mjs export const mjsSource = true; >mjsSource : true diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt index dc5a10a070863..f889f40e378cb 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -68,9 +69,11 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error export { type }; export { ts }; export const implicitCjsSource = true; -==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (0 errors) ==== +==== tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts (1 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"; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols index b1b4757000e77..ce8944196c089 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).symbols @@ -198,19 +198,19 @@ import * as ts from "inner/types"; >ts : Symbol(ts, Decl(index.d.mts, 4, 6)) export { cjs }; ->cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) +>cjs : Symbol(mjs.cjs, Decl(index.d.mts, 5, 8)) export { mjs }; ->mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) +>mjs : Symbol(mjs.mjs, Decl(index.d.mts, 6, 8)) export { type }; ->type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) +>type : Symbol(mjs.type, Decl(index.d.mts, 7, 8)) export { ts }; ->ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) +>ts : Symbol(mjs.ts, Decl(index.d.mts, 8, 8)) export const mjsSource = true; ->mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsSource : Symbol(mjs.mjsSource, Decl(index.d.mts, 9, 12)) === tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts === // cjs format file diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types index 4df6899a8a148..7b1fe309bb0dd 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).types @@ -187,28 +187,28 @@ export const implicitCjsSource = true; === tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts === // esm format file import * as cjs from "inner/a"; ->cjs : typeof cjs +>cjs : any import * as mjs from "inner/b"; ->mjs : typeof cjs +>mjs : typeof mjs import * as type from "inner"; ->type : typeof cjs +>type : typeof mjs import * as ts from "inner/types"; ->ts : typeof cjs +>ts : typeof mjs export { cjs }; ->cjs : typeof cjs +>cjs : any export { mjs }; ->mjs : typeof cjs +>mjs : typeof mjs export { type }; ->type : typeof cjs +>type : typeof mjs export { ts }; ->ts : typeof cjs +>ts : typeof mjs export const mjsSource = true; >mjsSource : true diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt index f5a2bc0aae321..3878dce9543c1 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -68,9 +69,11 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: export { type }; export { ts }; export const implicitCjsSource = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (1 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"; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js index fa4dc561343ac..cd984941c2c9b 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).js @@ -122,22 +122,6 @@ 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"; @@ -191,11 +175,27 @@ 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/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols index 7f4d8533a44fd..88fdfed4eaaea 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).symbols @@ -198,19 +198,19 @@ import * as ts from "inner/types"; >ts : Symbol(ts, Decl(index.d.mts, 4, 6)) export { cjs }; ->cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) +>cjs : Symbol(mjs.cjs, Decl(index.d.mts, 5, 8)) export { mjs }; ->mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) +>mjs : Symbol(mjs.mjs, Decl(index.d.mts, 6, 8)) export { type }; ->type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) +>type : Symbol(mjs.type, Decl(index.d.mts, 7, 8)) export { ts }; ->ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) +>ts : Symbol(mjs.ts, Decl(index.d.mts, 8, 8)) export const mjsSource = true; ->mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsSource : Symbol(mjs.mjsSource, Decl(index.d.mts, 9, 12)) === tests/cases/conformance/node/node_modules/inner/index.d.cts === // cjs format file diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types index fe81bf80e7f83..d46ce7ffa461f 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).types @@ -187,28 +187,28 @@ export const implicitCjsSource = true; === tests/cases/conformance/node/node_modules/inner/index.d.mts === // esm format file import * as cjs from "inner/a"; ->cjs : typeof cjs +>cjs : any import * as mjs from "inner/b"; ->mjs : typeof cjs +>mjs : typeof mjs import * as type from "inner"; ->type : typeof cjs +>type : typeof mjs import * as ts from "inner/types"; ->ts : typeof cjs +>ts : typeof mjs export { cjs }; ->cjs : typeof cjs +>cjs : any export { mjs }; ->mjs : typeof cjs +>mjs : typeof mjs export { type }; ->type : typeof cjs +>type : typeof mjs export { ts }; ->ts : typeof cjs +>ts : typeof mjs export const mjsSource = true; >mjsSource : true diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt index f5a2bc0aae321..3878dce9543c1 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -68,9 +69,11 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: export { type }; export { ts }; export const implicitCjsSource = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (1 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"; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js index fa4dc561343ac..cd984941c2c9b 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).js @@ -122,22 +122,6 @@ 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"; @@ -191,11 +175,27 @@ 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/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols index 7f4d8533a44fd..88fdfed4eaaea 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).symbols @@ -198,19 +198,19 @@ import * as ts from "inner/types"; >ts : Symbol(ts, Decl(index.d.mts, 4, 6)) export { cjs }; ->cjs : Symbol(cjs.cjs, Decl(index.d.mts, 5, 8)) +>cjs : Symbol(mjs.cjs, Decl(index.d.mts, 5, 8)) export { mjs }; ->mjs : Symbol(cjs.mjs, Decl(index.d.mts, 6, 8)) +>mjs : Symbol(mjs.mjs, Decl(index.d.mts, 6, 8)) export { type }; ->type : Symbol(cjs.type, Decl(index.d.mts, 7, 8)) +>type : Symbol(mjs.type, Decl(index.d.mts, 7, 8)) export { ts }; ->ts : Symbol(cjs.ts, Decl(index.d.mts, 8, 8)) +>ts : Symbol(mjs.ts, Decl(index.d.mts, 8, 8)) export const mjsSource = true; ->mjsSource : Symbol(cjs.mjsSource, Decl(index.d.mts, 9, 12)) +>mjsSource : Symbol(mjs.mjsSource, Decl(index.d.mts, 9, 12)) === tests/cases/conformance/node/node_modules/inner/index.d.cts === // cjs format file diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types index fe81bf80e7f83..d46ce7ffa461f 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).types @@ -187,28 +187,28 @@ export const implicitCjsSource = true; === tests/cases/conformance/node/node_modules/inner/index.d.mts === // esm format file import * as cjs from "inner/a"; ->cjs : typeof cjs +>cjs : any import * as mjs from "inner/b"; ->mjs : typeof cjs +>mjs : typeof mjs import * as type from "inner"; ->type : typeof cjs +>type : typeof mjs import * as ts from "inner/types"; ->ts : typeof cjs +>ts : typeof mjs export { cjs }; ->cjs : typeof cjs +>cjs : any export { mjs }; ->mjs : typeof cjs +>mjs : typeof mjs export { type }; ->type : typeof cjs +>type : typeof mjs export { ts }; ->ts : typeof cjs +>ts : typeof mjs export const mjsSource = true; >mjsSource : true diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt deleted file mode 100644 index ff4732909567d..0000000000000 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt +++ /dev/null @@ -1,89 +0,0 @@ -tests/cases/conformance/node/other2.cts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. -tests/cases/conformance/node/other2.cts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. -tests/cases/conformance/node/other2.mts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. -tests/cases/conformance/node/other2.mts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. -tests/cases/conformance/node/other2.ts(2,14): error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. -tests/cases/conformance/node/other2.ts(3,14): error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. - - -==== tests/cases/conformance/node/index.ts (0 errors) ==== - // esm format file - export {}; -==== tests/cases/conformance/node/index.mts (0 errors) ==== - // esm format file - export {}; -==== tests/cases/conformance/node/index.cts (0 errors) ==== - // cjs format file - export {}; -==== tests/cases/conformance/node/other.ts (0 errors) ==== - // esm format file - export const a = await import("package/cjs"); - export const b = await import("package/mjs"); - export const c = await import("package"); - export const f = await import("inner"); -==== tests/cases/conformance/node/other2.ts (2 errors) ==== - // esm format file - export const d = await import("inner/cjs"); - ~ -!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. - export const e = await import("inner/mjs"); - ~ -!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. -==== tests/cases/conformance/node/other.mts (0 errors) ==== - // esm format file - export const a = await import("package/cjs"); - export const b = await import("package/mjs"); - export const c = await import("package"); - export const f = await import("inner"); -==== tests/cases/conformance/node/other2.mts (2 errors) ==== - // esm format file - export const d = await import("inner/cjs"); - ~ -!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. - export const e = await import("inner/mjs"); - ~ -!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. -==== tests/cases/conformance/node/other.cts (0 errors) ==== - // cjs format file, no TLA - export const a = import("package/cjs"); - export const b = import("package/mjs"); - export const c = import("package"); - export const f = import("inner"); -==== tests/cases/conformance/node/other2.cts (2 errors) ==== - // cjs format file, no TLA - export const d = import("inner/cjs"); - ~ -!!! error TS2742: The inferred type of 'd' cannot be named without a reference to './node_modules/inner/index.cjs'. This is likely not portable. A type annotation is necessary. - export const e = import("inner/mjs"); - ~ -!!! error TS2742: The inferred type of 'e' cannot be named without a reference to './node_modules/inner/index.mjs'. This is likely not portable. A type annotation is necessary. -==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ==== - // cjs format file - export const cjsMain = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== - // esm format file - export const esm = true; -==== tests/cases/conformance/node/node_modules/inner/index.d.cts (0 errors) ==== - // cjs format file - export const cjsNonmain = true; -==== tests/cases/conformance/node/package.json (0 errors) ==== - { - "name": "package", - "private": true, - "type": "module", - "exports": { - "./cjs": "./index.cjs", - "./mjs": "./index.mjs", - ".": "./index.js" - } - } -==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js index 64cca2d68b045..1448b4d594cc7 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js @@ -122,26 +122,165 @@ export {}; //// [index.d.cts] export {}; //// [other.d.ts] -export declare const a: typeof import("./index.cjs"); -export declare const b: typeof import("./index.mjs"); +export declare const a: typeof import("package/cjs"); +export declare const b: typeof import("package/mjs"); export declare const c: typeof import("package"); export declare const f: { default: typeof import("inner"); cjsMain: true; }; +//// [other2.d.ts] +export declare const d: { + default: typeof import("inner/cjs"); + cjsNonmain: true; +}; +export declare const e: { + default: typeof import("inner/mjs"); + esm: true; +}; //// [other.d.mts] -export declare const a: typeof import("./index.cjs"); -export declare const b: typeof import("./index.mjs"); +export declare const a: typeof import("package/cjs"); +export declare const b: typeof import("package/mjs"); export declare const c: typeof import("package"); export declare const f: { default: typeof import("inner"); cjsMain: true; }; +//// [other2.d.mts] +export declare const d: { + default: typeof import("inner/cjs"); + cjsNonmain: true; +}; +export declare const e: { + default: typeof import("inner/mjs"); + esm: true; +}; //// [other.d.cts] -export declare const a: Promise; -export declare const b: Promise; +export declare const a: Promise; +export declare const b: Promise; export declare const c: Promise; export declare const f: Promise<{ default: typeof import("inner"); cjsMain: true; }>; +//// [other2.d.cts] +export declare const d: Promise<{ + default: typeof import("inner/cjs"); + cjsNonmain: true; +}>; +export declare const e: Promise<{ + default: typeof import("inner/mjs"); + esm: true; +}>; + + +//// [DtsFileErrors] + + +tests/cases/conformance/node/other.d.cts(2,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/other.d.cts(3,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.d.ts (0 errors) ==== + export {}; + +==== tests/cases/conformance/node/index.d.mts (0 errors) ==== + export {}; + +==== tests/cases/conformance/node/index.d.cts (0 errors) ==== + export {}; + +==== tests/cases/conformance/node/other.d.ts (0 errors) ==== + export declare const a: typeof import("package/cjs"); + export declare const b: typeof import("package/mjs"); + export declare const c: typeof import("package"); + export declare const f: { + default: typeof import("inner"); + cjsMain: true; + }; + +==== tests/cases/conformance/node/other2.d.ts (0 errors) ==== + export declare const d: { + default: typeof import("inner/cjs"); + cjsNonmain: true; + }; + export declare const e: { + default: typeof import("inner/mjs"); + esm: true; + }; + +==== tests/cases/conformance/node/other.d.mts (0 errors) ==== + export declare const a: typeof import("package/cjs"); + export declare const b: typeof import("package/mjs"); + export declare const c: typeof import("package"); + export declare const f: { + default: typeof import("inner"); + cjsMain: true; + }; + +==== tests/cases/conformance/node/other2.d.mts (0 errors) ==== + export declare const d: { + default: typeof import("inner/cjs"); + cjsNonmain: true; + }; + export declare const e: { + default: typeof import("inner/mjs"); + esm: true; + }; + +==== tests/cases/conformance/node/other.d.cts (2 errors) ==== + export declare const a: Promise; + export declare const b: Promise; + ~~~~~~~~~~~~~ +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + export declare const c: Promise; + ~~~~~~~~~ +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + export declare const f: Promise<{ + default: typeof import("inner"); + cjsMain: true; + }>; + +==== tests/cases/conformance/node/other2.d.cts (1 errors) ==== + export declare const d: Promise<{ + default: typeof import("inner/cjs"); + cjsNonmain: true; + }>; + export declare const e: Promise<{ + default: typeof import("inner/mjs"); + ~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. + esm: true; + }>; + +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + export const cjsMain = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + export const esm = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + export const cjsNonmain = true; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/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/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js index 92989a9705a3a..7fdb02cf02112 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).js @@ -91,20 +91,6 @@ 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,9 +141,23 @@ 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.ts] +//// [index.d.mts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; @@ -170,7 +170,7 @@ 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.mts] +//// [index.d.cts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; @@ -183,7 +183,7 @@ 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] +//// [index.d.ts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js index 92989a9705a3a..7fdb02cf02112 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).js @@ -91,20 +91,6 @@ 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,9 +141,23 @@ 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.ts] +//// [index.d.mts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; @@ -170,7 +170,7 @@ 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.mts] +//// [index.d.cts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; @@ -183,7 +183,7 @@ 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] +//// [index.d.ts] import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; import * as type from "package"; diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js index 8ba8057d431c1..813d5046ccfbc 100644 --- a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=node12).js @@ -23,14 +23,6 @@ type; } } -//// [index.js] -// esm format file -import * as type from "#type"; -type; -//// [index.mjs] -// esm format file -import * as type from "#type"; -type; //// [index.cjs] "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { @@ -56,11 +48,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); // esm format file const type = __importStar(require("#type")); type; +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.d.cts] +export {}; //// [index.d.ts] export {}; //// [index.d.mts] export {}; -//// [index.d.cts] -export {}; diff --git a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js index 8ba8057d431c1..813d5046ccfbc 100644 --- a/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesImportResolutionIntoExport(module=nodenext).js @@ -23,14 +23,6 @@ type; } } -//// [index.js] -// esm format file -import * as type from "#type"; -type; -//// [index.mjs] -// esm format file -import * as type from "#type"; -type; //// [index.cjs] "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { @@ -56,11 +48,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); // esm format file const type = __importStar(require("#type")); type; +//// [index.js] +// esm format file +import * as type from "#type"; +type; +//// [index.mjs] +// esm format file +import * as type from "#type"; +type; +//// [index.d.cts] +export {}; //// [index.d.ts] export {}; //// [index.d.mts] export {}; -//// [index.d.cts] -export {}; diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).js b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js index 3aebb7f0fc7b4..28c25e10f9ef1 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=node12).js +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).js @@ -88,20 +88,6 @@ 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,11 +137,25 @@ 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/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js index 3aebb7f0fc7b4..28c25e10f9ef1 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).js @@ -88,20 +88,6 @@ 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,11 +137,25 @@ 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/tests/baselines/reference/nodeModulesPackageImports(module=node12).js b/tests/baselines/reference/nodeModulesPackageImports(module=node12).js index 11b7ef2f6a449..7fb8361dd0ac8 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=node12).js +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).js @@ -37,14 +37,6 @@ 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"; @@ -82,11 +74,19 @@ 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/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js index 11b7ef2f6a449..7fb8361dd0ac8 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).js @@ -37,14 +37,6 @@ 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"; @@ -82,11 +74,19 @@ 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/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js index 8ff9ac6650c27..d9e50d040c5ef 100644 --- a/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js +++ b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js @@ -126,16 +126,19 @@ Program options: {"outDir":"/user/username/projects/myproject/packages/pkg1/buil Program structureReused: Not Program files:: /a/lib/lib.es2020.full.d.ts +/user/username/projects/myproject/packages/pkg2/build/const.d.cts /user/username/projects/myproject/packages/pkg2/build/index.d.ts /user/username/projects/myproject/packages/pkg1/index.ts Semantic diagnostics in builder refreshed for:: /a/lib/lib.es2020.full.d.ts +/user/username/projects/myproject/packages/pkg2/build/const.d.cts /user/username/projects/myproject/packages/pkg2/build/index.d.ts /user/username/projects/myproject/packages/pkg1/index.ts Shape signatures in builder refreshed for:: /a/lib/lib.es2020.full.d.ts (used version) +/user/username/projects/myproject/packages/pkg2/build/const.d.cts (used version) /user/username/projects/myproject/packages/pkg2/build/index.d.ts (used version) /user/username/projects/myproject/packages/pkg1/index.ts (used version) @@ -327,6 +330,7 @@ Program options: {"outDir":"/user/username/projects/myproject/packages/pkg1/buil Program structureReused: Not Program files:: /a/lib/lib.es2020.full.d.ts +/user/username/projects/myproject/packages/pkg2/build/const.d.cts /user/username/projects/myproject/packages/pkg2/build/index.d.ts /user/username/projects/myproject/packages/pkg1/index.ts @@ -435,6 +439,7 @@ Program options: {"outDir":"/user/username/projects/myproject/packages/pkg1/buil Program structureReused: Not Program files:: /a/lib/lib.es2020.full.d.ts +/user/username/projects/myproject/packages/pkg2/build/const.d.cts /user/username/projects/myproject/packages/pkg2/build/index.d.ts /user/username/projects/myproject/packages/pkg1/index.ts @@ -555,6 +560,7 @@ Program options: {"outDir":"/user/username/projects/myproject/packages/pkg1/buil Program structureReused: Not Program files:: /a/lib/lib.es2020.full.d.ts +/user/username/projects/myproject/packages/pkg2/build/const.d.cts /user/username/projects/myproject/packages/pkg2/build/index.d.ts /user/username/projects/myproject/packages/pkg1/index.ts diff --git a/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts b/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts index 23c8824780793..3f8bae7ffc404 100644 --- a/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts +++ b/tests/cases/conformance/node/nodeModulesDeclarationEmitDynamicImportWithPackageExports.ts @@ -1,6 +1,5 @@ // @module: nodenext // @declaration: true -// @outDir: out // @filename: index.ts // esm format file export {}; diff --git a/tests/cases/fourslash/nodeModulesFileEditStillAllowsResolutionsToWork.ts b/tests/cases/fourslash/nodeModulesFileEditStillAllowsResolutionsToWork.ts new file mode 100644 index 0000000000000..d3c8153d93565 --- /dev/null +++ b/tests/cases/fourslash/nodeModulesFileEditStillAllowsResolutionsToWork.ts @@ -0,0 +1,19 @@ +/// + +// @Filename: /tsconfig.json +//// { "compilerOptions": { "module": "nodenext", "strict": true } } + +// @Filename: /package.json +//// { "type": "module", "imports": { "#foo": "./foo.cjs" } } + +// @Filename: /foo.cts +//// export const x = 1; + +// @Filename: /index.ts +//// import * as mod from "#foo"; +//// /**/ + +goTo.marker(""); +edit.insert("mod.x"); +verify.noErrors(); +verify.getSuggestionDiagnostics([]); From 408ef20e9c891c3ed40192ea6aada85fe49773a3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 20 Sep 2021 18:51:12 -0700 Subject: [PATCH 08/12] Fix a bunch of incremental bugs that dont repro under fourslash for some reason --- src/compiler/checker.ts | 5 +++-- src/compiler/parser.ts | 1 + src/compiler/program.ts | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a57d2f6a1aa9b..22e077cae2dc0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1831,7 +1831,7 @@ namespace ts { isInExternalModule = true; // falls through case SyntaxKind.ModuleDeclaration: - const moduleExports = getSymbolOfNode(location as SourceFile | ModuleDeclaration).exports || emptySymbols; + const moduleExports = getSymbolOfNode(location as SourceFile | ModuleDeclaration)?.exports || emptySymbols; if (location.kind === SyntaxKind.SourceFile || (isModuleDeclaration(location) && location.flags & NodeFlags.Ambient && !isGlobalScopeAugmentation(location))) { // It's an external module. First see if the module has an export default and if the local @@ -1874,7 +1874,7 @@ namespace ts { } break; case SyntaxKind.EnumDeclaration: - if (result = lookup(getSymbolOfNode(location)!.exports!, name, meaning & SymbolFlags.EnumMember)) { + if (result = lookup(getSymbolOfNode(location)?.exports || emptySymbols, name, meaning & SymbolFlags.EnumMember)) { break loop; } break; @@ -4610,6 +4610,7 @@ namespace ts { isSourceOfProjectReferenceRedirect: fileName => host.isSourceOfProjectReferenceRedirect(fileName), fileExists: fileName => host.fileExists(fileName), getFileIncludeReasons: () => host.getFileIncludeReasons(), + readFile: host.readFile ? (fileName => host.readFile!(fileName)) : undefined, } : undefined }, encounteredError: false, reportedDiagnostic: false, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b99bbd9e0ec04..b28a415cf626e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8624,6 +8624,7 @@ namespace ts { newText, aggressiveChecks ); + result.impliedNodeFormat = sourceFile.impliedNodeFormat; return result; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index bb4a0b7fd54a3..c4e76241abba8 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -998,6 +998,7 @@ namespace ts { getSourceOfProjectReferenceRedirect, forEachResolvedProjectReference }); + const readFile = host.readFile.bind(host) as typeof host.readFile; tracing?.push(tracing.Phase.Program, "shouldProgramCreateNewSourceFiles", { hasOldProgram: !!oldProgram }); const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options); @@ -1182,6 +1183,7 @@ namespace ts { isSourceOfProjectReferenceRedirect, emitBuildInfo, fileExists, + readFile, directoryExists, getSymlinkCache, realpath: host.realpath?.bind(host), @@ -1444,6 +1446,7 @@ namespace ts { // If we change our policy of rechecking failed lookups on each program create, // we should adjust the value returned here. function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string, index: number): boolean { + if (index >= length(oldSourceFile?.imports) + length(oldSourceFile?.moduleAugmentations)) return false; // mode index out of bounds, don't reuse resolution const resolutionToFile = getResolvedModule(oldSourceFile, moduleName, oldSourceFile && getModeForResolutionAtIndex(oldSourceFile, index)); const resolvedFile = resolutionToFile && oldProgram!.getSourceFile(resolutionToFile.resolvedFileName); if (resolutionToFile && resolvedFile) { From 4a339756afb4eaccc5f84b4ea976ba5c526a0f02 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 21 Sep 2021 12:11:32 -0700 Subject: [PATCH 09/12] Always include extensions on completions for cjs/mjs style imports --- src/services/stringCompletions.ts | 4 ++-- .../nodeModulesImportCompletions1.ts | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/nodeModulesImportCompletions1.ts diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index cc81c6ab97f0e..fddf8fffae74b 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -432,11 +432,11 @@ namespace ts.Completions.StringCompletions { let foundFileName: string; const outputExtension = moduleSpecifiers.tryGetJSExtensionForFile(filePath, host.getCompilationSettings()); - if (includeExtensionsOption === IncludeExtensionsOption.Exclude && !fileExtensionIs(filePath, Extension.Json)) { + if (includeExtensionsOption === IncludeExtensionsOption.Exclude && !fileExtensionIsOneOf(filePath, [Extension.Json, Extension.Mts, Extension.Cts, Extension.Dmts, Extension.Dcts, Extension.Mjs, Extension.Cjs])) { foundFileName = removeFileExtension(getBaseFileName(filePath)); foundFiles.set(foundFileName, tryGetExtensionFromPath(filePath)); } - else if (includeExtensionsOption === IncludeExtensionsOption.ModuleSpecifierCompletion && outputExtension) { + else if ((fileExtensionIsOneOf(filePath, [Extension.Mts, Extension.Cts, Extension.Dmts, Extension.Dcts, Extension.Mjs, Extension.Cjs]) || includeExtensionsOption === IncludeExtensionsOption.ModuleSpecifierCompletion) && outputExtension) { foundFileName = changeExtension(getBaseFileName(filePath), outputExtension); foundFiles.set(foundFileName, outputExtension); } diff --git a/tests/cases/fourslash/nodeModulesImportCompletions1.ts b/tests/cases/fourslash/nodeModulesImportCompletions1.ts new file mode 100644 index 0000000000000..81ea6dd8e1c2c --- /dev/null +++ b/tests/cases/fourslash/nodeModulesImportCompletions1.ts @@ -0,0 +1,23 @@ +/// +// @allowJs: true +// @Filename: /src/module.mts +//// export {} +// @Filename: /src/module.cts +//// export {} +// @Filename: /src/decl.d.mts +//// export {} +// @Filename: /src/decl.d.cts +//// export {} +// @Filename: /src/js.mjs +//// export {} +// @Filename: /src/js.cjs +//// export {} + +// @Filename: /src/main.mts +//// import {} from ".//**/"; + +verify.completions({ + marker: "", + exact: ["decl.cjs", "decl.mjs", "js.cjs", "js.mjs", "module.cjs", "module.mjs"], + isNewIdentifierLocation: true, +}); \ No newline at end of file From 76afb7981fd933548a2b86184ae44f8a7a6c203d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 21 Sep 2021 13:05:40 -0700 Subject: [PATCH 10/12] String completion relative import suggestions respect the mode of the import when choosing if they provide extensions --- src/services/stringCompletions.ts | 10 ++++-- .../nodeModulesImportCompletions1.ts | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index fddf8fffae74b..d0771f2e97b3b 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -321,8 +321,13 @@ namespace ts.Completions.StringCompletions { const scriptDirectory = getDirectoryPath(scriptPath); return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && (isRootedDiskPath(literalValue) || isUrl(literalValue)) - ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, preferences) + ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, getIncludeExtensionOption()) : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker); + + function getIncludeExtensionOption() { + const mode = isStringLiteralLike(node) ? getModeForUsageLocation(sourceFile, node) : undefined; + return preferences.importModuleSpecifierEnding === "js" || mode === ModuleKind.ESNext ? IncludeExtensionsOption.ModuleSpecifierCompletion : IncludeExtensionsOption.Exclude; + } } interface ExtensionOptions { @@ -332,8 +337,7 @@ namespace ts.Completions.StringCompletions { function getExtensionOptions(compilerOptions: CompilerOptions, includeExtensionsOption = IncludeExtensionsOption.Exclude): ExtensionOptions { return { extensions: flatten(getSupportedExtensionsForModuleResolution(compilerOptions)), includeExtensionsOption }; } - function getCompletionEntriesForRelativeModules(literalValue: string, scriptDirectory: string, compilerOptions: CompilerOptions, host: LanguageServiceHost, scriptPath: Path, preferences: UserPreferences) { - const includeExtensions = preferences.importModuleSpecifierEnding === "js" ? IncludeExtensionsOption.ModuleSpecifierCompletion : IncludeExtensionsOption.Exclude; + function getCompletionEntriesForRelativeModules(literalValue: string, scriptDirectory: string, compilerOptions: CompilerOptions, host: LanguageServiceHost, scriptPath: Path, includeExtensions: IncludeExtensionsOption) { const extensionOptions = getExtensionOptions(compilerOptions, includeExtensions); if (compilerOptions.rootDirs) { return getCompletionEntriesForDirectoryFragmentWithRootDirs( diff --git a/tests/cases/fourslash/nodeModulesImportCompletions1.ts b/tests/cases/fourslash/nodeModulesImportCompletions1.ts index 81ea6dd8e1c2c..b2356088b0391 100644 --- a/tests/cases/fourslash/nodeModulesImportCompletions1.ts +++ b/tests/cases/fourslash/nodeModulesImportCompletions1.ts @@ -1,23 +1,48 @@ /// // @allowJs: true +// @module: nodenext // @Filename: /src/module.mts //// export {} // @Filename: /src/module.cts //// export {} +// @Filename: /src/module.js +//// export {} // @Filename: /src/decl.d.mts //// export {} // @Filename: /src/decl.d.cts //// export {} +// @Filename: /src/decl.d.ts +//// export {} // @Filename: /src/js.mjs //// export {} // @Filename: /src/js.cjs //// export {} +// @Filename: /src/js.js +//// export {} + +// @Filename: /main.mts +//// import {} from "./src//*1*/"; +//// import mod = require("./src//*2*/"); +//// const m = import("./src//*3*/"); -// @Filename: /src/main.mts -//// import {} from ".//**/"; +// @Filename: /main.cts +//// import {} from "./src//*4*/"; +//// import mod = require("./src//*5*/"); +//// const m = import("./src//*6*/"); + +// @Filename: /main.ts +//// import {} from "./src//*7*/"; +//// import mod = require("./src//*8*/"); +//// const m = import("./src//*9*/"); + +verify.completions({ + marker: ["1", "3", "6", "9"], + exact: ["decl.cjs", "decl.mjs", "decl.js", "js.cjs", "js.js", "js.mjs", "module.cjs", "module.js", "module.mjs"], + isNewIdentifierLocation: true, +}); verify.completions({ - marker: "", - exact: ["decl.cjs", "decl.mjs", "js.cjs", "js.mjs", "module.cjs", "module.mjs"], + marker: ["2", "4", "5", "7", "8"], + exact: ["decl.cjs", "decl.mjs", "decl", "js.cjs", "js", "js.mjs", "module.cjs", "module", "module.mjs"], isNewIdentifierLocation: true, }); \ No newline at end of file From 0891db48f0a692f3dce5e4414a93982f170c830f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 Sep 2021 09:00:50 -0700 Subject: [PATCH 11/12] Style feedback --- src/compiler/checker.ts | 8 ++++---- src/compiler/moduleNameResolver.ts | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d113dc3072b86..bc40c2f2cd121 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3379,10 +3379,10 @@ namespace ts { const currentSourceFile = getSourceFileOfNode(location); const contextSpecifier = isStringLiteralLike(location) ? location - : (isImportCall(location) ? location : findAncestor(location, isImportCall))?.arguments[0] || - (isImportDeclaration(location) ? location : findAncestor(location, isImportDeclaration))?.moduleSpecifier || - (isExternalModuleImportEqualsDeclaration(location) ? location : findAncestor(location, isExternalModuleImportEqualsDeclaration))?.moduleReference.expression || - (isExportDeclaration(location) ? location : findAncestor(location, isExportDeclaration))?.moduleSpecifier || + : findAncestor(location, isImportCall)?.arguments[0] || + findAncestor(location, isImportDeclaration)?.moduleSpecifier || + findAncestor(location, isExternalModuleImportEqualsDeclaration)?.moduleReference.expression || + findAncestor(location, isExportDeclaration)?.moduleSpecifier || (isModuleDeclaration(location) ? location : location.parent && isModuleDeclaration(location.parent) && location.parent.name === location ? location.parent : undefined)?.name || (isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal; const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : undefined)!; // TODO: GH#18217 diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index fdfe10c7d70a1..6d45b769dd69b 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1189,7 +1189,9 @@ namespace ts { EsmMode = 1 << 5, } - function node12ModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { + function node12ModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, + host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, + resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { return nodeNextModuleNameResolverWorker( NodeResolutionFeatures.Imports | NodeResolutionFeatures.SelfName | NodeResolutionFeatures.Exports, moduleName, @@ -1202,7 +1204,9 @@ namespace ts { ); } - function nodeNextModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { + function nodeNextModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, + host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, + resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { return nodeNextModuleNameResolverWorker( NodeResolutionFeatures.AllFeatures, moduleName, @@ -1241,8 +1245,17 @@ namespace ts { const traceEnabled = isTraceEnabled(compilerOptions, host); const failedLookupLocations: string[] = []; - // conditions are only used by the node12/nodenext resolver - there's no priority order in the list, it's essentially a set (priority is determined by object insertion order in the object we look at). - const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features, conditions: features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] }; + // conditions are only used by the node12/nodenext resolver - there's no priority order in the list, + //it's essentially a set (priority is determined by object insertion order in the object we look at). + const state: ModuleResolutionState = { + compilerOptions, + host, + traceEnabled, + failedLookupLocations, + packageJsonInfoCache: cache, + features, + conditions: features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] + }; const result = forEach(extensions, ext => tryResolve(ext)); return createResolvedModuleWithFailedLookupLocations(result?.value?.resolved, result?.value?.isExternalLibraryImport, failedLookupLocations, state.resultFromCache); From a2e799ac3110010c3b4a167eb5a7259fc44e0e0b Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 24 Sep 2021 12:35:42 -0700 Subject: [PATCH 12/12] Change diagnostic case --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...sPackageSelfName(module=node12).errors.txt | 4 +- ...ackageSelfName(module=nodenext).errors.txt | 4 +- .../nodeModules1(module=node12).errors.txt | 104 +++++++++--------- .../nodeModules1(module=nodenext).errors.txt | 104 +++++++++--------- ...eModulesAllowJs1(module=node12).errors.txt | 104 +++++++++--------- ...odulesAllowJs1(module=nodenext).errors.txt | 104 +++++++++--------- ...alPackageExports(module=node12).errors.txt | 8 +- ...PackageExports(module=nodenext).errors.txt | 8 +- ...JsPackageExports(module=node12).errors.txt | 20 ++-- ...PackageExports(module=nodenext).errors.txt | 20 ++-- ...JsPackageImports(module=node12).errors.txt | 8 +- ...PackageImports(module=nodenext).errors.txt | 8 +- ...gePatternExports(module=node12).errors.txt | 12 +- ...PatternExports(module=nodenext).errors.txt | 12 +- ...xportsTrailers(module=nodenext).errors.txt | 12 +- ...ronousCallErrors(module=node12).errors.txt | 12 +- ...nousCallErrors(module=nodenext).errors.txt | 12 +- ...alPackageExports(module=node12).errors.txt | 8 +- ...PackageExports(module=nodenext).errors.txt | 8 +- ...tionEmitDynamicImportWithPackageExports.js | 12 +- ...thPackageExports(module=node12).errors.txt | 20 ++-- ...PackageExports(module=nodenext).errors.txt | 20 ++-- ...esPackageExports(module=node12).errors.txt | 20 ++-- ...PackageExports(module=nodenext).errors.txt | 20 ++-- ...esPackageImports(module=node12).errors.txt | 8 +- ...PackageImports(module=nodenext).errors.txt | 8 +- ...gePatternExports(module=node12).errors.txt | 12 +- ...PatternExports(module=nodenext).errors.txt | 12 +- ...xportsTrailers(module=nodenext).errors.txt | 12 +- ...ronousCallErrors(module=node12).errors.txt | 12 +- ...nousCallErrors(module=nodenext).errors.txt | 12 +- ...ePackageSelfName(module=node12).errors.txt | 4 +- ...ackageSelfName(module=nodenext).errors.txt | 4 +- ...t-correctly-with-cts-and-mts-extensions.js | 4 +- 36 files changed, 378 insertions(+), 378 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bc40c2f2cd121..a6717262817b3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3396,7 +3396,7 @@ namespace ts { if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeNext) { const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration); if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext) { - error(errorNode, Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_es_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead, moduleReference); + error(errorNode, Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead, moduleReference); } } // merged symbol is module declaration symbol combined with all augmentations diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 608e211322876..5a4cd1e09dd6f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1397,7 +1397,7 @@ "category": "Error", "code": 1470 }, - "Module '{0}' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead.": { + "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.": { "category": "Error", "code": 1471 }, diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt index 4396d968d3e21..bdf6aba250c51 100644 --- a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=node12).errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'pack // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. self; ==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt index 4396d968d3e21..bdf6aba250c51 100644 --- a/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeAllowJsPackageSelfName(module=nodenext).errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS1471: Module 'pack // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. self; ==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeModules1(module=node12).errors.txt b/tests/baselines/reference/nodeModules1(module=node12).errors.txt index 25a54cd60c914..6398640a86946 100644 --- a/tests/baselines/reference/nodeModules1(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModules1(module=node12).errors.txt @@ -1,19 +1,19 @@ -tests/cases/conformance/node/index.cts(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.cts(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.cts(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -36,11 +36,11 @@ tests/cases/conformance/node/index.mts(21,22): error TS2307: Cannot find module tests/cases/conformance/node/index.mts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/index.mts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/index.mts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/index.mts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.mts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.mts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.mts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -63,11 +63,11 @@ tests/cases/conformance/node/index.ts(21,22): error TS2307: Cannot find module ' tests/cases/conformance/node/index.ts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/index.ts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/index.ts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/index.ts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.ts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.ts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.ts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -191,10 +191,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -203,13 +203,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -264,35 +264,35 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m2 from "./index.mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m3 from "./index.cjs"; import * as m4 from "./subfolder/index.js"; import * as m5 from "./subfolder/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m6 from "./subfolder/index.cjs"; import * as m7 from "./subfolder2/index.js"; import * as m8 from "./subfolder2/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m11 from "./subfolder2/another/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) import * as m13 from "./"; ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m14 from "./index"; ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m15 from "./subfolder"; import * as m16 from "./subfolder/"; import * as m17 from "./subfolder/index"; @@ -301,13 +301,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import * as m20 from "./subfolder2/index"; import * as m21 from "./subfolder2/another"; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m22 from "./subfolder2/another/"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m23 from "./subfolder2/another/index"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -335,10 +335,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -347,13 +347,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -477,10 +477,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -489,13 +489,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; diff --git a/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt index 25a54cd60c914..6398640a86946 100644 --- a/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModules1(module=nodenext).errors.txt @@ -1,19 +1,19 @@ -tests/cases/conformance/node/index.cts(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.cts(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.cts(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.cts(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -36,11 +36,11 @@ tests/cases/conformance/node/index.mts(21,22): error TS2307: Cannot find module tests/cases/conformance/node/index.mts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/index.mts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/index.mts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/index.mts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.mts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.mts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.mts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.mts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -63,11 +63,11 @@ tests/cases/conformance/node/index.ts(21,22): error TS2307: Cannot find module ' tests/cases/conformance/node/index.ts(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/index.ts(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/index.ts(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/index.ts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.ts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/index.ts(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/index.ts(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/index.ts(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -191,10 +191,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -203,13 +203,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -264,35 +264,35 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m2 from "./index.mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m3 from "./index.cjs"; import * as m4 from "./subfolder/index.js"; import * as m5 from "./subfolder/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m6 from "./subfolder/index.cjs"; import * as m7 from "./subfolder2/index.js"; import * as m8 from "./subfolder2/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m11 from "./subfolder2/another/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) import * as m13 from "./"; ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m14 from "./index"; ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m15 from "./subfolder"; import * as m16 from "./subfolder/"; import * as m17 from "./subfolder/index"; @@ -301,13 +301,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import * as m20 from "./subfolder2/index"; import * as m21 from "./subfolder2/another"; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m22 from "./subfolder2/another/"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m23 from "./subfolder2/another/index"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -335,10 +335,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -347,13 +347,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -477,10 +477,10 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -489,13 +489,13 @@ tests/cases/conformance/node/index.ts(84,21): error TS2307: Cannot find module ' import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt index 40c019c539686..ff46be3295d17 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=node12).errors.txt @@ -1,19 +1,19 @@ -tests/cases/conformance/node/allowJs/index.cjs(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.cjs(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.cjs(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -37,9 +37,9 @@ tests/cases/conformance/node/allowJs/index.js(22,22): error TS2307: Cannot find tests/cases/conformance/node/allowJs/index.js(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(50,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(51,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(52,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(53,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(54,1): error TS8002: 'import ... =' can only be used in TypeScript files. @@ -47,11 +47,11 @@ tests/cases/conformance/node/allowJs/index.js(55,1): error TS8002: 'import ... = tests/cases/conformance/node/allowJs/index.js(56,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(57,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(58,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(59,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(60,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -74,11 +74,11 @@ tests/cases/conformance/node/allowJs/index.mjs(21,22): error TS2307: Cannot find tests/cases/conformance/node/allowJs/index.mjs(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.mjs(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -204,12 +204,12 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find ~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. @@ -232,17 +232,17 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -296,35 +296,35 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m2 from "./index.mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m3 from "./index.cjs"; import * as m4 from "./subfolder/index.js"; import * as m5 from "./subfolder/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m6 from "./subfolder/index.cjs"; import * as m7 from "./subfolder2/index.js"; import * as m8 from "./subfolder2/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m11 from "./subfolder2/another/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) import * as m13 from "./"; ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m14 from "./index"; ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m15 from "./subfolder"; import * as m16 from "./subfolder/"; import * as m17 from "./subfolder/index"; @@ -333,13 +333,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import * as m20 from "./subfolder2/index"; import * as m21 from "./subfolder2/another"; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m22 from "./subfolder2/another/"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m23 from "./subfolder2/another/index"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -367,10 +367,10 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -379,13 +379,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -509,10 +509,10 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -521,13 +521,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; diff --git a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt index 40c019c539686..ff46be3295d17 100644 --- a/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).errors.txt @@ -1,19 +1,19 @@ -tests/cases/conformance/node/allowJs/index.cjs(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(2,21): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,21): error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(6,21): error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,21): error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(11,22): error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(12,22): error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(15,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(16,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(23,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(24,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(25,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(51,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(52,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(59,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(60,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(61,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.cjs(75,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.cjs(76,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.cjs(77,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -37,9 +37,9 @@ tests/cases/conformance/node/allowJs/index.js(22,22): error TS2307: Cannot find tests/cases/conformance/node/allowJs/index.js(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(50,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(51,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(52,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(53,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(54,1): error TS8002: 'import ... =' can only be used in TypeScript files. @@ -47,11 +47,11 @@ tests/cases/conformance/node/allowJs/index.js(55,1): error TS8002: 'import ... = tests/cases/conformance/node/allowJs/index.js(56,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(57,1): error TS8002: 'import ... =' can only be used in TypeScript files. tests/cases/conformance/node/allowJs/index.js(58,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(59,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(60,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.js(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -74,11 +74,11 @@ tests/cases/conformance/node/allowJs/index.mjs(21,22): error TS2307: Cannot find tests/cases/conformance/node/allowJs/index.mjs(22,22): error TS2307: Cannot find module './subfolder2/another' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(23,22): error TS2307: Cannot find module './subfolder2/another/' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(24,22): error TS2307: Cannot find module './subfolder2/another/index' or its corresponding type declarations. -tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(50,22): error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(51,22): error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(58,22): error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(59,22): error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.mjs(60,22): error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.mjs(74,21): error TS2307: Cannot find module './' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(75,21): error TS2307: Cannot find module './index' or its corresponding type declarations. tests/cases/conformance/node/allowJs/index.mjs(76,21): error TS2307: Cannot find module './subfolder' or its corresponding type declarations. @@ -204,12 +204,12 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find ~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. @@ -232,17 +232,17 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -296,35 +296,35 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // ESM-format imports below should issue errors import * as m1 from "./index.js"; ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m2 from "./index.mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m3 from "./index.cjs"; import * as m4 from "./subfolder/index.js"; import * as m5 from "./subfolder/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m6 from "./subfolder/index.cjs"; import * as m7 from "./subfolder2/index.js"; import * as m8 from "./subfolder2/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m9 from "./subfolder2/index.cjs"; import * as m10 from "./subfolder2/another/index.js"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m11 from "./subfolder2/another/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m12 from "./subfolder2/another/index.cjs"; // The next ones should _mostly_ work - cjs format files have index resolution and extension resolution (except for those which resolve to an esm format file) import * as m13 from "./"; ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m14 from "./index"; ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m15 from "./subfolder"; import * as m16 from "./subfolder/"; import * as m17 from "./subfolder/index"; @@ -333,13 +333,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import * as m20 from "./subfolder2/index"; import * as m21 from "./subfolder2/another"; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m22 from "./subfolder2/another/"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as m23 from "./subfolder2/another/index"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m1; void m2; void m3; @@ -367,10 +367,10 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -379,13 +379,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; @@ -509,10 +509,10 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find // These should _mostly_ work - `import = require` always desugars to require calls, which do have extension and index resolution (but can't load anything that resolves to esm!) import m24 = require("./"); ~~~~ -!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m25 = require("./index"); ~~~~~~~~~ -!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m26 = require("./subfolder"); import m27 = require("./subfolder/"); import m28 = require("./subfolder/index"); @@ -521,13 +521,13 @@ tests/cases/conformance/node/allowJs/index.mjs(84,21): error TS2307: Cannot find import m31 = require("./subfolder2/index"); import m32 = require("./subfolder2/another"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m33 = require("./subfolder2/another/"); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import m34 = require("./subfolder2/another/index"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './subfolder2/another/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. void m24; void m25; void m26; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt index f889f40e378cb..83e50c001e74c 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node12).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -41,10 +41,10 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt index f889f40e378cb..83e50c001e74c 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -41,10 +41,10 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt index cb9ff4a2588b4..e6f4b3ce2eb2b 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node12).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -39,17 +39,17 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; cjsi; mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; @@ -79,7 +79,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt index cb9ff4a2588b4..e6f4b3ce2eb2b 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -39,17 +39,17 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; cjsi; mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; @@ -79,7 +79,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt index b87ae74b3a7e2..261be58f1a221 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node12).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -23,10 +23,10 @@ tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#typ import * as cjs from "#cjs"; import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "#type"; ~~~~~~~ -!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt index b87ae74b3a7e2..261be58f1a221 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -23,10 +23,10 @@ tests/cases/conformance/node/allowJs/index.cjs(4,23): error TS1471: Module '#typ import * as cjs from "#cjs"; import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "#type"; ~~~~~~~ -!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt index 1918d77ac427d..0f1999477226b 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node12).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjsi from "inner/cjs/index"; import * as mjsi from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "inner/cjs/index"; import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt index 1918d77ac427d..0f1999477226b 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=nodenext).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjsi from "inner/cjs/index"; import * as mjsi from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "inner/cjs/index"; import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt index 53cb3483c338c..b989016f16abe 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/allowJs/index.js (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjsi from "inner/cjs/index.cjs"; import * as mjsi from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index.js"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index.js"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/allowJs/node_modules/inner/index.d.ts(3,22): error import * as cjs from "inner/cjs/index.cjs"; import * as mjs from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index.js"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=node12).errors.txt b/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=node12).errors.txt index 08214d061608c..c722192e6704e 100644 --- a/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=node12).errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/node/allowJs/index.js(3,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(5,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/subfolder/index.js(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/subfolder/index.js(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/subfolder/index.js(3,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/subfolder/index.js(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/subfolder/index.js(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'import ... =' can only be used in TypeScript files. @@ -11,12 +11,12 @@ tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'imp // cjs format file import {h} from "../index.js"; ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import mod = require("../index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f as _f} from "./index.js"; import mod2 = require("./index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -33,7 +33,7 @@ tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'imp ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f} from "./subfolder/index.js"; import mod2 = require("./subfolder/index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=nodenext).errors.txt index 08214d061608c..c722192e6704e 100644 --- a/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsSynchronousCallErrors(module=nodenext).errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/node/allowJs/index.js(3,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/index.js(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/index.js(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/index.js(5,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/subfolder/index.js(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/subfolder/index.js(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/subfolder/index.js(3,1): error TS8002: 'import ... =' can only be used in TypeScript files. -tests/cases/conformance/node/allowJs/subfolder/index.js(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/allowJs/subfolder/index.js(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'import ... =' can only be used in TypeScript files. @@ -11,12 +11,12 @@ tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'imp // cjs format file import {h} from "../index.js"; ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import mod = require("../index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f as _f} from "./index.js"; import mod2 = require("./index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -33,7 +33,7 @@ tests/cases/conformance/node/allowJs/subfolder/index.js(5,1): error TS8002: 'imp ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS8002: 'import ... =' can only be used in TypeScript files. ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f} from "./subfolder/index.js"; import mod2 = require("./subfolder/index.js"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt index 3878dce9543c1..7397e1e1dbd27 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=node12).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -41,10 +41,10 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt index 3878dce9543c1..7397e1e1dbd27 100644 --- a/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesConditionalPackageExports(module=nodenext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.mts(2,13): error TS2303: Circular definition of import alias 'cjs'. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. @@ -41,10 +41,10 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js index 1448b4d594cc7..a872cc70f5625 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js @@ -177,9 +177,9 @@ export declare const e: Promise<{ //// [DtsFileErrors] -tests/cases/conformance/node/other.d.cts(2,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/other.d.cts(3,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/other.d.cts(2,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/other.d.cts(3,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.d.ts (0 errors) ==== @@ -233,10 +233,10 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs export declare const a: Promise; export declare const b: Promise; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. export declare const c: Promise; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. export declare const f: Promise<{ default: typeof import("inner"); cjsMain: true; @@ -250,7 +250,7 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs export declare const e: Promise<{ default: typeof import("inner/mjs"); ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. esm: true; }>; diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt index 693d2dc59072a..11f39b9dd9366 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=node12).errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. tests/cases/conformance/node/node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. @@ -41,17 +41,17 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. export const a = cjs; export const b = mjs; export const c = type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; export const d = cjsi; export const e = mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; cjs; ~~~ @@ -85,7 +85,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; cjs; ~~~ diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt index 693d2dc59072a..11f39b9dd9366 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesDeclarationEmitWithPackageExports(module=nodenext).errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.cts(5,1): error TS1036: Statements are not allowed in ambient contexts. tests/cases/conformance/node/node_modules/inner/index.d.mts(5,1): error TS1036: Statements are not allowed in ambient contexts. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: Statements are not allowed in ambient contexts. @@ -41,17 +41,17 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. export const a = cjs; export const b = mjs; export const c = type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; export const d = cjsi; export const e = mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; cjs; ~~~ @@ -85,7 +85,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(5,1): error TS1036: S import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; cjs; ~~~ diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt index 6f540a99bf47c..464db33f319b0 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesPackageExports(module=node12).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -39,17 +39,17 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; cjsi; mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; @@ -79,7 +79,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt index 6f540a99bf47c..464db33f319b0 100644 --- a/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesPackageExports(module=nodenext).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(9,23): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -39,17 +39,17 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "package/cjs"; import * as mjs from "package/mjs"; ~~~~~~~~~~~~~ -!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; import * as cjsi from "inner/cjs"; import * as mjsi from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner"; cjsi; mjsi; @@ -61,7 +61,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; @@ -79,7 +79,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "inner/cjs"; import * as mjs from "inner/mjs"; ~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt index 158ac7eec3de2..cc174f1eb7e26 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node12).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -23,10 +23,10 @@ tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' canno import * as cjs from "#cjs"; import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "#type"; ~~~~~~~ -!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt index 158ac7eec3de2..cc174f1eb7e26 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/node/index.cts(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,22): error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -23,10 +23,10 @@ tests/cases/conformance/node/index.cts(4,23): error TS1471: Module '#type' canno import * as cjs from "#cjs"; import * as mjs from "#mjs"; ~~~~~~ -!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "#type"; ~~~~~~~ -!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '#type' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. cjs; mjs; type; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt index abb5aca2008b1..0dc3774d5ef60 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=node12).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjsi from "inner/cjs/index"; import * as mjsi from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "inner/cjs/index"; import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt index abb5aca2008b1..0dc3774d5ef60 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesPackagePatternExports(module=nodenext).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjsi from "inner/cjs/index"; import * as mjsi from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "inner/cjs/index"; import * as mjs from "inner/mjs/index"; ~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt index b9d0b079ca659..9aa041ab4186a 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(3,23): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. -tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -25,7 +25,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjsi from "inner/cjs/index.cjs"; import * as mjsi from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as typei from "inner/js/index.js"; cjsi; mjsi; @@ -37,7 +37,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: !!! error TS2303: Circular definition of import alias 'cjs'. import * as mjs from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index.js"; export { cjs }; export { mjs }; @@ -55,7 +55,7 @@ tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: import * as cjs from "inner/cjs/index.cjs"; import * as mjs from "inner/mjs/index.mjs"; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'inner/mjs/index.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import * as type from "inner/js/index.js"; export { cjs }; export { mjs }; diff --git a/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=node12).errors.txt b/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=node12).errors.txt index 708be971e762e..012ef390621c9 100644 --- a/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=node12).errors.txt +++ b/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=node12).errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/node/index.ts(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/subfolder/index.ts(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/subfolder/index.ts(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/subfolder/index.ts (2 errors) ==== // cjs format file import {h} from "../index.js"; ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import mod = require("../index.js"); ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f as _f} from "./index.js"; import mod2 = require("./index.js"); export async function f() { @@ -23,7 +23,7 @@ tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../ import {h as _h} from "./index.js"; import mod = require("./index.js"); ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f} from "./subfolder/index.js"; import mod2 = require("./subfolder/index.js"); export async function h() { diff --git a/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=nodenext).errors.txt index 708be971e762e..012ef390621c9 100644 --- a/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesSynchronousCallErrors(module=nodenext).errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/node/index.ts(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/subfolder/index.ts(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. -tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.ts(3,22): error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/subfolder/index.ts(2,17): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/subfolder/index.ts (2 errors) ==== // cjs format file import {h} from "../index.js"; ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import mod = require("../index.js"); ~~~~~~~~~~~~~ -!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module '../index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f as _f} from "./index.js"; import mod2 = require("./index.js"); export async function f() { @@ -23,7 +23,7 @@ tests/cases/conformance/node/subfolder/index.ts(3,22): error TS1471: Module '../ import {h as _h} from "./index.js"; import mod = require("./index.js"); ~~~~~~~~~~~~ -!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module './index.js' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. import {f} from "./subfolder/index.js"; import mod2 = require("./subfolder/index.js"); export async function h() { diff --git a/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt b/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt index 058ef398feaf6..c1573b8f51dd8 100644 --- a/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt +++ b/tests/baselines/reference/nodePackageSelfName(module=node12).errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' can // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. self; ==== tests/cases/conformance/node/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt b/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt index 058ef398feaf6..c1573b8f51dd8 100644 --- a/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodePackageSelfName(module=nodenext).errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. ==== tests/cases/conformance/node/index.ts (0 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/node/index.cts(2,23): error TS1471: Module 'package' can // esm format file import * as self from "package"; ~~~~~~~~~ -!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +!!! error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. self; ==== tests/cases/conformance/node/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js index d9e50d040c5ef..bb84fc7c82f8f 100644 --- a/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js +++ b/tests/baselines/reference/tsbuild/watchMode/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js @@ -316,7 +316,7 @@ File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - File '/a/lib/package.json' does not exist. File '/a/package.json' does not exist. File '/package.json' does not exist. -packages/pkg1/index.ts:1:29 - error TS1471: Module 'pkg2' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +packages/pkg1/index.ts:1:29 - error TS1471: Module 'pkg2' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. 1 import type { TheNum } from 'pkg2'    ~~~~~~ @@ -546,7 +546,7 @@ File '/user/username/projects/myproject/packages/pkg2/build/const.d.cts' exist - File '/a/lib/package.json' does not exist. File '/a/package.json' does not exist. File '/package.json' does not exist. -packages/pkg1/index.ts:1:29 - error TS1471: Module 'pkg2' cannot be imported using this construct. The specifier only resolves to an es module, which cannot be imported synchronously. Use dynamic import instead. +packages/pkg1/index.ts:1:29 - error TS1471: Module 'pkg2' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. 1 import type { TheNum } from 'pkg2'    ~~~~~~