diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0eb1a99609473..8a44d047ac3cc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39766,16 +39766,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkSourceElement(node.argument); if (node.attributes) { - const override = getResolutionModeOverride(node.attributes, grammarErrorOnNode); - const errorNode = node.attributes; - if (override && errorNode && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { - grammarErrorOnNode( - errorNode, - node.attributes.token === SyntaxKind.WithKeyword - ? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext - : Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext, - ); - } + getResolutionModeOverride(node.attributes, grammarErrorOnNode); } checkTypeReferenceOrImport(node); } @@ -45212,14 +45203,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const override = getResolutionModeOverride(node, validForTypeAttributes ? grammarErrorOnNode : undefined); const isImportAttributes = declaration.attributes.token === SyntaxKind.WithKeyword; if (validForTypeAttributes && override) { - if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode( - node, - isImportAttributes - ? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext - : Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext, - ); - } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9083506fbeb38..86996c1bd7f5d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1480,10 +1480,6 @@ "category": "Error", "code": 1451 }, - "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.": { - "category": "Error", - "code": 1452 - }, "`resolution-mode` should be either `require` or `import`.": { "category": "Error", "code": 1453 @@ -1520,10 +1516,6 @@ "category": "Message", "code": 1461 }, - "The 'resolution-mode' attribute is only supported when 'moduleResolution' is 'node16' or 'nodenext'.": { - "category": "Error", - "code": 1462 - }, "'resolution-mode' is the only valid key for type import attributes.": { "category": "Error", "code": 1463 diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index d27a545584384..f978cf7ea0016 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -556,18 +556,21 @@ export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string const failedLookupLocations: string[] = []; const affectingLocations: string[] = []; + // Allow type reference directives to opt into `exports` resolution in any resolution mode + // when a `resolution-mode` override is present. let features = getNodeResolutionFeatures(options); - // Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution - // setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being - // set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports - // are present in a non-modal project; while in theory we'd like to either ignore the mode or provide faithful modern resolution, depending on what we feel is best, - // in practice, not every cache has the options available to intelligently make the choice to ignore the mode request, and it's unclear how modern "faithful modern - // resolution" should be (`node16`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution - // context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do). - if (resolutionMode === ModuleKind.ESNext && (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node16 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext)) { + if (resolutionMode !== undefined) { + features |= NodeResolutionFeatures.AllFeatures; + } + const moduleResolution = getEmitModuleResolutionKind(options); + if (resolutionMode === ModuleKind.ESNext && (ModuleResolutionKind.Node16 <= moduleResolution && moduleResolution <= ModuleResolutionKind.NodeNext)) { features |= NodeResolutionFeatures.EsmMode; } - const conditions = features & NodeResolutionFeatures.Exports ? getConditions(options, !!(features & NodeResolutionFeatures.EsmMode)) : []; + // true: "import" / false: "require" / undefined: default based on settings + const useImportCondition = resolutionMode === ModuleKind.ESNext || (resolutionMode !== undefined ? false : undefined); + const conditions = (features & NodeResolutionFeatures.Exports) + ? getConditions(options, useImportCondition) + : []; const diagnostics: Diagnostic[] = []; const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, @@ -722,17 +725,33 @@ function getNodeResolutionFeatures(options: CompilerOptions) { return features; } -/** @internal */ +/** + * @param overrideResolutionModeAttribute + * @internal + */ export function getConditions(options: CompilerOptions, esmMode?: boolean) { + const moduleResolution = getEmitModuleResolutionKind(options); + if (esmMode === undefined) { + if (moduleResolution === ModuleResolutionKind.Bundler) { + // bundler always uses `import` unless explicitly overridden + esmMode ??= moduleResolution === ModuleResolutionKind.Bundler; + } + else if (moduleResolution === ModuleResolutionKind.Node10) { + // node10 does not support package.json imports/exports without + // an explicit resolution-mode override on a type-only import + // (indicated by `esmMode` being set) + return []; + } + } // conditions are only used by the node16/nodenext/bundler resolvers - 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 conditions = esmMode || getEmitModuleResolutionKind(options) === ModuleResolutionKind.Bundler + const conditions = esmMode ? ["import"] : ["require"]; if (!options.noDtsResolution) { conditions.push("types"); } - if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Bundler) { + if (moduleResolution !== ModuleResolutionKind.Bundler) { conditions.push("node"); } return concatenate(conditions, options.customConditions); @@ -1393,13 +1412,13 @@ export function resolveModuleName(moduleName: string, containingFile: string, co result = nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); break; case ModuleResolutionKind.Node10: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference); + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode ? getConditions(compilerOptions, resolutionMode === ModuleKind.ESNext) : undefined); break; case ModuleResolutionKind.Classic: result = classicNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference); break; case ModuleResolutionKind.Bundler: - result = bundlerModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference); + result = bundlerModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode ? getConditions(compilerOptions, resolutionMode === ModuleKind.ESNext) : undefined); break; default: return Debug.fail(`Unexpected moduleResolution: ${moduleResolution}`); @@ -1681,7 +1700,7 @@ function nodeNextModuleNameResolver(moduleName: string, containingFile: string, ); } -function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations { +function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode, conditions?: string[]): 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 @@ -1690,7 +1709,7 @@ function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, modu if (getResolveJsonModule(compilerOptions)) { extensions |= Extensions.Json; } - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference); + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference, conditions); } function tryResolveJSModuleWorker(moduleName: string, initialDir: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { @@ -1704,21 +1723,24 @@ function tryResolveJSModuleWorker(moduleName: string, initialDir: string, host: Extensions.JavaScript, /*isConfigLookup*/ false, /*redirectedReference*/ undefined, + /*conditions*/ undefined, ); } - -export function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations { +export function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; +/** @internal */ +export function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, conditions?: string[]): ResolvedModuleWithFailedLookupLocations; +export function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, conditions?: string[]): ResolvedModuleWithFailedLookupLocations { const containingDirectory = getDirectoryPath(containingFile); let extensions = compilerOptions.noDtsResolution ? Extensions.ImplementationFiles : Extensions.TypeScript | Extensions.JavaScript | Extensions.Declaration; if (getResolveJsonModule(compilerOptions)) { extensions |= Extensions.Json; } - return nodeModuleNameResolverWorker(getNodeResolutionFeatures(compilerOptions), moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference); + return nodeModuleNameResolverWorker(getNodeResolutionFeatures(compilerOptions), moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference, conditions); } 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, isConfigLookup?: boolean): ResolvedModuleWithFailedLookupLocations { +/** @internal */ export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, conditions?: string[], 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, conditions?: string[], isConfigLookup?: boolean): ResolvedModuleWithFailedLookupLocations { let extensions; if (isConfigLookup) { extensions = Extensions.Json; @@ -1732,20 +1754,38 @@ export function nodeModuleNameResolver(moduleName: string, containingFile: strin ? Extensions.TypeScript | Extensions.JavaScript | Extensions.Declaration | Extensions.Json : Extensions.TypeScript | Extensions.JavaScript | Extensions.Declaration; } - return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, getDirectoryPath(containingFile), compilerOptions, host, cache, extensions, !!isConfigLookup, redirectedReference); + + return nodeModuleNameResolverWorker(conditions ? NodeResolutionFeatures.AllFeatures : NodeResolutionFeatures.None, moduleName, getDirectoryPath(containingFile), compilerOptions, host, cache, extensions, !!isConfigLookup, redirectedReference, conditions); } /** @internal */ export function nodeNextJsonConfigResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - return nodeModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, getDirectoryPath(containingFile), { moduleResolution: ModuleResolutionKind.NodeNext }, host, /*cache*/ undefined, Extensions.Json, /*isConfigLookup*/ true, /*redirectedReference*/ undefined); + return nodeModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, getDirectoryPath(containingFile), { moduleResolution: ModuleResolutionKind.NodeNext }, host, /*cache*/ undefined, Extensions.Json, /*isConfigLookup*/ true, /*redirectedReference*/ undefined, /*conditions*/ undefined); } -function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingDirectory: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache: ModuleResolutionCache | undefined, extensions: Extensions, isConfigLookup: boolean, redirectedReference: ResolvedProjectReference | undefined): ResolvedModuleWithFailedLookupLocations { +function nodeModuleNameResolverWorker( + features: NodeResolutionFeatures, + moduleName: string, + containingDirectory: string, + compilerOptions: CompilerOptions, + host: ModuleResolutionHost, + cache: ModuleResolutionCache | undefined, + extensions: Extensions, + isConfigLookup: boolean, + redirectedReference: ResolvedProjectReference | undefined, + conditions: readonly string[] | undefined, +): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); const failedLookupLocations: string[] = []; const affectingLocations: string[] = []; - const conditions = getConditions(compilerOptions, !!(features & NodeResolutionFeatures.EsmMode)); + const moduleResolution = getEmitModuleResolutionKind(compilerOptions); + conditions ??= getConditions( + compilerOptions, + moduleResolution === ModuleResolutionKind.Bundler || moduleResolution === ModuleResolutionKind.Node10 + ? undefined + : !!(features & NodeResolutionFeatures.EsmMode), + ); const diagnostics: Diagnostic[] = []; const state: ModuleResolutionState = { @@ -1756,19 +1796,18 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa affectingLocations, packageJsonInfoCache: cache, features, - conditions, + conditions: conditions ?? emptyArray, requestContainingDirectory: containingDirectory, reportDiagnostic: diag => void diagnostics.push(diag), isConfigLookup, candidateIsFromPackageJsonField: false, }; - - if (traceEnabled && moduleResolutionSupportsPackageJsonExportsAndImports(getEmitModuleResolutionKind(compilerOptions))) { - trace(host, Diagnostics.Resolving_in_0_mode_with_conditions_1, features & NodeResolutionFeatures.EsmMode ? "ESM" : "CJS", conditions.map(c => `'${c}'`).join(", ")); + if (traceEnabled && moduleResolutionSupportsPackageJsonExportsAndImports(moduleResolution)) { + trace(host, Diagnostics.Resolving_in_0_mode_with_conditions_1, features & NodeResolutionFeatures.EsmMode ? "ESM" : "CJS", state.conditions.map(c => `'${c}'`).join(", ")); } let result; - if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node10) { + if (moduleResolution === ModuleResolutionKind.Node10) { const priorityExtensions = extensions & (Extensions.TypeScript | Extensions.Declaration); const secondaryExtensions = extensions & ~(Extensions.TypeScript | Extensions.Declaration); result = priorityExtensions && tryResolve(priorityExtensions, state) || @@ -1789,7 +1828,7 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa && features & NodeResolutionFeatures.Exports && !isExternalModuleNameRelative(moduleName) && !extensionIsOk(Extensions.TypeScript | Extensions.Declaration, result.value.resolved.extension) - && conditions.includes("import") + && conditions?.includes("import") ) { traceIfEnabled(state, Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update); const diagnosticState = { @@ -2643,7 +2682,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo const combinedLookup = pattern ? target.replace(/\*/g, subpath) : target + subpath; traceIfEnabled(state, Diagnostics.Using_0_subpath_1_with_target_2, "imports", key, combinedLookup); traceIfEnabled(state, Diagnostics.Resolving_module_0_from_1, combinedLookup, scope.packageDirectory + "/"); - const result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, extensions, /*isConfigLookup*/ false, redirectedReference); + const result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, extensions, /*isConfigLookup*/ false, redirectedReference, state.conditions); return toSearchResult( result.resolvedModule ? { path: result.resolvedModule.resolvedFileName, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 49934452ff9f5..2a5fedace1399 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -865,7 +865,6 @@ export function getModeForResolutionAtIndex(file: SourceFile, index: number): Re // eslint-disable-next-line @typescript-eslint/unified-signatures export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ResolutionMode; export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ResolutionMode { - if (file.impliedNodeFormat === undefined) return undefined; // 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)); @@ -892,7 +891,6 @@ export function isExclusivelyTypeOnlyImportOrExport(decl: ImportDeclaration | Ex * @returns The final resolution mode of the import */ export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMode; }, usage: StringLiteralLike) { - if (file.impliedNodeFormat === undefined) return undefined; if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) { const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent); if (isTypeOnly) { @@ -908,6 +906,7 @@ export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMo return override; } } + 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; @@ -3863,14 +3862,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg const fileName = toFileNameLowerCase(ref.fileName); resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective); const mode = ref.resolutionMode || file.impliedNodeFormat; - if (mode && getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeNext) { - (fileProcessingDiagnostics ??= []).push({ - kind: FilePreprocessingDiagnosticsKind.ResolutionDiagnostics, - diagnostics: [ - createDiagnosticForRange(file, ref, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext), - ], - }); - } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: FileIncludeKind.TypeReferenceDirective, file: file.path, index }); } } diff --git a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt deleted file mode 100644 index fcec678778db4..0000000000000 --- a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt +++ /dev/null @@ -1,45 +0,0 @@ -/index.ts(1,23): error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. -/index.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'. -/index.ts(2,23): error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. -/index.ts(2,23): error TS2688: Cannot find type definition file for 'pkg'. -/index.ts(3,1): error TS2304: Cannot find name 'foo'. -/index.ts(4,1): error TS2304: Cannot find name 'bar'. - - -==== /index.ts (6 errors) ==== - /// - ~~~ -!!! error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. - ~~~ -!!! error TS2688: Cannot find type definition file for 'pkg'. - /// - ~~~ -!!! error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. - ~~~ -!!! error TS2688: Cannot find type definition file for 'pkg'. - foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary - ~~~ -!!! error TS2304: Cannot find name 'foo'. - bar; - ~~~ -!!! error TS2304: Cannot find name 'bar'. - export {}; -==== /node_modules/pkg/package.json (0 errors) ==== - { - "name": "pkg", - "version": "0.0.1", - "exports": { - "import": "./import.js", - "require": "./require.js" - } - } -==== /node_modules/pkg/import.d.ts (0 errors) ==== - export {}; - declare global { - var foo: number; - } -==== /node_modules/pkg/require.d.ts (0 errors) ==== - export {}; - declare global { - var bar: number; - } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.js b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.js index 23956dcec3a63..e82a9a84d58bc 100644 --- a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.js +++ b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.js @@ -22,7 +22,7 @@ declare global { //// [index.ts] /// /// -foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary +foo; bar; export {}; @@ -31,5 +31,5 @@ export {}; Object.defineProperty(exports, "__esModule", { value: true }); /// /// -foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary +foo; bar; diff --git a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.symbols b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.symbols index 8a2edac1f389b..a7da6602add90 100644 --- a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.symbols +++ b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.symbols @@ -1,9 +1,28 @@ //// [tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.ts] //// === /index.ts === - /// /// -foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary +foo; +>foo : Symbol(foo, Decl(import.d.ts, 2, 7)) + bar; +>bar : Symbol(bar, Decl(require.d.ts, 2, 7)) + +export {}; +=== /node_modules/pkg/import.d.ts === export {}; +declare global { +>global : Symbol(global, Decl(import.d.ts, 0, 10)) + + var foo: number; +>foo : Symbol(foo, Decl(import.d.ts, 2, 7)) +} +=== /node_modules/pkg/require.d.ts === +export {}; +declare global { +>global : Symbol(global, Decl(require.d.ts, 0, 10)) + + var bar: number; +>bar : Symbol(bar, Decl(require.d.ts, 2, 7)) +} diff --git a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.types b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.types index f3e89c2c89f14..79c8972776373 100644 --- a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.types +++ b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.types @@ -3,10 +3,26 @@ === /index.ts === /// /// -foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary ->foo : any +foo; +>foo : number bar; ->bar : any +>bar : number export {}; +=== /node_modules/pkg/import.d.ts === +export {}; +declare global { +>global : typeof global + + var foo: number; +>foo : number +} +=== /node_modules/pkg/require.d.ts === +export {}; +declare global { +>global : typeof global + + var bar: number; +>bar : number +} diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).symbols b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).symbols new file mode 100644 index 0000000000000..3b36b51d0afa7 --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).symbols @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : Symbol(Default, Decl(app.ts, 0, 0)) +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : Symbol(Import, Decl(app.ts, 0, 38)) +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : Symbol(Require, Decl(app.ts, 1, 82)) +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 2, 84)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 4, 94)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).types b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).types new file mode 100644 index 0000000000000..f3c63d21500ce --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=bundler).types @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : "module" +>x : error + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : "module" +>x : error + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : "script" +>x : error + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : "other" +>x : error + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : "other" +>x : error + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).errors.txt b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).errors.txt new file mode 100644 index 0000000000000..f7596129d6f40 --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).errors.txt @@ -0,0 +1,46 @@ +error TS2688: Cannot find type definition file for 'foo'. + The file is in the program because: + Entry point for implicit type library 'foo' +/app.ts(1,30): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +/app.ts(2,29): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +/app.ts(3,30): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + + +!!! error TS2688: Cannot find type definition file for 'foo'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point for implicit type library 'foo' +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export declare const x: "module"; + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export declare const x: "script"; + +==== /app.ts (3 errors) ==== + type Default = typeof import("foo").x; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + // resolution-mode does not enforce file extension in `bundler`, just sets conditions + type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; + type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; + +==== /other.ts (0 errors) ==== + export const x = "other"; + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).symbols b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).symbols new file mode 100644 index 0000000000000..5d3941b76cc7c --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).symbols @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : Symbol(Default, Decl(app.ts, 0, 0)) + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : Symbol(Import, Decl(app.ts, 0, 38)) + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : Symbol(Require, Decl(app.ts, 1, 82)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 2, 84)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 4, 94)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).types b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).types new file mode 100644 index 0000000000000..bc1037abadf8e --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=classic).types @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : any +>x : any + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : any +>x : any + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : any +>x : any + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : "other" +>x : any + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : "other" +>x : any + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).errors.txt b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).errors.txt new file mode 100644 index 0000000000000..61dafd0967d69 --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).errors.txt @@ -0,0 +1,40 @@ +error TS2688: Cannot find type definition file for 'foo'. + The file is in the program because: + Entry point for implicit type library 'foo' +/app.ts(1,30): error TS2307: Cannot find module 'foo' or its corresponding type declarations. + + +!!! error TS2688: Cannot find type definition file for 'foo'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point for implicit type library 'foo' +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export declare const x: "module"; + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export declare const x: "script"; + +==== /app.ts (1 errors) ==== + type Default = typeof import("foo").x; + ~~~~~ +!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. + type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; + type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; + // resolution-mode does not enforce file extension in `bundler`, just sets conditions + type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; + type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; + +==== /other.ts (0 errors) ==== + export const x = "other"; + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).symbols b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).symbols new file mode 100644 index 0000000000000..e83a9671ea382 --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).symbols @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : Symbol(Default, Decl(app.ts, 0, 0)) + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : Symbol(Import, Decl(app.ts, 0, 38)) +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : Symbol(Require, Decl(app.ts, 1, 82)) +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 2, 84)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 4, 94)) +>x : Symbol(x, Decl(other.ts, 0, 12)) + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).types b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).types new file mode 100644 index 0000000000000..ad88d6531656b --- /dev/null +++ b/tests/baselines/reference/resolutionModeImportType1(moduleresolution=node10).types @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +type Default = typeof import("foo").x; +>Default : any +>x : any + +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +>Import : "module" +>x : any + +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +>Require : "script" +>x : any + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +>ImportRelative : "other" +>x : any + +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; +>RequireRelative : "other" +>x : any + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/baselines/reference/resolutionModeTripleSlash1.errors.txt b/tests/baselines/reference/resolutionModeTripleSlash1.errors.txt new file mode 100644 index 0000000000000..963acbfbf25d1 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash1.errors.txt @@ -0,0 +1,45 @@ +/app.ts(3,1): error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? + + +==== /tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "types": [] + } + } + +==== /app.ts (1 errors) ==== + /// + MODULE; // ok + SCRIPT; // error + ~~~~~~ +!!! error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? +!!! related TS2728 lib.scripthost.d.ts:--:--: 'WScript' is declared here. + +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export {}; + declare global { + const MODULE: any; + } + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export {}; + declare global { + const SCRIPT: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTripleSlash2.errors.txt b/tests/baselines/reference/resolutionModeTripleSlash2.errors.txt new file mode 100644 index 0000000000000..1faa2b7574c83 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash2.errors.txt @@ -0,0 +1,47 @@ +/app.ts(2,1): error TS2304: Cannot find name 'MODULE'. + + +==== /tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "declaration": true, + "emitDeclarationOnly": true, + "types": [] + } + } + +==== /app.ts (1 errors) ==== + /// + MODULE; // error + ~~~~~~ +!!! error TS2304: Cannot find name 'MODULE'. + SCRIPT; // ok + function foo() { + return SCRIPT; + } +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export {}; + declare global { + const MODULE: any; + } + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export {}; + declare global { + const SCRIPT: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTripleSlash2.js b/tests/baselines/reference/resolutionModeTripleSlash2.js new file mode 100644 index 0000000000000..e30b6cf9158ac --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash2.js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTripleSlash2.ts] //// + +//// [package.json] +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +//// [index.d.mts] +export {}; +declare global { + const MODULE: any; +} + +//// [index.d.cts] +export {}; +declare global { + const SCRIPT: any; +} + +//// [app.ts] +/// +MODULE; // error +SCRIPT; // ok +function foo() { + return SCRIPT; +} + + + +//// [app.d.ts] +declare function foo(): any; diff --git a/tests/baselines/reference/resolutionModeTripleSlash3.errors.txt b/tests/baselines/reference/resolutionModeTripleSlash3.errors.txt new file mode 100644 index 0000000000000..e0f57ac5b81c5 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash3.errors.txt @@ -0,0 +1,45 @@ +/app.ts(3,1): error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? + + +==== /tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "types": [] + } + } + +==== /app.ts (1 errors) ==== + /// + MODULE; // ok + SCRIPT; // error + ~~~~~~ +!!! error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? +!!! related TS2728 lib.scripthost.d.ts:--:--: 'WScript' is declared here. + +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export {}; + declare global { + const MODULE: any; + } + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export {}; + declare global { + const SCRIPT: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTripleSlash4.errors.txt b/tests/baselines/reference/resolutionModeTripleSlash4.errors.txt new file mode 100644 index 0000000000000..81626cc54b2f6 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash4.errors.txt @@ -0,0 +1,51 @@ +/app.ts(1,23): error TS2688: Cannot find type definition file for 'foo'. +/app.ts(2,1): error TS2304: Cannot find name 'MODULE'. +/app.ts(3,1): error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? + + +==== /tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "module": "esnext", + "moduleResolution": "node10", + "noEmit": true, + "types": [] + } + } + +==== /app.ts (3 errors) ==== + /// + ~~~ +!!! error TS2688: Cannot find type definition file for 'foo'. + MODULE; // error + ~~~~~~ +!!! error TS2304: Cannot find name 'MODULE'. + SCRIPT; // error + ~~~~~~ +!!! error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? +!!! related TS2728 lib.scripthost.d.ts:--:--: 'WScript' is declared here. + +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export {}; + declare global { + const MODULE: any; + } + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export {}; + declare global { + const SCRIPT: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTripleSlash5.errors.txt b/tests/baselines/reference/resolutionModeTripleSlash5.errors.txt new file mode 100644 index 0000000000000..6618295aa9e5c --- /dev/null +++ b/tests/baselines/reference/resolutionModeTripleSlash5.errors.txt @@ -0,0 +1,45 @@ +/app.ts(3,1): error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? + + +==== /tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "module": "esnext", + "moduleResolution": "node10", + "noEmit": true, + "types": [] + } + } + +==== /app.ts (1 errors) ==== + /// + MODULE; // ok + SCRIPT; // error + ~~~~~~ +!!! error TS2552: Cannot find name 'SCRIPT'. Did you mean 'WScript'? +!!! related TS2728 lib.scripthost.d.ts:--:--: 'WScript' is declared here. + +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export {}; + declare global { + const MODULE: any; + } + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export {}; + declare global { + const SCRIPT: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).js b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).js new file mode 100644 index 0000000000000..961512bfab79f --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).js @@ -0,0 +1,62 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +//// [package.json] +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +//// [index.d.mts] +export declare const x: "module"; + +//// [index.d.cts] +export declare const x: "script"; + +//// [app.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; + +export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative +} + +//// [other.ts] +export const x = "other"; + + + + +//// [other.d.ts] +export declare const x = "other"; +//// [app.d.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; +export { _Default, _Import, _Require, _ImportRelative, _RequireRelative }; diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).symbols b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).symbols new file mode 100644 index 0000000000000..1d28242ebf843 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).symbols @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +import type { x as Default } from "foo"; +>x : Symbol(Default, Decl(index.d.mts, 0, 20)) +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>x : Symbol(Default, Decl(index.d.mts, 0, 20)) +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>x : Symbol(Require, Decl(index.d.cts, 0, 20)) +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +type _Default = typeof Default; +>_Default : Symbol(_Default, Decl(app.ts, 2, 80)) +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +type _Import = typeof Import; +>_Import : Symbol(_Import, Decl(app.ts, 3, 31)) +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +type _Require = typeof Require; +>_Require : Symbol(_Require, Decl(app.ts, 4, 29)) +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 9, 92)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 10, 45)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +export { + _Default, +>_Default : Symbol(_Default, Decl(app.ts, 13, 8)) + + _Import, +>_Import : Symbol(_Import, Decl(app.ts, 14, 11)) + + _Require, +>_Require : Symbol(_Require, Decl(app.ts, 15, 10)) + + _ImportRelative, +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 16, 11)) + + _RequireRelative +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 17, 18)) +} + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).types b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).types new file mode 100644 index 0000000000000..404083065a83d --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=bundler).types @@ -0,0 +1,74 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +import type { x as Default } from "foo"; +>x : "module" +>Default : any + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>x : "module" +>Import : any + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>x : "script" +>Require : any + +type _Default = typeof Default; +>_Default : "module" +>Default : "module" + +type _Import = typeof Import; +>_Import : "module" +>Import : "module" + +type _Require = typeof Require; +>_Require : "script" +>Require : "script" + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : "other" +>ImportRelative : any + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : "other" +>RequireRelative : any + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : "other" +>ImportRelative : "other" + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : "other" +>RequireRelative : "other" + +export { + _Default, +>_Default : any + + _Import, +>_Import : any + + _Require, +>_Require : any + + _ImportRelative, +>_ImportRelative : any + + _RequireRelative +>_RequireRelative : any +} + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).errors.txt b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).errors.txt new file mode 100644 index 0000000000000..8e52a8e3c12ce --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).errors.txt @@ -0,0 +1,60 @@ +error TS2688: Cannot find type definition file for 'foo'. + The file is in the program because: + Entry point for implicit type library 'foo' +/app.ts(1,35): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +/app.ts(2,34): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +/app.ts(3,35): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + + +!!! error TS2688: Cannot find type definition file for 'foo'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point for implicit type library 'foo' +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export declare const x: "module"; + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export declare const x: "script"; + +==== /app.ts (3 errors) ==== + import type { x as Default } from "foo"; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + import type { x as Import } from "foo" assert { "resolution-mode": "import" }; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + import type { x as Require } from "foo" assert { "resolution-mode": "require" }; + ~~~~~ +!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + type _Default = typeof Default; + type _Import = typeof Import; + type _Require = typeof Require; + + // resolution-mode does not enforce file extension in `bundler`, just sets conditions + import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; + import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; + type _ImportRelative = typeof ImportRelative; + type _RequireRelative = typeof RequireRelative; + + export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative + } + +==== /other.ts (0 errors) ==== + export const x = "other"; + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).js b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).js new file mode 100644 index 0000000000000..961512bfab79f --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).js @@ -0,0 +1,62 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +//// [package.json] +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +//// [index.d.mts] +export declare const x: "module"; + +//// [index.d.cts] +export declare const x: "script"; + +//// [app.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; + +export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative +} + +//// [other.ts] +export const x = "other"; + + + + +//// [other.d.ts] +export declare const x = "other"; +//// [app.d.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; +export { _Default, _Import, _Require, _ImportRelative, _RequireRelative }; diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).symbols b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).symbols new file mode 100644 index 0000000000000..a9c303545a796 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).symbols @@ -0,0 +1,70 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +import type { x as Default } from "foo"; +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +type _Default = typeof Default; +>_Default : Symbol(_Default, Decl(app.ts, 2, 80)) +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +type _Import = typeof Import; +>_Import : Symbol(_Import, Decl(app.ts, 3, 31)) +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +type _Require = typeof Require; +>_Require : Symbol(_Require, Decl(app.ts, 4, 29)) +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 9, 92)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 10, 45)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +export { + _Default, +>_Default : Symbol(_Default, Decl(app.ts, 13, 8)) + + _Import, +>_Import : Symbol(_Import, Decl(app.ts, 14, 11)) + + _Require, +>_Require : Symbol(_Require, Decl(app.ts, 15, 10)) + + _ImportRelative, +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 16, 11)) + + _RequireRelative +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 17, 18)) +} + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).types b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).types new file mode 100644 index 0000000000000..fae95dc236b7a --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=classic).types @@ -0,0 +1,74 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +import type { x as Default } from "foo"; +>x : any +>Default : any + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>x : any +>Import : any + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>x : any +>Require : any + +type _Default = typeof Default; +>_Default : any +>Default : any + +type _Import = typeof Import; +>_Import : any +>Import : any + +type _Require = typeof Require; +>_Require : any +>Require : any + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : "other" +>ImportRelative : any + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : "other" +>RequireRelative : any + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : "other" +>ImportRelative : "other" + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : "other" +>RequireRelative : "other" + +export { + _Default, +>_Default : any + + _Import, +>_Import : any + + _Require, +>_Require : any + + _ImportRelative, +>_ImportRelative : any + + _RequireRelative +>_RequireRelative : any +} + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).errors.txt b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).errors.txt new file mode 100644 index 0000000000000..e0030925c182d --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).errors.txt @@ -0,0 +1,54 @@ +error TS2688: Cannot find type definition file for 'foo'. + The file is in the program because: + Entry point for implicit type library 'foo' +/app.ts(1,35): error TS2307: Cannot find module 'foo' or its corresponding type declarations. + + +!!! error TS2688: Cannot find type definition file for 'foo'. +!!! error TS2688: The file is in the program because: +!!! error TS2688: Entry point for implicit type library 'foo' +==== /node_modules/@types/foo/package.json (0 errors) ==== + { + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } + } + +==== /node_modules/@types/foo/index.d.mts (0 errors) ==== + export declare const x: "module"; + +==== /node_modules/@types/foo/index.d.cts (0 errors) ==== + export declare const x: "script"; + +==== /app.ts (1 errors) ==== + import type { x as Default } from "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. + import type { x as Import } from "foo" assert { "resolution-mode": "import" }; + import type { x as Require } from "foo" assert { "resolution-mode": "require" }; + type _Default = typeof Default; + type _Import = typeof Import; + type _Require = typeof Require; + + // resolution-mode does not enforce file extension in `bundler`, just sets conditions + import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; + import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; + type _ImportRelative = typeof ImportRelative; + type _RequireRelative = typeof RequireRelative; + + export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative + } + +==== /other.ts (0 errors) ==== + export const x = "other"; + \ No newline at end of file diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).js b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).js new file mode 100644 index 0000000000000..961512bfab79f --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).js @@ -0,0 +1,62 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +//// [package.json] +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +//// [index.d.mts] +export declare const x: "module"; + +//// [index.d.cts] +export declare const x: "script"; + +//// [app.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; + +export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative +} + +//// [other.ts] +export const x = "other"; + + + + +//// [other.d.ts] +export declare const x = "other"; +//// [app.d.ts] +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; +export { _Default, _Import, _Require, _ImportRelative, _RequireRelative }; diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).symbols b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).symbols new file mode 100644 index 0000000000000..fd0c9f96b57a3 --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).symbols @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : Symbol(x, Decl(index.d.mts, 0, 20)) + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : Symbol(x, Decl(index.d.cts, 0, 20)) + +=== /app.ts === +import type { x as Default } from "foo"; +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>x : Symbol(Import, Decl(index.d.mts, 0, 20)) +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>x : Symbol(Require, Decl(index.d.cts, 0, 20)) +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +type _Default = typeof Default; +>_Default : Symbol(_Default, Decl(app.ts, 2, 80)) +>Default : Symbol(Default, Decl(app.ts, 0, 13)) + +type _Import = typeof Import; +>_Import : Symbol(_Import, Decl(app.ts, 3, 31)) +>Import : Symbol(Import, Decl(app.ts, 1, 13)) + +type _Require = typeof Require; +>_Require : Symbol(_Require, Decl(app.ts, 4, 29)) +>Require : Symbol(Require, Decl(app.ts, 2, 13)) + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : Symbol(ImportRelative, Decl(other.ts, 0, 12)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 9, 92)) +>ImportRelative : Symbol(ImportRelative, Decl(app.ts, 8, 13)) + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 10, 45)) +>RequireRelative : Symbol(RequireRelative, Decl(app.ts, 9, 13)) + +export { + _Default, +>_Default : Symbol(_Default, Decl(app.ts, 13, 8)) + + _Import, +>_Import : Symbol(_Import, Decl(app.ts, 14, 11)) + + _Require, +>_Require : Symbol(_Require, Decl(app.ts, 15, 10)) + + _ImportRelative, +>_ImportRelative : Symbol(_ImportRelative, Decl(app.ts, 16, 11)) + + _RequireRelative +>_RequireRelative : Symbol(_RequireRelative, Decl(app.ts, 17, 18)) +} + +=== /other.ts === +export const x = "other"; +>x : Symbol(x, Decl(other.ts, 0, 12)) + diff --git a/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).types b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).types new file mode 100644 index 0000000000000..6e1edbf27b29d --- /dev/null +++ b/tests/baselines/reference/resolutionModeTypeOnlyImport1(moduleresolution=node10).types @@ -0,0 +1,74 @@ +//// [tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts] //// + +=== /node_modules/@types/foo/index.d.mts === +export declare const x: "module"; +>x : "module" + +=== /node_modules/@types/foo/index.d.cts === +export declare const x: "script"; +>x : "script" + +=== /app.ts === +import type { x as Default } from "foo"; +>x : any +>Default : any + +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +>x : "module" +>Import : any + +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +>x : "script" +>Require : any + +type _Default = typeof Default; +>_Default : any +>Default : any + +type _Import = typeof Import; +>_Import : "module" +>Import : "module" + +type _Require = typeof Require; +>_Require : "script" +>Require : "script" + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +>x : "other" +>ImportRelative : any + +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +>x : "other" +>RequireRelative : any + +type _ImportRelative = typeof ImportRelative; +>_ImportRelative : "other" +>ImportRelative : "other" + +type _RequireRelative = typeof RequireRelative; +>_RequireRelative : "other" +>RequireRelative : "other" + +export { + _Default, +>_Default : any + + _Import, +>_Import : any + + _Require, +>_Require : any + + _ImportRelative, +>_ImportRelative : any + + _RequireRelative +>_RequireRelative : any +} + +=== /other.ts === +export const x = "other"; +>x : "other" +>"other" : "other" + diff --git a/tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts b/tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts new file mode 100644 index 0000000000000..9c29af37a654e --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts @@ -0,0 +1,32 @@ +// @module: esnext +// @moduleResolution: bundler, node10, classic +// @noEmit: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export declare const x: "module"; + +// @Filename: /node_modules/@types/foo/index.d.cts +export declare const x: "script"; + +// @Filename: /app.ts +type Default = typeof import("foo").x; +type Import = typeof import("foo", { assert: { "resolution-mode": "import" } }).x; +type Require = typeof import("foo", { assert: { "resolution-mode": "require" } }).x; +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +type ImportRelative = typeof import("./other", { assert: { "resolution-mode": "import" } }).x; +type RequireRelative = typeof import("./other", { assert: { "resolution-mode": "require" } }).x; + +// @Filename: /other.ts +export const x = "other"; diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash1.ts b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash1.ts new file mode 100644 index 0000000000000..2049afd48718d --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash1.ts @@ -0,0 +1,40 @@ +// @noTypesAndSymbols: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export {}; +declare global { + const MODULE: any; +} + +//@Filename: /node_modules/@types/foo/index.d.cts +export {}; +declare global { + const SCRIPT: any; +} + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "types": [] + } +} + +// @Filename: /app.ts +/// +MODULE; // ok +SCRIPT; // error diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash2.ts b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash2.ts new file mode 100644 index 0000000000000..ed87315448da3 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash2.ts @@ -0,0 +1,44 @@ +// @noTypesAndSymbols: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export {}; +declare global { + const MODULE: any; +} + +//@Filename: /node_modules/@types/foo/index.d.cts +export {}; +declare global { + const SCRIPT: any; +} + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "declaration": true, + "emitDeclarationOnly": true, + "types": [] + } +} + +// @Filename: /app.ts +/// +MODULE; // error +SCRIPT; // ok +function foo() { + return SCRIPT; +} \ No newline at end of file diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash3.ts b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash3.ts new file mode 100644 index 0000000000000..8f3516eb89e59 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash3.ts @@ -0,0 +1,40 @@ +// @noTypesAndSymbols: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export {}; +declare global { + const MODULE: any; +} + +//@Filename: /node_modules/@types/foo/index.d.cts +export {}; +declare global { + const SCRIPT: any; +} + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "types": [] + } +} + +// @Filename: /app.ts +/// +MODULE; // ok +SCRIPT; // error diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash4.ts b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash4.ts new file mode 100644 index 0000000000000..3602b1df25016 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash4.ts @@ -0,0 +1,40 @@ +// @noTypesAndSymbols: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export {}; +declare global { + const MODULE: any; +} + +//@Filename: /node_modules/@types/foo/index.d.cts +export {}; +declare global { + const SCRIPT: any; +} + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "node10", + "noEmit": true, + "types": [] + } +} + +// @Filename: /app.ts +/// +MODULE; // error +SCRIPT; // error diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash5.ts b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash5.ts new file mode 100644 index 0000000000000..eee5023aebfec --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTripleSlash5.ts @@ -0,0 +1,40 @@ +// @noTypesAndSymbols: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export {}; +declare global { + const MODULE: any; +} + +//@Filename: /node_modules/@types/foo/index.d.cts +export {}; +declare global { + const SCRIPT: any; +} + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "esnext", + "moduleResolution": "node10", + "noEmit": true, + "types": [] + } +} + +// @Filename: /app.ts +/// +MODULE; // ok +SCRIPT; // error diff --git a/tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts b/tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts new file mode 100644 index 0000000000000..24ccc38c0034d --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolutionModeTypeOnlyImport1.ts @@ -0,0 +1,47 @@ +// @module: esnext +// @moduleResolution: bundler, node10, classic +// @declaration: true +// @emitDeclarationOnly: true + +// @Filename: /node_modules/@types/foo/package.json +{ + "name": "@types/foo", + "version": "1.0.0", + "exports": { + ".": { + "import": "./index.d.mts", + "require": "./index.d.cts" + } + } +} + +// @Filename: /node_modules/@types/foo/index.d.mts +export declare const x: "module"; + +// @Filename: /node_modules/@types/foo/index.d.cts +export declare const x: "script"; + +// @Filename: /app.ts +import type { x as Default } from "foo"; +import type { x as Import } from "foo" assert { "resolution-mode": "import" }; +import type { x as Require } from "foo" assert { "resolution-mode": "require" }; +type _Default = typeof Default; +type _Import = typeof Import; +type _Require = typeof Require; + +// resolution-mode does not enforce file extension in `bundler`, just sets conditions +import type { x as ImportRelative } from "./other" assert { "resolution-mode": "import" }; +import type { x as RequireRelative } from "./other" assert { "resolution-mode": "require" }; +type _ImportRelative = typeof ImportRelative; +type _RequireRelative = typeof RequireRelative; + +export { + _Default, + _Import, + _Require, + _ImportRelative, + _RequireRelative +} + +// @Filename: /other.ts +export const x = "other"; diff --git a/tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.ts b/tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.ts index 19e37f389adbb..96876c10b4809 100644 --- a/tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.ts +++ b/tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.ts @@ -23,6 +23,6 @@ declare global { // @filename: /index.ts /// /// -foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary +foo; bar; export {}; \ No newline at end of file