diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dbe53a978c6ed..8c1b1d2550435 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -248,6 +248,7 @@ import { getAllJSDocTags, getAllowSyntheticDefaultImports, getAncestor, + getAnyExtensionFromPath, getAssignedExpandoInitializer, getAssignmentDeclarationKind, getAssignmentDeclarationPropertyAccessKind, @@ -259,6 +260,7 @@ import { getCombinedLocalAndExportSymbolFlags, getCombinedModifierFlags, getCombinedNodeFlags, + getCommonSourceDirectoryOfConfig, getContainingClass, getContainingClassExcludingClassDecorators, getContainingClassStaticBlock, @@ -352,6 +354,8 @@ import { getPropertyAssignmentAliasLikeExpression, getPropertyNameForPropertyNameNode, getPropertyNameFromType, + getRelativePathFromDirectory, + getRelativePathFromFile, getResolutionDiagnostic, getResolutionModeOverride, getResolveJsonModule, @@ -414,6 +418,7 @@ import { hasSyntacticModifiers, hasType, HeritageClause, + hostGetCanonicalFileName, Identifier, identifierToKeywordKind, IdentifierTypePredicate, @@ -693,6 +698,7 @@ import { isParenthesizedTypeNode, isPartOfParameterDeclaration, isPartOfTypeNode, + isPartOfTypeOnlyImportOrExportDeclaration, isPartOfTypeQuery, isPlainJsFile, isPrefixUnaryExpression, @@ -994,6 +1000,7 @@ import { ShorthandPropertyAssignment, shouldAllowImportingTsExtension, shouldPreserveConstEnums, + shouldRewriteModuleSpecifier, Signature, SignatureDeclaration, SignatureFlags, @@ -1007,6 +1014,7 @@ import { skipTypeParentheses, some, SourceFile, + sourceFileMayBeEmitted, SpreadAssignment, SpreadElement, startsWith, @@ -4665,6 +4673,45 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension); } } + else if ( + compilerOptions.rewriteRelativeImportExtensions + && !(location.flags & NodeFlags.Ambient) + && !isDeclarationFileName(moduleReference) + && !isLiteralImportTypeNode(location) + && !isPartOfTypeOnlyImportOrExportDeclaration(location) + ) { + const shouldRewrite = shouldRewriteModuleSpecifier(moduleReference, compilerOptions); + if (!resolvedModule.resolvedUsingTsExtension && shouldRewrite) { + error( + errorNode, + Diagnostics.This_relative_import_path_is_unsafe_to_rewrite_because_it_looks_like_a_file_name_but_actually_resolves_to_0, + getRelativePathFromFile(getNormalizedAbsolutePath(currentSourceFile.fileName, host.getCurrentDirectory()), resolvedModule.resolvedFileName, hostGetCanonicalFileName(host)), + ); + } + else if (resolvedModule.resolvedUsingTsExtension && !shouldRewrite && sourceFileMayBeEmitted(sourceFile, host)) { + error( + errorNode, + Diagnostics.This_import_uses_a_0_extension_to_resolve_to_an_input_TypeScript_file_but_will_not_be_rewritten_during_emit_because_it_is_not_a_relative_path, + getAnyExtensionFromPath(moduleReference), + ); + } + else if (resolvedModule.resolvedUsingTsExtension && shouldRewrite) { + const redirect = host.getResolvedProjectReferenceToRedirect(sourceFile.path); + if (redirect) { + const ignoreCase = !host.useCaseSensitiveFileNames(); + const ownRootDir = host.getCommonSourceDirectory(); + const otherRootDir = getCommonSourceDirectoryOfConfig(redirect.commandLine, ignoreCase); + const rootDirPath = getRelativePathFromDirectory(ownRootDir, otherRootDir, ignoreCase); + const outDirPath = getRelativePathFromDirectory(compilerOptions.outDir || ownRootDir, redirect.commandLine.options.outDir || otherRootDir, ignoreCase); + if (rootDirPath !== outDirPath) { + error( + errorNode, + Diagnostics.This_import_path_is_unsafe_to_rewrite_because_it_resolves_to_another_project_and_the_relative_path_between_the_projects_output_files_is_not_the_same_as_the_relative_path_between_its_input_files, + ); + } + } + } + } if (sourceFile.symbol) { if (errorNode && resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) { @@ -50871,6 +50918,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return ["__propKey"]; case ExternalEmitHelpers.AddDisposableResourceAndDisposeResources: return ["__addDisposableResource", "__disposeResources"]; + case ExternalEmitHelpers.RewriteRelativeImportExtension: + return ["__rewriteRelativeImportExtension"]; default: return Debug.fail("Unrecognized helper"); } @@ -52911,7 +52960,7 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host: TypeCheckerHo getCurrentDirectory: () => host.getCurrentDirectory(), getSymlinkCache: maybeBind(host, host.getSymlinkCache), getPackageJsonInfoCache: () => host.getPackageJsonInfoCache?.(), - useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames), + useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), redirectTargetsMap: host.redirectTargetsMap, getProjectReferenceRedirect: fileName => host.getProjectReferenceRedirect(fileName), isSourceOfProjectReferenceRedirect: fileName => host.isSourceOfProjectReferenceRedirect(fileName), diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 45a68c12e9db6..6bb5e981e0470 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1177,6 +1177,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ defaultValueDescription: false, transpileOptionValue: undefined, }, + { + name: "rewriteRelativeImportExtensions", + type: "boolean", + affectsSemanticDiagnostics: true, + affectsBuildInfo: true, + category: Diagnostics.Modules, + description: Diagnostics.Rewrite_ts_tsx_mts_and_cts_file_extensions_in_relative_import_paths_to_their_JavaScript_equivalent_in_output_files, + defaultValueDescription: false, + }, { name: "resolvePackageJsonExports", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a2e1eea633fb9..0159afd496de7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3964,6 +3964,18 @@ "category": "Error", "code": 2875 }, + "This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to \"{0}\".": { + "category": "Error", + "code": 2876 + }, + "This import uses a '{0}' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path.": { + "category": "Error", + "code": 2877 + }, + "This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files.": { + "category": "Error", + "code": 2878 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -5947,6 +5959,10 @@ "category": "Message", "code": 6420 }, + "Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files.": { + "category": "Message", + "code": 6421 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/factory/emitHelpers.ts b/src/compiler/factory/emitHelpers.ts index 722e408e0743b..2dc6a55441e8b 100644 --- a/src/compiler/factory/emitHelpers.ts +++ b/src/compiler/factory/emitHelpers.ts @@ -23,6 +23,7 @@ import { isCallExpression, isComputedPropertyName, isIdentifier, + JsxEmit, memoize, ObjectLiteralElementLike, ParameterDeclaration, @@ -139,6 +140,8 @@ export interface EmitHelperFactory { // 'using' helpers createAddDisposableResourceHelper(envBinding: Expression, value: Expression, async: boolean): Expression; createDisposeResourcesHelper(envBinding: Expression): Expression; + // --rewriteRelativeImportExtensions helpers + createRewriteRelativeImportExtensionsHelper(expression: Expression): Expression; } /** @internal */ @@ -189,6 +192,8 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel // 'using' helpers createAddDisposableResourceHelper, createDisposeResourcesHelper, + // --rewriteRelativeImportExtensions helpers + createRewriteRelativeImportExtensionsHelper, }; /** @@ -682,6 +687,17 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel context.requestEmitHelper(disposeResourcesHelper); return factory.createCallExpression(getUnscopedHelperName("__disposeResources"), /*typeArguments*/ undefined, [envBinding]); } + + function createRewriteRelativeImportExtensionsHelper(expression: Expression) { + context.requestEmitHelper(rewriteRelativeImportExtensionsHelper); + return factory.createCallExpression( + getUnscopedHelperName("__rewriteRelativeImportExtension"), + /*typeArguments*/ undefined, + context.getCompilerOptions().jsx === JsxEmit.Preserve + ? [expression, factory.createTrue()] + : [expression], + ); + } } /** @internal */ @@ -1422,6 +1438,21 @@ const disposeResourcesHelper: UnscopedEmitHelper = { });`, }; +const rewriteRelativeImportExtensionsHelper: UnscopedEmitHelper = { + name: "typescript:rewriteRelativeImportExtensions", + importName: "__rewriteRelativeImportExtension", + scoped: false, + text: ` + var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\\.\\.?\\//.test(path)) { + return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; + };`, +}; + /** @internal */ export const asyncSuperHelper: EmitHelper = { name: "typescript:async-super", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index aedc7beca8c47..75dd9a5465764 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -36,6 +36,7 @@ import { forEach, forEachAncestorDirectory, formatMessage, + getAllowImportingTsExtensions, getAllowJSCompilerOption, getAnyExtensionFromPath, getBaseFileName, @@ -1484,7 +1485,7 @@ export function resolveModuleName(moduleName: string, containingFile: string, co * 'typings' entry or file 'index' with some supported extension * - Classic loader will only try to interpret '/a/b/c' as file. */ -type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined; +type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState, packageJsonValue?: string) => Resolved | undefined; /** * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to @@ -2094,13 +2095,14 @@ function loadModuleFromFileNoImplicitExtensions(extensions: Extensions, candidat * module specifiers written in source files - and so it always allows the * candidate to end with a TS extension (but will also try substituting a JS extension for a TS extension). */ -function loadFileNameFromPackageJsonField(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined { +function loadFileNameFromPackageJsonField(extensions: Extensions, candidate: string, packageJsonValue: string | undefined, onlyRecordFailures: boolean, state: ModuleResolutionState): PathAndExtension | undefined { if ( extensions & Extensions.TypeScript && fileExtensionIsOneOf(candidate, supportedTSImplementationExtensions) || extensions & Extensions.Declaration && fileExtensionIsOneOf(candidate, supportedDeclarationExtensions) ) { const result = tryFile(candidate, onlyRecordFailures, state); - return result !== undefined ? { path: candidate, ext: tryExtractTSExtension(candidate) as Extension, resolvedUsingTsExtension: undefined } : undefined; + const ext = tryExtractTSExtension(candidate) as Extension; + return result !== undefined ? { path: candidate, ext, resolvedUsingTsExtension: packageJsonValue ? !endsWith(packageJsonValue, ext) : undefined } : undefined; } if (state.isConfigLookup && extensions === Extensions.Json && fileExtensionIs(candidate, Extension.Json)) { @@ -2316,7 +2318,7 @@ function loadEntrypointsFromExportMap( } const resolvedTarget = combinePaths(scope.packageDirectory, target); const finalPath = getNormalizedAbsolutePath(resolvedTarget, state.host.getCurrentDirectory?.()); - const result = loadFileNameFromPackageJsonField(extensions, finalPath, /*onlyRecordFailures*/ false, state); + const result = loadFileNameFromPackageJsonField(extensions, finalPath, target, /*onlyRecordFailures*/ false, state); if (result) { entrypoints = appendIfUnique(entrypoints, result, (a, b) => a.path === b.path); return true; @@ -2487,7 +2489,7 @@ function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: st } const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => { - const fromFile = loadFileNameFromPackageJsonField(extensions, candidate, onlyRecordFailures, state); + const fromFile = loadFileNameFromPackageJsonField(extensions, candidate, /*packageJsonValue*/ undefined, onlyRecordFailures, state); if (fromFile) { return noPackageId(fromFile); } @@ -2790,7 +2792,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo const finalPath = toAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath); const inputLink = tryLoadInputFileForPath(finalPath, subpath, combinePaths(scope.packageDirectory, "package.json"), isImports); if (inputLink) return inputLink; - return toSearchResult(withPackageId(scope, loadFileNameFromPackageJsonField(extensions, finalPath, /*onlyRecordFailures*/ false, state), state)); + return toSearchResult(withPackageId(scope, loadFileNameFromPackageJsonField(extensions, finalPath, target, /*onlyRecordFailures*/ false, state), state)); } else if (typeof target === "object" && target !== null) { // eslint-disable-line no-restricted-syntax if (!Array.isArray(target)) { @@ -2936,7 +2938,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo if (!extensionIsOk(extensions, possibleExt)) continue; const possibleInputWithInputExtension = changeAnyExtension(possibleInputBase, possibleExt, ext, !useCaseSensitiveFileNames(state)); if (state.host.fileExists(possibleInputWithInputExtension)) { - return toSearchResult(withPackageId(scope, loadFileNameFromPackageJsonField(extensions, possibleInputWithInputExtension, /*onlyRecordFailures*/ false, state), state)); + return toSearchResult(withPackageId(scope, loadFileNameFromPackageJsonField(extensions, possibleInputWithInputExtension, /*packageJsonValue*/ undefined, /*onlyRecordFailures*/ false, state), state)); } } } @@ -3333,7 +3335,7 @@ function resolveFromTypeRoot(moduleName: string, state: ModuleResolutionState) { // so this function doesn't check them to avoid propagating errors. /** @internal */ export function shouldAllowImportingTsExtension(compilerOptions: CompilerOptions, fromFileName?: string): boolean { - return !!compilerOptions.allowImportingTsExtensions || !!fromFileName && isDeclarationFileName(fromFileName); + return getAllowImportingTsExtensions(compilerOptions) || !!fromFileName && isDeclarationFileName(fromFileName); } /** diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ebc23493b4f72..45d8539f581e3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -99,8 +99,8 @@ import { flatten, forEach, forEachAncestorDirectory, - forEachChild, forEachChildRecursively, + forEachDynamicImportOrRequireCall, forEachEmittedFile, forEachEntry, forEachKey, @@ -162,7 +162,6 @@ import { hasExtension, HasInvalidatedLibResolutions, HasInvalidatedResolutions, - hasJSDocNodes, hasJSFileExtension, hasJsonModuleEmitEnabled, hasProperty, @@ -200,7 +199,6 @@ import { isImportTypeNode, isInJSFile, isJSDocImportTag, - isLiteralImportTypeNode, isModifier, isModuleDeclaration, isObjectLiteralExpression, @@ -3521,7 +3519,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } if ((file.flags & NodeFlags.PossiblyContainsDynamicImport) || isJavaScriptFile) { - collectDynamicImportOrRequireOrJsDocImportCalls(file); + forEachDynamicImportOrRequireCall(file, /*includeTypeSpaceImports*/ true, /*requireStringLiteralLikeArgument*/ true, (node, moduleSpecifier) => { + 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, moduleSpecifier); + }); } file.imports = imports || emptyArray; @@ -3584,50 +3585,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } } } - - function collectDynamicImportOrRequireOrJsDocImportCalls(file: SourceFile) { - const r = /import|require/g; - while (r.exec(file.text) !== null) { // eslint-disable-line no-restricted-syntax - const node = getNodeAtPosition(file, r.lastIndex); - if (isJavaScriptFile && isRequireCall(node, /*requireStringLiteralLikeArgument*/ 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 at least 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); - } - else if (isJavaScriptFile && isJSDocImportTag(node)) { - const moduleNameExpr = getExternalModuleName(node); - if (moduleNameExpr && isStringLiteral(moduleNameExpr) && moduleNameExpr.text) { - setParentRecursive(node, /*incremental*/ false); - imports = append(imports, moduleNameExpr); - } - } - } - } - - /** Returns a token if position is in [start-of-leading-trivia, end), includes JSDoc only in JS files */ - function getNodeAtPosition(sourceFile: SourceFile, position: number): Node { - let current: Node = sourceFile; - const getContainingChild = (child: Node) => { - if (child.pos <= position && (position < child.end || (position === child.end && (child.kind === SyntaxKind.EndOfFileToken)))) { - return child; - } - }; - while (true) { - const child = isJavaScriptFile && hasJSDocNodes(current) && forEach(current.jsDoc, getContainingChild) || forEachChild(current, getContainingChild); - if (!child) { - return current; - } - current = child; - } - } } function getLibFileFromReference(ref: FileReference) { @@ -4557,7 +4514,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } } - if (options.allowImportingTsExtensions && !(options.noEmit || options.emitDeclarationOnly)) { + if (options.allowImportingTsExtensions && !(options.noEmit || options.emitDeclarationOnly || options.rewriteRelativeImportExtensions)) { createOptionValueDiagnostic("allowImportingTsExtensions", Diagnostics.Option_allowImportingTsExtensions_can_only_be_used_when_either_noEmit_or_emitDeclarationOnly_is_set); } diff --git a/src/compiler/transformers/module/esnextAnd2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts index f36388bf8983b..2f2d23c468089 100644 --- a/src/compiler/transformers/module/esnextAnd2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -1,7 +1,9 @@ import { + addEmitHelpers, addRange, append, Bundle, + CallExpression, chainBundle, createEmptyExports, createExternalHelpersImportDeclarationIfNeeded, @@ -12,6 +14,7 @@ import { ExportDeclaration, Expression, ExpressionStatement, + forEachDynamicImportOrRequireCall, GeneratedIdentifierFlags, getEmitFlags, getEmitModuleKind, @@ -31,17 +34,22 @@ import { isExternalModuleImportEqualsDeclaration, isExternalModuleIndicator, isIdentifier, + isInJSFile, isNamespaceExport, isSourceFile, isStatement, + isStringLiteralLike, ModifierFlags, ModuleKind, Node, NodeFlags, NodeId, + rangeContainsRange, + rewriteModuleSpecifier, ScriptTarget, setOriginalNode, setTextRange, + shouldRewriteModuleSpecifier, singleOrMany, some, SourceFile, @@ -73,6 +81,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S context.enableSubstitution(SyntaxKind.Identifier); const noSubstitution = new Set(); + let importsAndRequiresToRewriteOrShim: CallExpression[] | undefined; let helperNameSubstitutions: Map | undefined; let currentSourceFile: SourceFile | undefined; let importRequireStatements: [ImportDeclaration, VariableStatement] | undefined; @@ -86,7 +95,15 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S if (isExternalModule(node) || getIsolatedModules(compilerOptions)) { currentSourceFile = node; importRequireStatements = undefined; + if (compilerOptions.rewriteRelativeImportExtensions && (currentSourceFile.flags & NodeFlags.PossiblyContainsDynamicImport || isInJSFile(node))) { + forEachDynamicImportOrRequireCall(node, /*includeTypeSpaceImports*/ false, /*requireStringLiteralLikeArgument*/ false, node => { + if (!isStringLiteralLike(node.arguments[0]) || shouldRewriteModuleSpecifier(node.arguments[0].text, compilerOptions)) { + importsAndRequiresToRewriteOrShim = append(importsAndRequiresToRewriteOrShim, node); + } + }); + } let result = updateExternalModule(node); + addEmitHelpers(result, context.readEmitHelpers()); currentSourceFile = undefined; if (importRequireStatements) { result = factory.updateSourceFile( @@ -135,11 +152,53 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S case SyntaxKind.ExportDeclaration: const exportDecl = node as ExportDeclaration; return visitExportDeclaration(exportDecl); + case SyntaxKind.ImportDeclaration: + return visitImportDeclaration(node as ImportDeclaration); + case SyntaxKind.CallExpression: + if (node === importsAndRequiresToRewriteOrShim?.[0]) { + return visitImportOrRequireCall(importsAndRequiresToRewriteOrShim.shift()!); + } + break; + default: + if (importsAndRequiresToRewriteOrShim?.length && rangeContainsRange(node, importsAndRequiresToRewriteOrShim[0])) { + return visitEachChild(node, visitor, context); + } } return node; } + function visitImportDeclaration(node: ImportDeclaration): VisitResult { + if (!compilerOptions.rewriteRelativeImportExtensions) { + return node; + } + const updatedModuleSpecifier = rewriteModuleSpecifier(node.moduleSpecifier, compilerOptions); + if (updatedModuleSpecifier === node.moduleSpecifier) { + return node; + } + return factory.updateImportDeclaration( + node, + node.modifiers, + node.importClause, + updatedModuleSpecifier, + node.attributes, + ); + } + + function visitImportOrRequireCall(node: CallExpression): VisitResult { + return factory.updateCallExpression( + node, + node.expression, + node.typeArguments, + [ + isStringLiteralLike(node.arguments[0]) + ? rewriteModuleSpecifier(node.arguments[0], compilerOptions) + : emitHelpers().createRewriteRelativeImportExtensionsHelper(node.arguments[0]), + ...node.arguments.slice(1), + ], + ); + } + /** * Creates a `require()` call to import an external module. * @@ -149,7 +208,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S const moduleName = getExternalModuleNameLiteral(factory, importNode, Debug.checkDefined(currentSourceFile), host, resolver, compilerOptions); const args: Expression[] = []; if (moduleName) { - args.push(moduleName); + args.push(rewriteModuleSpecifier(moduleName, compilerOptions)); } if (getEmitModuleKind(compilerOptions) === ModuleKind.Preserve) { return factory.createCallExpression(factory.createIdentifier("require"), /*typeArguments*/ undefined, args); @@ -270,14 +329,21 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S } function visitExportDeclaration(node: ExportDeclaration) { - // `export * as ns` only needs to be transformed in ES2015 - if (compilerOptions.module !== undefined && compilerOptions.module > ModuleKind.ES2015) { - return node; - } - - // Either ill-formed or don't need to be tranformed. - if (!node.exportClause || !isNamespaceExport(node.exportClause) || !node.moduleSpecifier) { - return node; + const updatedModuleSpecifier = rewriteModuleSpecifier(node.moduleSpecifier, compilerOptions); + if ( + (compilerOptions.module !== undefined && compilerOptions.module > ModuleKind.ES2015) + || !node.exportClause || !isNamespaceExport(node.exportClause) || !node.moduleSpecifier + ) { + // Either ill-formed or don't need to be tranformed. + return (!node.moduleSpecifier || updatedModuleSpecifier === node.moduleSpecifier) ? node : + factory.updateExportDeclaration( + node, + node.modifiers, + node.isTypeOnly, + node.exportClause, + updatedModuleSpecifier, + node.attributes, + ); } const oldIdentifier = node.exportClause.name; @@ -291,7 +357,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S synthName, ), ), - node.moduleSpecifier, + updatedModuleSpecifier!, node.attributes, ); setOriginalNode(importDecl, node.exportClause); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index be0cf4bdf85c2..ae0d2a0aaa87c 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -34,6 +34,7 @@ import { firstOrUndefined, flattenDestructuringAssignment, FlattenLevel, + forEachDynamicImportOrRequireCall, ForInStatement, ForOfStatement, ForStatement, @@ -114,6 +115,7 @@ import { isSpreadElement, isStatement, isStringLiteral, + isStringLiteralLike, isVariableDeclaration, isVariableDeclarationList, LabeledStatement, @@ -136,11 +138,13 @@ import { PrefixUnaryExpression, reduceLeft, removeAllComments, + rewriteModuleSpecifier, ScriptTarget, setEmitFlags, setOriginalNode, setTextRange, ShorthandPropertyAssignment, + shouldRewriteModuleSpecifier, singleOrMany, some, SourceFile, @@ -213,6 +217,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile let currentSourceFile: SourceFile; // The current file. let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file. + let importsAndRequiresToRewriteOrShim: CallExpression[] | undefined; const noSubstitution: boolean[] = []; // Set of nodes for which substitution rules should be ignored. let needUMDDynamicImportHelper: boolean; @@ -236,6 +241,13 @@ export function transformModule(context: TransformationContext): (x: SourceFile currentSourceFile = node; currentModuleInfo = collectExternalModuleInfo(context, node); moduleInfoMap[getOriginalNodeId(node)] = currentModuleInfo; + if (compilerOptions.rewriteRelativeImportExtensions) { + forEachDynamicImportOrRequireCall(node, /*includeTypeSpaceImports*/ false, /*requireStringLiteralLikeArgument*/ false, node => { + if (!isStringLiteralLike(node.arguments[0]) || shouldRewriteModuleSpecifier(node.arguments[0].text, compilerOptions)) { + importsAndRequiresToRewriteOrShim = append(importsAndRequiresToRewriteOrShim, node); + } + }); + } // Perform the transformation. const transformModule = getTransformModuleDelegate(moduleKind); @@ -783,7 +795,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile function visitorWorker(node: Node, valueIsDiscarded: boolean): VisitResult { // This visitor does not need to descend into the tree if there is no dynamic import, destructuring assignment, or update expression // as export/import statements are only transformed at the top level of a file. - if (!(node.transformFlags & (TransformFlags.ContainsDynamicImport | TransformFlags.ContainsDestructuringAssignment | TransformFlags.ContainsUpdateExpressionForIdentifier))) { + if (!(node.transformFlags & (TransformFlags.ContainsDynamicImport | TransformFlags.ContainsDestructuringAssignment | TransformFlags.ContainsUpdateExpressionForIdentifier)) && !importsAndRequiresToRewriteOrShim?.length) { return node; } @@ -797,8 +809,15 @@ export function transformModule(context: TransformationContext): (x: SourceFile case SyntaxKind.PartiallyEmittedExpression: return visitPartiallyEmittedExpression(node as PartiallyEmittedExpression, valueIsDiscarded); case SyntaxKind.CallExpression: + const needsRewrite = node === firstOrUndefined(importsAndRequiresToRewriteOrShim); + if (needsRewrite) { + importsAndRequiresToRewriteOrShim!.shift(); + } if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) { - return visitImportCallExpression(node); + return visitImportCallExpression(node, needsRewrite); + } + else if (needsRewrite) { + return shimOrRewriteImportOrRequireCall(node as CallExpression); } break; case SyntaxKind.BinaryExpression: @@ -1170,14 +1189,34 @@ export function transformModule(context: TransformationContext): (x: SourceFile return visitEachChild(node, visitor, context); } - function visitImportCallExpression(node: ImportCall): Expression { + function shimOrRewriteImportOrRequireCall(node: CallExpression): CallExpression { + return factory.updateCallExpression( + node, + node.expression, + /*typeArguments*/ undefined, + visitNodes(node.arguments, (arg: Expression) => { + if (arg === node.arguments[0]) { + return isStringLiteralLike(arg) + ? rewriteModuleSpecifier(arg, compilerOptions) + : emitHelpers().createRewriteRelativeImportExtensionsHelper(arg); + } + return visitor(arg); + }, isExpression), + ); + } + + function visitImportCallExpression(node: ImportCall, rewriteOrShim: boolean): Expression { if (moduleKind === ModuleKind.None && languageVersion >= ScriptTarget.ES2020) { return visitEachChild(node, visitor, context); } const externalModuleName = getExternalModuleNameLiteral(factory, node, currentSourceFile, host, resolver, compilerOptions); const firstArgument = visitNode(firstOrUndefined(node.arguments), visitor, isExpression); // Only use the external module name if it differs from the first argument. This allows us to preserve the quote style of the argument on output. - const argument = externalModuleName && (!firstArgument || !isStringLiteral(firstArgument) || firstArgument.text !== externalModuleName.text) ? externalModuleName : firstArgument; + const argument = externalModuleName && (!firstArgument || !isStringLiteral(firstArgument) || firstArgument.text !== externalModuleName.text) + ? externalModuleName + : firstArgument && rewriteOrShim + ? isStringLiteral(firstArgument) ? rewriteModuleSpecifier(firstArgument, compilerOptions) : emitHelpers().createRewriteRelativeImportExtensionsHelper(firstArgument) + : firstArgument; const containsLexicalThis = !!(node.transformFlags & TransformFlags.ContainsLexicalThis); switch (compilerOptions.module) { case ModuleKind.AMD: @@ -1500,7 +1539,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile const moduleName = getExternalModuleNameLiteral(factory, importNode, currentSourceFile, host, resolver, compilerOptions); const args: Expression[] = []; if (moduleName) { - args.push(moduleName); + args.push(rewriteModuleSpecifier(moduleName, compilerOptions)); } return factory.createCallExpression(factory.createIdentifier("require"), /*typeArguments*/ undefined, args); diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 75a6a34a55b1c..75656cf5aefab 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2343,7 +2343,14 @@ export function transformTypeScript(context: TransformationContext): Transformer // never elide `export from ` declarations - // they should be kept for sideffects/untyped exports, even when the // type checker doesn't know about any exports - return node; + return factory.updateExportDeclaration( + node, + node.modifiers, + node.isTypeOnly, + node.exportClause, + node.moduleSpecifier, + node.attributes, + ); } // Elide the export declaration if all of its named exports are elided. @@ -2422,8 +2429,10 @@ export function transformTypeScript(context: TransformationContext): Transformer } if (isExternalModuleImportEqualsDeclaration(node)) { - const isReferenced = shouldEmitAliasDeclaration(node); - return isReferenced ? visitEachChild(node, visitor, context) : undefined; + if (!shouldEmitAliasDeclaration(node)) { + return undefined; + } + return visitEachChild(node, visitor, context); } if (!shouldEmitImportEqualsDeclaration(node)) { diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 0079aa25aab16..0658ae8b857a2 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -7,11 +7,13 @@ import { BindingElement, Bundle, cast, + changeExtension, ClassDeclaration, ClassElement, ClassExpression, ClassLikeDeclaration, ClassStaticBlockDeclaration, + CompilerOptions, CompoundAssignmentOperator, CoreTransformationContext, createExternalHelpersImportDeclarationIfNeeded, @@ -21,6 +23,7 @@ import { ExportDeclaration, ExportSpecifier, Expression, + factory, filter, formatGeneratedName, FunctionDeclaration, @@ -33,6 +36,7 @@ import { getNodeForGeneratedName, getNodeId, getOriginalNode, + getOutputExtension, hasDecorators, hasStaticModifier, hasSyntacticModifier, @@ -61,6 +65,7 @@ import { isPrivateIdentifier, isPropertyDeclaration, isStatic, + isStringLiteral, isStringLiteralLike, isSuperCall, isTryStatement, @@ -83,6 +88,9 @@ import { PrivateIdentifierAutoAccessorPropertyDeclaration, PrivateIdentifierMethodDeclaration, PropertyDeclaration, + setOriginalNode, + setTextRange, + shouldRewriteModuleSpecifier, skipParentheses, some, SourceFile, @@ -863,3 +871,16 @@ function isSimpleParameter(node: ParameterDeclaration) { export function isSimpleParameterList(nodes: NodeArray): boolean { return every(nodes, isSimpleParameter); } + +/** @internal */ +export function rewriteModuleSpecifier(node: Expression, compilerOptions: CompilerOptions): Expression; +/** @internal */ +export function rewriteModuleSpecifier(node: Expression | undefined, compilerOptions: CompilerOptions): Expression | undefined; +/** @internal */ +export function rewriteModuleSpecifier(node: Expression | undefined, compilerOptions: CompilerOptions): Expression | undefined { + if (!node || !isStringLiteral(node) || !shouldRewriteModuleSpecifier(node.text, compilerOptions)) { + return node; + } + const updatedText = changeExtension(node.text, getOutputExtension(node.text, compilerOptions)); + return updatedText !== node.text ? setOriginalNode(setTextRange(factory.createStringLiteral(updatedText, node.singleQuote), node), node) : node; +} diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6f939a5989dcb..f9f3dc0adba58 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5016,7 +5016,7 @@ export interface EmitResult { } /** @internal */ -export interface TypeCheckerHost extends ModuleSpecifierResolutionHost { +export interface TypeCheckerHost extends ModuleSpecifierResolutionHost, SourceFileMayBeEmittedHost { getCompilerOptions(): CompilerOptions; getSourceFiles(): readonly SourceFile[]; @@ -7451,6 +7451,7 @@ export interface CompilerOptions { removeComments?: boolean; resolvePackageJsonExports?: boolean; resolvePackageJsonImports?: boolean; + rewriteRelativeImportExtensions?: boolean; rootDir?: string; rootDirs?: string[]; skipLibCheck?: boolean; @@ -8468,6 +8469,7 @@ export const enum ExternalEmitHelpers { SetFunctionName = 1 << 22, // __setFunctionName (used by class fields and ECMAScript decorators) PropKey = 1 << 23, // __propKey (used by class fields and ECMAScript decorators) AddDisposableResourceAndDisposeResources = 1 << 24, // __addDisposableResource and __disposeResources (used by ESNext transformations) + RewriteRelativeImportExtension = 1 << 25, // __rewriteRelativeImportExtension (used by --rewriteRelativeImportExtensions) FirstEmitHelper = Extends, LastEmitHelper = AddDisposableResourceAndDisposeResources, @@ -9890,7 +9892,7 @@ export interface HasCurrentDirectory { /** @internal */ export interface ModuleSpecifierResolutionHost { - useCaseSensitiveFileNames?(): boolean; + useCaseSensitiveFileNames(): boolean; fileExists(path: string): boolean; getCurrentDirectory(): string; directoryExists?(path: string): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f608adcb8d7e0..f1d10dccdf697 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -298,6 +298,7 @@ import { isJSDocAugmentsTag, isJSDocFunctionType, isJSDocImplementsTag, + isJSDocImportTag, isJSDocLinkLike, isJSDocMemberName, isJSDocNameReference, @@ -4302,6 +4303,11 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal } } +/** @internal */ +export function shouldRewriteModuleSpecifier(specifier: string, compilerOptions: CompilerOptions): boolean { + return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier); +} + /** @internal */ export function getExternalModuleName(node: AnyImportOrReExport | ImportTypeNode | ImportCall | ModuleDeclaration | JSDocImportTag): Expression | undefined { switch (node.kind) { @@ -7854,6 +7860,16 @@ export function getLinesBetweenPositionAndNextNonWhitespaceCharacter(pos: number return getLinesBetweenPositions(sourceFile, pos, Math.min(stopPos, nextPos)); } +/** @internal */ +export function rangeContainsRange(r1: TextRange, r2: TextRange): boolean { + return startEndContainsRange(r1.pos, r1.end, r2); +} + +/** @internal */ +export function startEndContainsRange(start: number, end: number, range: TextRange): boolean { + return start <= range.pos && end >= range.end; +} + function getPreviousNonWhitespacePosition(pos: number, stopPos = 0, sourceFile: SourceFile) { while (pos-- > stopPos) { if (!isWhiteSpaceLike(sourceFile.text.charCodeAt(pos))) { @@ -8900,6 +8916,12 @@ function createComputedCompilerOptions { + return !!(compilerOptions.allowImportingTsExtensions || compilerOptions.rewriteRelativeImportExtensions); + }, + }, target: { dependencies: ["module"], computeValue: compilerOptions => { @@ -9128,6 +9150,8 @@ const _computedOptions = createComputedCompilerOptions({ /** @internal */ export const computedOptions: Record CompilerOptionsValue; }> = _computedOptions; +/** @internal */ +export const getAllowImportingTsExtensions: (compilerOptions: CompilerOptions) => boolean = _computedOptions.allowImportingTsExtensions.computeValue; /** @internal */ export const getEmitScriptTarget: (compilerOptions: CompilerOptions) => ScriptTarget = _computedOptions.target.computeValue; /** @internal */ @@ -12004,3 +12028,50 @@ export const nodeCoreModules: Set = new Set([ ...unprefixedNodeCoreModulesList.map(name => `node:${name}`), ...exclusivelyPrefixedNodeCoreModules, ]); + +/** @internal */ +export function forEachDynamicImportOrRequireCall( + file: SourceFile, + includeTypeSpaceImports: IncludeTypeSpaceImports, + requireStringLiteralLikeArgument: RequireStringLiteralLikeArgument, + cb: (node: CallExpression | (IncludeTypeSpaceImports extends false ? never : JSDocImportTag | ImportTypeNode), argument: RequireStringLiteralLikeArgument extends true ? StringLiteralLike : Expression) => void, +): void { + const isJavaScriptFile = isInJSFile(file); + const r = /import|require/g; + while (r.exec(file.text) !== null) { // eslint-disable-line no-restricted-syntax + const node = getNodeAtPosition(file, r.lastIndex, /*includeJSDoc*/ includeTypeSpaceImports); + if (isJavaScriptFile && isRequireCall(node, requireStringLiteralLikeArgument)) { + cb(node, node.arguments[0] as RequireStringLiteralLikeArgument extends true ? StringLiteralLike : Expression); + } + else if (isImportCall(node) && node.arguments.length >= 1 && (!requireStringLiteralLikeArgument || isStringLiteralLike(node.arguments[0]))) { + cb(node, node.arguments[0] as RequireStringLiteralLikeArgument extends true ? StringLiteralLike : Expression); + } + else if (includeTypeSpaceImports && isLiteralImportTypeNode(node)) { + (cb as (node: CallExpression | JSDocImportTag | ImportTypeNode, argument: StringLiteralLike) => void)(node, node.argument.literal); + } + else if (includeTypeSpaceImports && isJSDocImportTag(node)) { + const moduleNameExpr = getExternalModuleName(node); + if (moduleNameExpr && isStringLiteral(moduleNameExpr) && moduleNameExpr.text) { + (cb as (node: CallExpression | JSDocImportTag | ImportTypeNode, argument: StringLiteralLike) => void)(node, moduleNameExpr); + } + } + } +} + +/** Returns a token if position is in [start-of-leading-trivia, end), includes JSDoc only in JS files */ +function getNodeAtPosition(sourceFile: SourceFile, position: number, includeJSDoc: boolean): Node { + const isJavaScriptFile = isInJSFile(sourceFile); + let current: Node = sourceFile; + const getContainingChild = (child: Node) => { + if (child.pos <= position && (position < child.end || (position === child.end && (child.kind === SyntaxKind.EndOfFileToken)))) { + return child; + } + }; + while (true) { + const child = isJavaScriptFile && includeJSDoc && hasJSDocNodes(current) && forEach(current.jsDoc, getContainingChild) || forEachChild(current, getContainingChild); + if (!child) { + return current; + } + current = child; + } +} diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 462ebc6da06d4..69971c94f27af 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1553,6 +1553,10 @@ export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnl return isTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node); } +export function isPartOfTypeOnlyImportOrExportDeclaration(node: Node): boolean { + return findAncestor(node, isTypeOnlyImportOrExportDeclaration) !== undefined; +} + export function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken { return node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index fe06adeb8b217..356c2878c90b8 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -320,6 +320,7 @@ import { PseudoBigInt, pseudoBigIntToString, QualifiedName, + rangeContainsRange, RefactorContext, removeFileExtension, removeSuffix, @@ -917,11 +918,6 @@ export function getLineStartPositionForPosition(position: number, sourceFile: So return lineStarts[line]; } -/** @internal */ -export function rangeContainsRange(r1: TextRange, r2: TextRange): boolean { - return startEndContainsRange(r1.pos, r1.end, r2); -} - /** @internal */ export function rangeContainsRangeExclusive(r1: TextRange, r2: TextRange): boolean { return rangeContainsPositionExclusive(r1, r2.pos) && rangeContainsPositionExclusive(r1, r2.end); @@ -937,11 +933,6 @@ export function rangeContainsPositionExclusive(r: TextRange, pos: number): boole return r.pos < pos && pos < r.end; } -/** @internal */ -export function startEndContainsRange(start: number, end: number, range: TextRange): boolean { - return start <= range.pos && end >= range.end; -} - /** @internal */ export function rangeContainsStartEnd(range: TextRange, start: number, end: number): boolean { return range.pos <= start && range.end >= end; @@ -2468,7 +2459,7 @@ export function createModuleSpecifierResolutionHost(program: Program, host: Lang fileExists: fileName => program.fileExists(fileName), getCurrentDirectory: () => host.getCurrentDirectory(), readFile: maybeBind(host, host.readFile), - useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames), + useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames) || program.useCaseSensitiveFileNames, getSymlinkCache: maybeBind(host, host.getSymlinkCache) || program.getSymlinkCache, getModuleSpecifierCache: maybeBind(host, host.getModuleSpecifierCache), getPackageJsonInfoCache: () => program.getModuleResolutionCache()?.getPackageJsonInfoCache(), diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 6ccd3eb32198a..11d8a931772c6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -7075,6 +7075,7 @@ declare namespace ts { removeComments?: boolean; resolvePackageJsonExports?: boolean; resolvePackageJsonImports?: boolean; + rewriteRelativeImportExtensions?: boolean; rootDir?: string; rootDirs?: string[]; skipLibCheck?: boolean; @@ -8750,6 +8751,7 @@ declare namespace ts { function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration; function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportDeclaration; function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyAliasDeclaration; + function isPartOfTypeOnlyImportOrExportDeclaration(node: Node): boolean; function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; function isImportAttributeName(node: Node): node is ImportAttributeName; function isModifier(node: Node): node is Modifier; diff --git a/tests/baselines/reference/cjsErrors.errors.txt b/tests/baselines/reference/cjsErrors.errors.txt new file mode 100644 index 0000000000000..010cc8f06a60c --- /dev/null +++ b/tests/baselines/reference/cjsErrors.errors.txt @@ -0,0 +1,12 @@ +index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts". + + +==== index.ts (1 errors) ==== + import foo = require("./foo.ts"); // Error + ~~~~~~~~~~ +!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts". + import type _foo = require("./foo.ts"); // Ok + +==== foo.ts/index.ts (0 errors) ==== + export = {}; + \ No newline at end of file diff --git a/tests/baselines/reference/cjsErrors.js b/tests/baselines/reference/cjsErrors.js new file mode 100644 index 0000000000000..e5ccbfe43a87f --- /dev/null +++ b/tests/baselines/reference/cjsErrors.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/cjsErrors.ts] //// + +//// [index.ts] +export = {}; + +//// [index.ts] +import foo = require("./foo.ts"); // Error +import type _foo = require("./foo.ts"); // Ok + + +//// [index.js] +"use strict"; +module.exports = {}; +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const foo = require("./foo.js"); // Error diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index 56a8ab81090be..c9c555d96f35d 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index 56a8ab81090be..c9c555d96f35d 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index 56a8ab81090be..c9c555d96f35d 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index 2128e19b491ba..57d57797e5c65 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 3a57b6b66b6ff..6f40fa430a101 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 457ad18d7fd76..c0898eedb6c94 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index 3c272c2c1027c..23354c3f64a09 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index cbec354c31b9f..acfcbb5bfad84 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 56a8ab81090be..c9c555d96f35d 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 49877df48bbfd..4c0ff4bb1cb43 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index 79727a965d651..c61179ba4d047 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -36,6 +36,7 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ diff --git a/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/rewriteRelativeImportExtensions/tsconfig.json b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/rewriteRelativeImportExtensions/tsconfig.json new file mode 100644 index 0000000000000..4cf4be4b496e8 --- /dev/null +++ b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/rewriteRelativeImportExtensions/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "rewriteRelativeImportExtensions": true, + "allowImportingTsExtensions": true + } +} diff --git a/tests/baselines/reference/emit(jsx=preserve).errors.txt b/tests/baselines/reference/emit(jsx=preserve).errors.txt new file mode 100644 index 0000000000000..cda66163154d1 --- /dev/null +++ b/tests/baselines/reference/emit(jsx=preserve).errors.txt @@ -0,0 +1,107 @@ +main.ts(2,16): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its corresponding type declarations. +main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations. +main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations. +main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +no.ts(1,16): error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations. +no.ts(2,16): error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations. +no.ts(3,16): error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations. +no.ts(4,16): error TS2307: Cannot find module '.foo.ts' or its corresponding type declarations. +no.ts(5,16): error TS2307: Cannot find module './foo.d.ts' or its corresponding type declarations. +no.ts(6,16): error TS2307: Cannot find module './foo.d.mts' or its corresponding type declarations. +no.ts(7,16): error TS2307: Cannot find module './foo.d.css.ts' or its corresponding type declarations. +no.ts(8,16): error TS2307: Cannot find module '#internal/foo.ts' or its corresponding type declarations. +no.ts(9,16): error TS2307: Cannot find module 'node:foo.ts' or its corresponding type declarations. +no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding type declarations. + + +==== globals.d.ts (0 errors) ==== + declare function require(module: string): any; + +==== main.ts (8 errors) ==== + // Rewrite + import {} from "./foo.ts"; + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import {} from "../foo.mts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '../foo.mts' or its corresponding type declarations. + import {} from "../../foo.cts"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations. + import {} from "./foo.tsx"; + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations. + import foo = require("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import "./foo.ts"; + export * from "./foo.ts"; + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + //Shim + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("./foo.ts", { with: { attr: "value" } }); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("" + "./foo.ts"); +==== js.js (0 errors) ==== + // Rewrite + import {} from "./foo.ts"; + import {} from "../foo.mts"; + import {} from "../../foo.cts"; + import {} from "./foo.tsx"; + import "./foo.ts"; + export * from "./foo.ts"; + // Shim + import("./foo.ts"); + import("./foo.ts", { with: { attr: "value" } }); + require("./foo.ts"); + { + require("./foo.ts"); + require(getPath()); + } + + // No rewrite or shim +==== no.ts (10 errors) ==== + import {} from "./foo.ts/foo.js"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations. + import {} from "foo.ts"; + ~~~~~~~~ +!!! error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations. + import {} from "pkg/foo.ts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations. + import {} from ".foo.ts"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module '.foo.ts' or its corresponding type declarations. + import {} from "./foo.d.ts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.ts' or its corresponding type declarations. + import {} from "./foo.d.mts"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.mts' or its corresponding type declarations. + import {} from "./foo.d.css.ts"; + ~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.css.ts' or its corresponding type declarations. + import {} from "#internal/foo.ts"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '#internal/foo.ts' or its corresponding type declarations. + import {} from "node:foo.ts"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'node:foo.ts' or its corresponding type declarations. + (require)("./foo.ts"); + import("node:path"); + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'node:path' or its corresponding type declarations. + require("node:path"); + +==== lol.ts (0 errors) ==== + // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 + \ No newline at end of file diff --git a/tests/baselines/reference/emit(jsx=preserve).js b/tests/baselines/reference/emit(jsx=preserve).js new file mode 100644 index 0000000000000..101590ab644b9 --- /dev/null +++ b/tests/baselines/reference/emit(jsx=preserve).js @@ -0,0 +1,115 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts] //// + +//// [globals.d.ts] +declare function require(module: string): any; + +//// [main.ts] +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import foo = require("./foo.ts"); +import "./foo.ts"; +export * from "./foo.ts"; +//Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +import("" + "./foo.ts"); +//// [js.js] +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import "./foo.ts"; +export * from "./foo.ts"; +// Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +require("./foo.ts"); +{ + require("./foo.ts"); + require(getPath()); +} + +// No rewrite or shim +//// [no.ts] +import {} from "./foo.ts/foo.js"; +import {} from "foo.ts"; +import {} from "pkg/foo.ts"; +import {} from ".foo.ts"; +import {} from "./foo.d.ts"; +import {} from "./foo.d.mts"; +import {} from "./foo.d.css.ts"; +import {} from "#internal/foo.ts"; +import {} from "node:foo.ts"; +(require)("./foo.ts"); +import("node:path"); +require("node:path"); + +//// [lol.ts] +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 + + +//// [main.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +// Rewrite +import {} from "./foo.js"; +import {} from "../foo.mjs"; +import {} from "../../foo.cjs"; +import {} from "./foo.jsx"; +const foo = require("./foo.js"); +import "./foo.js"; +export * from "./foo.js"; +//Shim +import("./foo.js"); +import("./foo.js", { with: { attr: "value" } }); +import(__rewriteRelativeImportExtension("" + "./foo.ts", true)); +//// [js.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +// Rewrite +import {} from "./foo.js"; +import {} from "../foo.mjs"; +import {} from "../../foo.cjs"; +import {} from "./foo.jsx"; +import "./foo.js"; +export * from "./foo.js"; +// Shim +import("./foo.js"); +import("./foo.js", { with: { attr: "value" } }); +require("./foo.js"); +{ + require("./foo.js"); + require(__rewriteRelativeImportExtension(getPath(), true)); +} +// No rewrite or shim +//// [no.js] +import {} from "./foo.ts/foo.js"; +import {} from "foo.ts"; +import {} from "pkg/foo.ts"; +import {} from ".foo.ts"; +import {} from "./foo.d.ts"; +import {} from "./foo.d.mts"; +import {} from "./foo.d.css.ts"; +import {} from "#internal/foo.ts"; +import {} from "node:foo.ts"; +(require)("./foo.ts"); +import("node:path"); +require("node:path"); +//// [lol.js] +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 diff --git a/tests/baselines/reference/emit(jsx=react).errors.txt b/tests/baselines/reference/emit(jsx=react).errors.txt new file mode 100644 index 0000000000000..cda66163154d1 --- /dev/null +++ b/tests/baselines/reference/emit(jsx=react).errors.txt @@ -0,0 +1,107 @@ +main.ts(2,16): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its corresponding type declarations. +main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations. +main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations. +main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +no.ts(1,16): error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations. +no.ts(2,16): error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations. +no.ts(3,16): error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations. +no.ts(4,16): error TS2307: Cannot find module '.foo.ts' or its corresponding type declarations. +no.ts(5,16): error TS2307: Cannot find module './foo.d.ts' or its corresponding type declarations. +no.ts(6,16): error TS2307: Cannot find module './foo.d.mts' or its corresponding type declarations. +no.ts(7,16): error TS2307: Cannot find module './foo.d.css.ts' or its corresponding type declarations. +no.ts(8,16): error TS2307: Cannot find module '#internal/foo.ts' or its corresponding type declarations. +no.ts(9,16): error TS2307: Cannot find module 'node:foo.ts' or its corresponding type declarations. +no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding type declarations. + + +==== globals.d.ts (0 errors) ==== + declare function require(module: string): any; + +==== main.ts (8 errors) ==== + // Rewrite + import {} from "./foo.ts"; + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import {} from "../foo.mts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '../foo.mts' or its corresponding type declarations. + import {} from "../../foo.cts"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations. + import {} from "./foo.tsx"; + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations. + import foo = require("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import "./foo.ts"; + export * from "./foo.ts"; + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + //Shim + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("./foo.ts", { with: { attr: "value" } }); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("" + "./foo.ts"); +==== js.js (0 errors) ==== + // Rewrite + import {} from "./foo.ts"; + import {} from "../foo.mts"; + import {} from "../../foo.cts"; + import {} from "./foo.tsx"; + import "./foo.ts"; + export * from "./foo.ts"; + // Shim + import("./foo.ts"); + import("./foo.ts", { with: { attr: "value" } }); + require("./foo.ts"); + { + require("./foo.ts"); + require(getPath()); + } + + // No rewrite or shim +==== no.ts (10 errors) ==== + import {} from "./foo.ts/foo.js"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations. + import {} from "foo.ts"; + ~~~~~~~~ +!!! error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations. + import {} from "pkg/foo.ts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations. + import {} from ".foo.ts"; + ~~~~~~~~~ +!!! error TS2307: Cannot find module '.foo.ts' or its corresponding type declarations. + import {} from "./foo.d.ts"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.ts' or its corresponding type declarations. + import {} from "./foo.d.mts"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.mts' or its corresponding type declarations. + import {} from "./foo.d.css.ts"; + ~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.d.css.ts' or its corresponding type declarations. + import {} from "#internal/foo.ts"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module '#internal/foo.ts' or its corresponding type declarations. + import {} from "node:foo.ts"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'node:foo.ts' or its corresponding type declarations. + (require)("./foo.ts"); + import("node:path"); + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'node:path' or its corresponding type declarations. + require("node:path"); + +==== lol.ts (0 errors) ==== + // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 + \ No newline at end of file diff --git a/tests/baselines/reference/emit(jsx=react).js b/tests/baselines/reference/emit(jsx=react).js new file mode 100644 index 0000000000000..e25e6fd2f058d --- /dev/null +++ b/tests/baselines/reference/emit(jsx=react).js @@ -0,0 +1,115 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts] //// + +//// [globals.d.ts] +declare function require(module: string): any; + +//// [main.ts] +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import foo = require("./foo.ts"); +import "./foo.ts"; +export * from "./foo.ts"; +//Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +import("" + "./foo.ts"); +//// [js.js] +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import "./foo.ts"; +export * from "./foo.ts"; +// Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +require("./foo.ts"); +{ + require("./foo.ts"); + require(getPath()); +} + +// No rewrite or shim +//// [no.ts] +import {} from "./foo.ts/foo.js"; +import {} from "foo.ts"; +import {} from "pkg/foo.ts"; +import {} from ".foo.ts"; +import {} from "./foo.d.ts"; +import {} from "./foo.d.mts"; +import {} from "./foo.d.css.ts"; +import {} from "#internal/foo.ts"; +import {} from "node:foo.ts"; +(require)("./foo.ts"); +import("node:path"); +require("node:path"); + +//// [lol.ts] +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 + + +//// [main.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +// Rewrite +import {} from "./foo.js"; +import {} from "../foo.mjs"; +import {} from "../../foo.cjs"; +import {} from "./foo.js"; +const foo = require("./foo.js"); +import "./foo.js"; +export * from "./foo.js"; +//Shim +import("./foo.js"); +import("./foo.js", { with: { attr: "value" } }); +import(__rewriteRelativeImportExtension("" + "./foo.ts")); +//// [js.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +// Rewrite +import {} from "./foo.js"; +import {} from "../foo.mjs"; +import {} from "../../foo.cjs"; +import {} from "./foo.js"; +import "./foo.js"; +export * from "./foo.js"; +// Shim +import("./foo.js"); +import("./foo.js", { with: { attr: "value" } }); +require("./foo.js"); +{ + require("./foo.js"); + require(__rewriteRelativeImportExtension(getPath())); +} +// No rewrite or shim +//// [no.js] +import {} from "./foo.ts/foo.js"; +import {} from "foo.ts"; +import {} from "pkg/foo.ts"; +import {} from ".foo.ts"; +import {} from "./foo.d.ts"; +import {} from "./foo.d.mts"; +import {} from "./foo.d.css.ts"; +import {} from "#internal/foo.ts"; +import {} from "node:foo.ts"; +(require)("./foo.ts"); +import("node:path"); +require("node:path"); +//// [lol.js] +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 diff --git a/tests/baselines/reference/emitModuleCommonJS(module=commonjs).errors.txt b/tests/baselines/reference/emitModuleCommonJS(module=commonjs).errors.txt new file mode 100644 index 0000000000000..38b0e2424efb7 --- /dev/null +++ b/tests/baselines/reference/emitModuleCommonJS(module=commonjs).errors.txt @@ -0,0 +1,25 @@ +a.js(4,11): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +a.js(5,10): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +b.ts(3,10): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + + +==== a.js (2 errors) ==== + { + require("" + "./foo.ts"); + import("" + "./foo.ts"); + require("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + } + +==== b.ts (1 errors) ==== + { + import("" + "./foo.ts"); + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + } + \ No newline at end of file diff --git a/tests/baselines/reference/emitModuleCommonJS(module=commonjs).js b/tests/baselines/reference/emitModuleCommonJS(module=commonjs).js new file mode 100644 index 0000000000000..a539507bd5ef5 --- /dev/null +++ b/tests/baselines/reference/emitModuleCommonJS(module=commonjs).js @@ -0,0 +1,45 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emitModuleCommonJS.ts] //// + +//// [a.js] +{ + require("" + "./foo.ts"); + import("" + "./foo.ts"); + require("./foo.ts"); + import("./foo.ts"); +} + +//// [b.ts] +{ + import("" + "./foo.ts"); + import("./foo.ts"); +} + + +//// [a.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +{ + require(__rewriteRelativeImportExtension("" + "./foo.ts")); + Promise.resolve(`${__rewriteRelativeImportExtension("" + "./foo.ts")}`).then(s => require(s)); + require("./foo.js"); + Promise.resolve().then(() => require("./foo.js")); +} +//// [b.js] +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +{ + Promise.resolve(`${__rewriteRelativeImportExtension("" + "./foo.ts")}`).then(s => require(s)); + Promise.resolve().then(() => require("./foo.js")); +} diff --git a/tests/baselines/reference/emitModuleCommonJS(module=nodenext).errors.txt b/tests/baselines/reference/emitModuleCommonJS(module=nodenext).errors.txt new file mode 100644 index 0000000000000..38b0e2424efb7 --- /dev/null +++ b/tests/baselines/reference/emitModuleCommonJS(module=nodenext).errors.txt @@ -0,0 +1,25 @@ +a.js(4,11): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +a.js(5,10): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. +b.ts(3,10): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + + +==== a.js (2 errors) ==== + { + require("" + "./foo.ts"); + import("" + "./foo.ts"); + require("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + } + +==== b.ts (1 errors) ==== + { + import("" + "./foo.ts"); + import("./foo.ts"); + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations. + } + \ No newline at end of file diff --git a/tests/baselines/reference/emitModuleCommonJS(module=nodenext).js b/tests/baselines/reference/emitModuleCommonJS(module=nodenext).js new file mode 100644 index 0000000000000..73c169d214e58 --- /dev/null +++ b/tests/baselines/reference/emitModuleCommonJS(module=nodenext).js @@ -0,0 +1,48 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emitModuleCommonJS.ts] //// + +//// [a.js] +{ + require("" + "./foo.ts"); + import("" + "./foo.ts"); + require("./foo.ts"); + import("./foo.ts"); +} + +//// [b.ts] +{ + import("" + "./foo.ts"); + import("./foo.ts"); +} + + +//// [a.js] +"use strict"; +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +{ + require(__rewriteRelativeImportExtension("" + "./foo.ts")); + import(__rewriteRelativeImportExtension("" + "./foo.ts")); + require("./foo.js"); + import("./foo.js"); +} +//// [b.js] +"use strict"; +var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) { + if (typeof path === "string" && /^\.\.?\//.test(path)) { + return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { + return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); + }); + } + return path; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +{ + import(__rewriteRelativeImportExtension("" + "./foo.ts")); + import("./foo.js"); +} diff --git a/tests/baselines/reference/packageJsonImportsErrors.errors.txt b/tests/baselines/reference/packageJsonImportsErrors.errors.txt new file mode 100644 index 0000000000000..8167e0cafd0ff --- /dev/null +++ b/tests/baselines/reference/packageJsonImportsErrors.errors.txt @@ -0,0 +1,31 @@ +/index.ts(2,16): error TS2877: This import uses a '.ts' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path. + + +==== /package.json (0 errors) ==== + { + "name": "pkg", + "type": "module", + "imports": { + "#foo.ts": "./foo.ts", + "#internal/*": "./internal/*" + }, + "exports": { + "./*.ts": { + "source": "./*.ts", + "default": "./*.js" + } + } + } + +==== /foo.ts (0 errors) ==== + export {}; + +==== /internal/foo.ts (0 errors) ==== + export {}; + +==== /index.ts (1 errors) ==== + import {} from "#foo.ts"; // Ok + import {} from "#internal/foo.ts"; // Error + ~~~~~~~~~~~~~~~~~~ +!!! error TS2877: This import uses a '.ts' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path. + import {} from "pkg/foo.ts"; // Ok \ No newline at end of file diff --git a/tests/baselines/reference/packageJsonImportsErrors.js b/tests/baselines/reference/packageJsonImportsErrors.js new file mode 100644 index 0000000000000..5a0805f046fa1 --- /dev/null +++ b/tests/baselines/reference/packageJsonImportsErrors.js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/packageJsonImportsErrors.ts] //// + +//// [package.json] +{ + "name": "pkg", + "type": "module", + "imports": { + "#foo.ts": "./foo.ts", + "#internal/*": "./internal/*" + }, + "exports": { + "./*.ts": { + "source": "./*.ts", + "default": "./*.js" + } + } +} + +//// [foo.ts] +export {}; + +//// [foo.ts] +export {}; + +//// [index.ts] +import {} from "#foo.ts"; // Ok +import {} from "#internal/foo.ts"; // Error +import {} from "pkg/foo.ts"; // Ok + +//// [foo.js] +export {}; +//// [foo.js] +export {}; +//// [index.js] +import {} from "#foo.ts"; // Ok +import {} from "#internal/foo.ts"; // Error +import {} from "pkg/foo.ts"; // Ok diff --git a/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences1.baseline b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences1.baseline new file mode 100644 index 0000000000000..990fb9003d8f7 --- /dev/null +++ b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences1.baseline @@ -0,0 +1,19 @@ +// === Syntax and Semantic Diagnostics === +Syntactic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences1.ts': + + +==== /tests/cases/fourslash/server/packages/common/src/index.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/packages/main/src/index.ts (0 errors) ==== + import {} from "../../common/src/index.ts"; + +Semantic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences1.ts': +/tests/cases/fourslash/server/packages/main/src/index.ts(1,16): error TS2878: This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files. + + +==== /tests/cases/fourslash/server/packages/common/src/index.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/packages/main/src/index.ts (1 errors) ==== + import {} from "../../common/src/index.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2878: This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files. \ No newline at end of file diff --git a/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences2.baseline b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences2.baseline new file mode 100644 index 0000000000000..a74f58924f510 --- /dev/null +++ b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences2.baseline @@ -0,0 +1,16 @@ +// === Syntax and Semantic Diagnostics === +Syntactic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences2.ts': + + +==== /tests/cases/fourslash/server/src/compiler/parser.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/src/services/services.ts (0 errors) ==== + import {} from "../compiler/parser.ts"; + +Semantic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences2.ts': + + +==== /tests/cases/fourslash/server/src/compiler/parser.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/src/services/services.ts (0 errors) ==== + import {} from "../compiler/parser.ts"; \ No newline at end of file diff --git a/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences3.baseline b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences3.baseline new file mode 100644 index 0000000000000..48b15a6ceddfa --- /dev/null +++ b/tests/baselines/reference/rewriteRelativeImportExtensionsProjectReferences3.baseline @@ -0,0 +1,16 @@ +// === Syntax and Semantic Diagnostics === +Syntactic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences3.ts': + + +==== /tests/cases/fourslash/server/src/compiler/parser.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/src/services/services.ts (0 errors) ==== + import {} from "../compiler/parser.ts"; + +Semantic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences3.ts': + + +==== /tests/cases/fourslash/server/src/compiler/parser.ts (0 errors) ==== + export {}; +==== /tests/cases/fourslash/server/src/services/services.ts (0 errors) ==== + import {} from "../compiler/parser.ts"; \ No newline at end of file diff --git a/tests/baselines/reference/tsc/commandLine/help-all.js b/tests/baselines/reference/tsc/commandLine/help-all.js index 08747d7b197fe..65d725168ba34 100644 --- a/tests/baselines/reference/tsc/commandLine/help-all.js +++ b/tests/baselines/reference/tsc/commandLine/help-all.js @@ -122,6 +122,11 @@ Use the package.json 'imports' field when resolving imports. type: boolean default: `true` when 'moduleResolution' is 'node16', 'nodenext', or 'bundler'; otherwise `false`. +--rewriteRelativeImportExtensions +Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. +type: boolean +default: false + --rootDir Specify the root folder within your source files. type: string diff --git a/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences1.js b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences1.js new file mode 100644 index 0000000000000..98d4e3467c79d --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences1.js @@ -0,0 +1,710 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/tests/cases/fourslash/server/packages/common/package.json] +{ + "name": "common", + "version": "1.0.0", + "type": "module", + "exports": { + ".": { + "source": "./src/index.ts", + "default": "./dist/index.js" + } + } +} + +//// [/tests/cases/fourslash/server/packages/common/src/index.ts] +export {}; + +//// [/tests/cases/fourslash/server/packages/common/tsconfig.json] +{ + "compilerOptions": { + "composite": true, + "rootDir": "src", + "outDir": "dist", + "module": "nodenext", + } +} + +//// [/tests/cases/fourslash/server/packages/main/package.json] +{ "type": "module" } + +//// [/tests/cases/fourslash/server/packages/main/src/index.ts] +import {} from "../../common/src/index.ts"; + +//// [/tests/cases/fourslash/server/packages/main/tsconfig.json] +{ + "compilerOptions": { + "module": "nodenext", + "rewriteRelativeImportExtensions": true, + "rootDir": "src", + "outDir": "dist", + }, + "references": [ + { "path": "../common" } + ] +} + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/common/tsconfig.json" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/packages/common/tsconfig.json ProjectRootPath: undefined:: Result: /tests/cases/fourslash/server/packages/common/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /tests/cases/fourslash/server/packages/common/tsconfig.json, currentDirectory: /tests/cases/fourslash/server/packages/common +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/packages/common/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/packages/common/src/index.ts" + ], + "options": { + "composite": true, + "rootDir": "/tests/cases/fourslash/server/packages/common/src", + "outDir": "/tests/cases/fourslash/server/packages/common/dist", + "module": 199, + "configFilePath": "/tests/cases/fourslash/server/packages/common/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/tests/cases/fourslash/server/packages/common/tsconfig.json", + "reason": "Creating possible configured project for /tests/cases/fourslash/server/packages/common/tsconfig.json to open" + } + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common 1 undefined Config: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common 1 undefined Config: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/src/index.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tests/cases/fourslash/server/packages/common/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/src/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.esnext.full.d.ts 500 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Missing file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/common/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tests/cases/fourslash/server/packages/common/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/packages/common/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (1) + /tests/cases/fourslash/server/packages/common/src/index.ts Text-1 "export {};" + + + src/index.ts + Matched by default include pattern '**/*' + File is ECMAScript module because 'package.json' has field "type" with value "module" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/tests/cases/fourslash/server/packages/common/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/tests/cases/fourslash/server/packages/common/tsconfig.json", + "configFile": "/tests/cases/fourslash/server/packages/common/tsconfig.json", + "diagnostics": [ + { + "text": "File '/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts' not found.\n The file is in the program because:\n Default library for target 'esnext'", + "code": 6053, + "category": "error" + }, + { + "text": "Cannot find global type 'Array'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Boolean'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Function'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'IArguments'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Number'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Object'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'RegExp'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'String'.", + "code": 2318, + "category": "error" + } + ] + } + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/packages/common/tsconfig.json ProjectRootPath: undefined:: Result: undefined +Info seq [hh:mm:ss:mss] Creating InferredProject: /dev/null/inferredProject1*, currentDirectory: /tests/cases/fourslash/server/packages/common +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /tests/cases/fourslash/server/packages/common/tsconfig.json SVC-1-0 "{\n \"compilerOptions\": {\n \"composite\": true,\n \"rootDir\": \"src\",\n \"outDir\": \"dist\",\n \"module\": \"nodenext\",\n }\n}" + + + ../../../../../../home/src/tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../../../../../home/src/tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + ../../../../../../home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + tsconfig.json + Root file specified for compilation + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/package.json 250 undefined WatchType: package.json file +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/packages/common/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (1) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/packages/common/tsconfig.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/common/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/common/package.json: *new* + {"pollingInterval":2000} + {"pollingInterval":250} +/tests/cases/fourslash/server/packages/common/src/index.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/packages/common/src/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/common/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: *new* + {} +/tests/cases/fourslash/node_modules/@types: *new* + {} + {} +/tests/cases/fourslash/server/node_modules: *new* + {} +/tests/cases/fourslash/server/node_modules/@types: *new* + {} + {} +/tests/cases/fourslash/server/packages/common: *new* + {} +/tests/cases/fourslash/server/packages/common/node_modules: *new* + {} +/tests/cases/fourslash/server/packages/common/node_modules/@types: *new* + {} + {} +/tests/cases/fourslash/server/packages/node_modules: *new* + {} +/tests/cases/fourslash/server/packages/node_modules/@types: *new* + {} + {} + +Projects:: +/dev/null/inferredProject1* (Inferred) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false +/tests/cases/fourslash/server/packages/common/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + noOpenRef: true + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/packages/common/src/index.ts *new* + version: Text-1 + containingProjects: 1 + /tests/cases/fourslash/server/packages/common/tsconfig.json +/tests/cases/fourslash/server/packages/common/tsconfig.json (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/main/src/index.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/packages/main/src/index.ts ProjectRootPath: undefined:: Result: /tests/cases/fourslash/server/packages/main/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /tests/cases/fourslash/server/packages/main/tsconfig.json, currentDirectory: /tests/cases/fourslash/server/packages/main +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/packages/main/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/packages/main/src/index.ts" + ], + "options": { + "module": 199, + "rewriteRelativeImportExtensions": true, + "rootDir": "/tests/cases/fourslash/server/packages/main/src", + "outDir": "/tests/cases/fourslash/server/packages/main/dist", + "configFilePath": "/tests/cases/fourslash/server/packages/main/tsconfig.json" + }, + "projectReferences": [ + { + "path": "/tests/cases/fourslash/server/packages/common", + "originalPath": "../common" + } + ] +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/tests/cases/fourslash/server/packages/main/tsconfig.json", + "reason": "Creating possible configured project for /tests/cases/fourslash/server/packages/main/src/index.ts to open" + } + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main 1 undefined Config: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main 1 undefined Config: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tests/cases/fourslash/server/packages/main/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/src/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/common/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/src/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/package.json 2000 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.esnext.full.d.ts 500 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Missing file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/packages/main/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tests/cases/fourslash/server/packages/main/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/packages/main/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + /tests/cases/fourslash/server/packages/common/src/index.ts Text-1 "export {};" + /tests/cases/fourslash/server/packages/main/src/index.ts SVC-1-0 "import {} from \"../../common/src/index.ts\";" + + + ../common/src/index.ts + Imported via "../../common/src/index.ts" from file 'src/index.ts' + File is ECMAScript module because '../common/package.json' has field "type" with value "module" + src/index.ts + Matched by default include pattern '**/*' + File is ECMAScript module because 'package.json' has field "type" with value "module" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/packages/main/package.json 250 undefined WatchType: package.json file +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/tests/cases/fourslash/server/packages/main/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/tests/cases/fourslash/server/packages/main/src/index.ts", + "configFile": "/tests/cases/fourslash/server/packages/main/tsconfig.json", + "diagnostics": [ + { + "text": "File '/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts' not found.\n The file is in the program because:\n Default library for target 'esnext'", + "code": 6053, + "category": "error" + }, + { + "text": "Cannot find global type 'Array'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Boolean'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Function'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'IArguments'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Number'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Object'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'RegExp'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'String'.", + "code": 2318, + "category": "error" + } + ] + } + } +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/packages/common/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (1) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/packages/main/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/packages/common/tsconfig.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/packages/main/src/index.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /tests/cases/fourslash/server/packages/main/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 1, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts: + {"pollingInterval":500} + {"pollingInterval":500} *new* +/tests/cases/fourslash/server/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/common/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/common/package.json: + {"pollingInterval":2000} + {"pollingInterval":250} + {"pollingInterval":2000} *new* +/tests/cases/fourslash/server/packages/common/src/index.ts: + {"pollingInterval":500} +/tests/cases/fourslash/server/packages/common/src/package.json: + {"pollingInterval":2000} + {"pollingInterval":2000} *new* +/tests/cases/fourslash/server/packages/common/tsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/main/package.json: *new* + {"pollingInterval":2000} + {"pollingInterval":250} +/tests/cases/fourslash/server/packages/main/src/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/main/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/packages/tsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: + {} +/tests/cases/fourslash/node_modules/@types: + {} + {} + {} *new* +/tests/cases/fourslash/server/node_modules: + {} +/tests/cases/fourslash/server/node_modules/@types: + {} + {} + {} *new* +/tests/cases/fourslash/server/packages/common: + {} +/tests/cases/fourslash/server/packages/common/node_modules: + {} +/tests/cases/fourslash/server/packages/common/node_modules/@types: + {} + {} +/tests/cases/fourslash/server/packages/main: *new* + {} +/tests/cases/fourslash/server/packages/main/node_modules/@types: *new* + {} +/tests/cases/fourslash/server/packages/node_modules: + {} +/tests/cases/fourslash/server/packages/node_modules/@types: + {} + {} + {} *new* + +Projects:: +/dev/null/inferredProject1* (Inferred) + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false +/tests/cases/fourslash/server/packages/common/tsconfig.json (Configured) *changed* + projectStateVersion: 1 + projectProgramVersion: 1 + noOpenRef: false *changed* +/tests/cases/fourslash/server/packages/main/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/packages/common/src/index.ts *changed* + version: Text-1 + containingProjects: 2 *changed* + /tests/cases/fourslash/server/packages/common/tsconfig.json + /tests/cases/fourslash/server/packages/main/tsconfig.json *new* +/tests/cases/fourslash/server/packages/common/tsconfig.json (Open) + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* +/tests/cases/fourslash/server/packages/main/src/index.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /tests/cases/fourslash/server/packages/main/tsconfig.json *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/common/src/index.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 2, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 3, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/main/src/index.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 3, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 4, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/common/src/index.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 4, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 5, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/packages/main/src/index.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 5, + "success": true, + "body": [ + { + "message": "This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files.", + "start": 15, + "length": 27, + "category": "error", + "code": 2878, + "startLocation": { + "line": 1, + "offset": 16 + }, + "endLocation": { + "line": 1, + "offset": 43 + } + } + ] + } \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences2.js b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences2.js new file mode 100644 index 0000000000000..d862b9f83843f --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences2.js @@ -0,0 +1,523 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/tests/cases/fourslash/server/src/compiler/parser.ts] +export {}; + +//// [/tests/cases/fourslash/server/src/compiler/tsconfig.json] +{ + "extends": "../tsconfig-base.json", + "compilerOptions": {} +} + +//// [/tests/cases/fourslash/server/src/services/services.ts] +import {} from "../compiler/parser.ts"; + +//// [/tests/cases/fourslash/server/src/services/tsconfig.json] +{ + "extends": "../tsconfig-base.json", + "compilerOptions": {}, + "references": [ + { "path": "../compiler" } + ] +} + +//// [/tests/cases/fourslash/server/src/tsconfig-base.json] +{ + "compilerOptions": { + "module": "nodenext", + "composite": true, + "rootDir": ".", + "outDir": "../dist", + "rewriteRelativeImportExtensions": true, + } +} + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/tsconfig-base.json" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined:: Result: undefined +Info seq [hh:mm:ss:mss] Creating InferredProject: /dev/null/inferredProject1*, currentDirectory: /tests/cases/fourslash/server/src +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /tests/cases/fourslash/server/src/tsconfig-base.json SVC-1-0 "{\n \"compilerOptions\": {\n \"module\": \"nodenext\",\n \"composite\": true,\n \"rootDir\": \".\",\n \"outDir\": \"../dist\",\n \"rewriteRelativeImportExtensions\": true,\n }\n}" + + + ../../../../../home/src/tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../../../../home/src/tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + ../../../../../home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + tsconfig-base.json + Root file specified for compilation + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: *new* + {} +/tests/cases/fourslash/node_modules/@types: *new* + {} +/tests/cases/fourslash/server/node_modules: *new* + {} +/tests/cases/fourslash/server/node_modules/@types: *new* + {} +/tests/cases/fourslash/server/src/node_modules: *new* + {} +/tests/cases/fourslash/server/src/node_modules/@types: *new* + {} + +Projects:: +/dev/null/inferredProject1* (Inferred) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/src/tsconfig-base.json (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/services/services.ts ProjectRootPath: undefined:: Result: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /tests/cases/fourslash/server/src/services/tsconfig.json, currentDirectory: /tests/cases/fourslash/server/src/services +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/src/services/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/src/services/services.ts" + ], + "options": { + "module": 199, + "composite": true, + "rootDir": "/tests/cases/fourslash/server/src", + "outDir": "/tests/cases/fourslash/server/dist", + "rewriteRelativeImportExtensions": true, + "configFilePath": "/tests/cases/fourslash/server/src/services/tsconfig.json" + }, + "projectReferences": [ + { + "path": "/tests/cases/fourslash/server/src/compiler", + "originalPath": "../compiler" + } + ] +} +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/tsconfig-base.json 2000 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Extended config file +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/tests/cases/fourslash/server/src/services/tsconfig.json", + "reason": "Creating possible configured project for /tests/cases/fourslash/server/src/services/services.ts to open" + } + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services 1 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services 1 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/src/compiler/parser.ts" + ], + "options": { + "module": 199, + "composite": true, + "rootDir": "/tests/cases/fourslash/server/src", + "outDir": "/tests/cases/fourslash/server/dist", + "rewriteRelativeImportExtensions": true, + "configFilePath": "/tests/cases/fourslash/server/src/compiler/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler 1 undefined Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler 1 undefined Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/parser.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.esnext.full.d.ts 500 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Missing file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tests/cases/fourslash/server/src/services/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/src/services/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + /tests/cases/fourslash/server/src/compiler/parser.ts Text-1 "export {};" + /tests/cases/fourslash/server/src/services/services.ts SVC-1-0 "import {} from \"../compiler/parser.ts\";" + + + ../compiler/parser.ts + Imported via "../compiler/parser.ts" from file 'services.ts' + File is CommonJS module because 'package.json' was not found + services.ts + Matched by default include pattern '**/*' + File is CommonJS module because 'package.json' was not found + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/tests/cases/fourslash/server/src/services/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/tests/cases/fourslash/server/src/services/services.ts", + "configFile": "/tests/cases/fourslash/server/src/services/tsconfig.json", + "diagnostics": [ + { + "text": "File '/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts' not found.\n The file is in the program because:\n Default library for target 'esnext'", + "code": 6053, + "category": "error" + }, + { + "text": "Cannot find global type 'Array'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Boolean'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Function'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'IArguments'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Number'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Object'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'RegExp'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'String'.", + "code": 2318, + "category": "error" + } + ] + } + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/services/tsconfig.json ProjectRootPath: undefined:: Result: undefined +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/src/services/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/services/services.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 1, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/compiler/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/compiler/parser.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/src/compiler/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/services/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/services/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig-base.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: + {} +/tests/cases/fourslash/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/node_modules: + {} +/tests/cases/fourslash/server/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/src/compiler: *new* + {} +/tests/cases/fourslash/server/src/node_modules: + {} +/tests/cases/fourslash/server/src/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/src/services: *new* + {} +/tests/cases/fourslash/server/src/services/node_modules/@types: *new* + {} + +Projects:: +/dev/null/inferredProject1* (Inferred) + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false +/tests/cases/fourslash/server/src/services/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/src/compiler/parser.ts *new* + version: Text-1 + containingProjects: 1 + /tests/cases/fourslash/server/src/services/tsconfig.json +/tests/cases/fourslash/server/src/services/services.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /tests/cases/fourslash/server/src/services/tsconfig.json *default* +/tests/cases/fourslash/server/src/tsconfig-base.json (Open) + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/compiler/parser.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 2, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 3, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 3, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 4, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/compiler/parser.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 4, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 5, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 5, + "success": true, + "body": [] + } \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences3.js b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences3.js new file mode 100644 index 0000000000000..78c9e35bd8de5 --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/rewriteRelativeImportExtensionsProjectReferences3.js @@ -0,0 +1,526 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/tests/cases/fourslash/server/src/compiler/parser.ts] +export {}; + +//// [/tests/cases/fourslash/server/src/compiler/tsconfig.json] +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "../../dist/compiler", +} + +//// [/tests/cases/fourslash/server/src/services/services.ts] +import {} from "../compiler/parser.ts"; + +//// [/tests/cases/fourslash/server/src/services/tsconfig.json] +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "../../dist/services", + }, + "references": [ + { "path": "../compiler" } + ] +} + +//// [/tests/cases/fourslash/server/src/tsconfig-base.json] +{ + "compilerOptions": { + "module": "nodenext", + "composite": true, + "rewriteRelativeImportExtensions": true, + } +} + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/tsconfig-base.json" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined:: Result: undefined +Info seq [hh:mm:ss:mss] Creating InferredProject: /dev/null/inferredProject1*, currentDirectory: /tests/cases/fourslash/server/src +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /tests/cases/fourslash/server/src/tsconfig-base.json SVC-1-0 "{\n \"compilerOptions\": {\n \"module\": \"nodenext\",\n \"composite\": true,\n \"rewriteRelativeImportExtensions\": true,\n }\n}" + + + ../../../../../home/src/tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../../../../home/src/tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + ../../../../../home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../../../../home/src/tslibs/TS/Lib/lib.d.ts' + tsconfig-base.json + Root file specified for compilation + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/jsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: *new* + {} +/tests/cases/fourslash/node_modules/@types: *new* + {} +/tests/cases/fourslash/server/node_modules: *new* + {} +/tests/cases/fourslash/server/node_modules/@types: *new* + {} +/tests/cases/fourslash/server/src/node_modules: *new* + {} +/tests/cases/fourslash/server/src/node_modules/@types: *new* + {} + +Projects:: +/dev/null/inferredProject1* (Inferred) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/src/tsconfig-base.json (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/services/services.ts ProjectRootPath: undefined:: Result: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /tests/cases/fourslash/server/src/services/tsconfig.json, currentDirectory: /tests/cases/fourslash/server/src/services +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/src/services/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/src/services/services.ts" + ], + "options": { + "module": 199, + "composite": true, + "rewriteRelativeImportExtensions": true, + "rootDir": "/tests/cases/fourslash/server/src/services", + "outDir": "/tests/cases/fourslash/server/dist/services", + "configFilePath": "/tests/cases/fourslash/server/src/services/tsconfig.json" + }, + "projectReferences": [ + { + "path": "/tests/cases/fourslash/server/src/compiler", + "originalPath": "../compiler" + } + ] +} +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/tsconfig-base.json 2000 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Extended config file +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/tests/cases/fourslash/server/src/services/tsconfig.json", + "reason": "Creating possible configured project for /tests/cases/fourslash/server/src/services/services.ts to open" + } + } +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services 1 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services 1 undefined Config: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json : { + "rootNames": [ + "/tests/cases/fourslash/server/src/compiler/parser.ts" + ], + "options": { + "module": 199, + "composite": true, + "rewriteRelativeImportExtensions": true, + "rootDir": "/tests/cases/fourslash/server/src/compiler", + "outDir": "/tests/cases/fourslash/server/dist/compiler", + "configFilePath": "/tests/cases/fourslash/server/src/compiler/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/tsconfig.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler 1 undefined Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler 1 undefined Config: /tests/cases/fourslash/server/src/compiler/tsconfig.json WatchType: Wild card directory +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/parser.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/compiler/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/package.json 2000 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.esnext.full.d.ts 500 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Missing file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/services/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/src/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/server/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /tests/cases/fourslash/node_modules/@types 1 undefined Project: /tests/cases/fourslash/server/src/services/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tests/cases/fourslash/server/src/services/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/src/services/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + /tests/cases/fourslash/server/src/compiler/parser.ts Text-1 "export {};" + /tests/cases/fourslash/server/src/services/services.ts SVC-1-0 "import {} from \"../compiler/parser.ts\";" + + + ../compiler/parser.ts + Imported via "../compiler/parser.ts" from file 'services.ts' + File is CommonJS module because 'package.json' was not found + services.ts + Matched by default include pattern '**/*' + File is CommonJS module because 'package.json' was not found + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/tests/cases/fourslash/server/src/services/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/tests/cases/fourslash/server/src/services/services.ts", + "configFile": "/tests/cases/fourslash/server/src/services/tsconfig.json", + "diagnostics": [ + { + "text": "File '/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts' not found.\n The file is in the program because:\n Default library for target 'esnext'", + "code": 6053, + "category": "error" + }, + { + "text": "Cannot find global type 'Array'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Boolean'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Function'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'IArguments'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Number'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Object'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'RegExp'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'String'.", + "code": 2318, + "category": "error" + } + ] + } + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tests/cases/fourslash/server/src/services/tsconfig.json ProjectRootPath: undefined:: Result: undefined +Info seq [hh:mm:ss:mss] Project '/tests/cases/fourslash/server/src/services/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (2) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) +Info seq [hh:mm:ss:mss] Files (4) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/tsconfig-base.json ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1* +Info seq [hh:mm:ss:mss] FileName: /tests/cases/fourslash/server/src/services/services.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /tests/cases/fourslash/server/src/services/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 1, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/compiler/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/compiler/parser.ts: *new* + {"pollingInterval":500} +/tests/cases/fourslash/server/src/compiler/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/jsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/services/package.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/services/tsconfig.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig-base.json: *new* + {"pollingInterval":2000} +/tests/cases/fourslash/server/src/tsconfig.json: + {"pollingInterval":2000} +/tests/cases/fourslash/server/tsconfig.json: + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/tests/cases/fourslash/node_modules: + {} +/tests/cases/fourslash/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/node_modules: + {} +/tests/cases/fourslash/server/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/src/compiler: *new* + {} +/tests/cases/fourslash/server/src/node_modules: + {} +/tests/cases/fourslash/server/src/node_modules/@types: + {} + {} *new* +/tests/cases/fourslash/server/src/services: *new* + {} +/tests/cases/fourslash/server/src/services/node_modules/@types: *new* + {} + +Projects:: +/dev/null/inferredProject1* (Inferred) + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false +/tests/cases/fourslash/server/src/services/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /dev/null/inferredProject1* +/tests/cases/fourslash/server/src/compiler/parser.ts *new* + version: Text-1 + containingProjects: 1 + /tests/cases/fourslash/server/src/services/tsconfig.json +/tests/cases/fourslash/server/src/services/services.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /tests/cases/fourslash/server/src/services/tsconfig.json *default* +/tests/cases/fourslash/server/src/tsconfig-base.json (Open) + version: SVC-1-0 + containingProjects: 1 + /dev/null/inferredProject1* *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/compiler/parser.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 2, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 3, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts", + "includeLinePosition": true + }, + "command": "syntacticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "syntacticDiagnosticsSync", + "request_seq": 3, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 4, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/compiler/parser.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 4, + "success": true, + "body": [] + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 5, + "type": "request", + "arguments": { + "file": "/tests/cases/fourslash/server/src/services/services.ts", + "includeLinePosition": true + }, + "command": "semanticDiagnosticsSync" + } +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "semanticDiagnosticsSync", + "request_seq": 5, + "success": true, + "body": [] + } \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/cjsErrors.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/cjsErrors.ts new file mode 100644 index 0000000000000..6d5009e3ba90f --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/cjsErrors.ts @@ -0,0 +1,11 @@ +// @module: nodenext +// @rewriteRelativeImportExtensions: true +// @noTypesAndSymbols: true +// @verbatimModuleSyntax: true + +// @Filename: foo.ts/index.ts +export = {}; + +// @Filename: index.ts +import foo = require("./foo.ts"); // Error +import type _foo = require("./foo.ts"); // Ok diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts new file mode 100644 index 0000000000000..57af4ea118719 --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts @@ -0,0 +1,59 @@ +// @target: esnext +// @module: preserve +// @verbatimModuleSyntax: true +// @allowJs: true +// @outDir: dist +// @rewriteRelativeImportExtensions: true +// @noTypesAndSymbols: true +// @jsx: react,preserve + +// @Filename: globals.d.ts +declare function require(module: string): any; + +// @Filename: main.ts +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import foo = require("./foo.ts"); +import "./foo.ts"; +export * from "./foo.ts"; +//Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +import("" + "./foo.ts"); +// @Filename: js.js +// Rewrite +import {} from "./foo.ts"; +import {} from "../foo.mts"; +import {} from "../../foo.cts"; +import {} from "./foo.tsx"; +import "./foo.ts"; +export * from "./foo.ts"; +// Shim +import("./foo.ts"); +import("./foo.ts", { with: { attr: "value" } }); +require("./foo.ts"); +{ + require("./foo.ts"); + require(getPath()); +} + +// No rewrite or shim +// @Filename: no.ts +import {} from "./foo.ts/foo.js"; +import {} from "foo.ts"; +import {} from "pkg/foo.ts"; +import {} from ".foo.ts"; +import {} from "./foo.d.ts"; +import {} from "./foo.d.mts"; +import {} from "./foo.d.css.ts"; +import {} from "#internal/foo.ts"; +import {} from "node:foo.ts"; +(require)("./foo.ts"); +import("node:path"); +require("node:path"); + +// @Filename: lol.ts +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emitModuleCommonJS.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emitModuleCommonJS.ts new file mode 100644 index 0000000000000..08ad2d68fb8ce --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emitModuleCommonJS.ts @@ -0,0 +1,20 @@ +// @checkJs: true +// @outDir: dist +// @target: esnext +// @module: commonjs,nodenext +// @rewriteRelativeImportExtensions: true +// @noTypesAndSymbols: true + +// @Filename: a.js +{ + require("" + "./foo.ts"); + import("" + "./foo.ts"); + require("./foo.ts"); + import("./foo.ts"); +} + +// @Filename: b.ts +{ + import("" + "./foo.ts"); + import("./foo.ts"); +} diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nodeModulesTsFiles.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nodeModulesTsFiles.ts new file mode 100644 index 0000000000000..e39b933d1f8e0 --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nodeModulesTsFiles.ts @@ -0,0 +1,13 @@ +// @module: nodenext +// @rewriteRelativeImportExtensions: true +// @noTypesAndSymbols: true +// @noEmit: true +// @noImplicitReferences: true + +// @Filename: /node_modules/lodash-ts/add.ts +export function add(a: number, b: number) { + return a + b; +} + +// @Filename: /index.ts +import { add } from "lodash-ts/add.ts"; // Ok diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/packageJsonImportsErrors.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/packageJsonImportsErrors.ts new file mode 100644 index 0000000000000..d91b8c48f1405 --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/packageJsonImportsErrors.ts @@ -0,0 +1,31 @@ +// @module: nodenext +// @rewriteRelativeImportExtensions: true +// @noTypesAndSymbols: true +// @verbatimModuleSyntax: true + +// @Filename: /package.json +{ + "name": "pkg", + "type": "module", + "imports": { + "#foo.ts": "./foo.ts", + "#internal/*": "./internal/*" + }, + "exports": { + "./*.ts": { + "source": "./*.ts", + "default": "./*.js" + } + } +} + +// @Filename: /foo.ts +export {}; + +// @Filename: /internal/foo.ts +export {}; + +// @Filename: /index.ts +import {} from "#foo.ts"; // Ok +import {} from "#internal/foo.ts"; // Error +import {} from "pkg/foo.ts"; // Ok \ No newline at end of file diff --git a/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences1.ts b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences1.ts new file mode 100644 index 0000000000000..78a1ca85cea9d --- /dev/null +++ b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences1.ts @@ -0,0 +1,49 @@ +/// + +// @Filename: packages/common/tsconfig.json +//// { +//// "compilerOptions": { +//// "composite": true, +//// "rootDir": "src", +//// "outDir": "dist", +//// "module": "nodenext", +//// } +//// } + +// @Filename: packages/common/package.json +//// { +//// "name": "common", +//// "version": "1.0.0", +//// "type": "module", +//// "exports": { +//// ".": { +//// "source": "./src/index.ts", +//// "default": "./dist/index.js" +//// } +//// } +//// } + +// @Filename: packages/common/src/index.ts +//// export {}; + +// @Filename: packages/main/tsconfig.json +//// { +//// "compilerOptions": { +//// "module": "nodenext", +//// "rewriteRelativeImportExtensions": true, +//// "rootDir": "src", +//// "outDir": "dist", +//// }, +//// "references": [ +//// { "path": "../common" } +//// ] +//// } + +// @Filename: packages/main/package.json +//// { "type": "module" } + +// @Filename: packages/main/src/index.ts +//// import {} from "../../common/src/index.ts"; + +goTo.file("/tests/cases/fourslash/server/packages/main/src/index.ts"); +verify.baselineSyntacticAndSemanticDiagnostics(); diff --git a/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences2.ts b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences2.ts new file mode 100644 index 0000000000000..3db2dbd16cefd --- /dev/null +++ b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences2.ts @@ -0,0 +1,36 @@ +/// + +// @Filename: src/tsconfig-base.json +//// { +//// "compilerOptions": { +//// "module": "nodenext", +//// "composite": true, +//// "rootDir": ".", +//// "outDir": "../dist", +//// "rewriteRelativeImportExtensions": true, +//// } +//// } + +// @Filename: src/compiler/tsconfig.json +//// { +//// "extends": "../tsconfig-base.json", +//// "compilerOptions": {} +//// } + +// @Filename: src/compiler/parser.ts +//// export {}; + +// @Filename: src/services/tsconfig.json +//// { +//// "extends": "../tsconfig-base.json", +//// "compilerOptions": {}, +//// "references": [ +//// { "path": "../compiler" } +//// ] +//// } + +// @Filename: src/services/services.ts +//// import {} from "../compiler/parser.ts"; + +goTo.file("/tests/cases/fourslash/server/src/services/services.ts"); +verify.baselineSyntacticAndSemanticDiagnostics(); diff --git a/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences3.ts b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences3.ts new file mode 100644 index 0000000000000..9ae9f8b1ff620 --- /dev/null +++ b/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences3.ts @@ -0,0 +1,39 @@ +/// + +// @Filename: src/tsconfig-base.json +//// { +//// "compilerOptions": { +//// "module": "nodenext", +//// "composite": true, +//// "rewriteRelativeImportExtensions": true, +//// } +//// } + +// @Filename: src/compiler/tsconfig.json +//// { +//// "extends": "../tsconfig-base.json", +//// "compilerOptions": { +//// "rootDir": ".", +//// "outDir": "../../dist/compiler", +//// } + +// @Filename: src/compiler/parser.ts +//// export {}; + +// @Filename: src/services/tsconfig.json +//// { +//// "extends": "../tsconfig-base.json", +//// "compilerOptions": { +//// "rootDir": ".", +//// "outDir": "../../dist/services", +//// }, +//// "references": [ +//// { "path": "../compiler" } +//// ] +//// } + +// @Filename: src/services/services.ts +//// import {} from "../compiler/parser.ts"; + +goTo.file("/tests/cases/fourslash/server/src/services/services.ts"); +verify.baselineSyntacticAndSemanticDiagnostics();