From 6d9d086990dc8653ed42429f8ebe14ba4302bca8 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:25:34 -0700 Subject: [PATCH 1/5] Fix easy ones in compiler --- src/compiler/emitter.ts | 19 ++++++++++--------- src/compiler/parser.ts | 14 +++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 05f117fdcfa12..6caabcf01e8d0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -217,6 +217,7 @@ import { isExportAssignment, isExportSpecifier, isExpression, + isFileLevelUniqueName, isFunctionLike, isGeneratedIdentifier, isGeneratedPrivateIdentifier, @@ -446,6 +447,7 @@ import { VariableDeclaration, VariableDeclarationList, VariableStatement, + version, VoidExpression, WhileStatement, WithStatement, @@ -1110,7 +1112,6 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi /** @internal */ export function createBuildInfo(program: ProgramBuildInfo | undefined, bundle: BundleBuildInfo | undefined): BuildInfo { - const version = ts.version; // Extracted into a const so the form is stable between namespace and module return { bundle, program, version }; } @@ -1212,10 +1213,10 @@ export function emitUsingBuildInfo( customTransformers?: CustomTransformers ): EmitUsingBuildInfoResult { tracing?.push(tracing.Phase.Emit, "emitUsingBuildInfo", {}, /*separateBeginAndEnd*/ true); - ts.performance.mark("beforeEmit"); + performance.mark("beforeEmit"); const result = emitUsingBuildInfoWorker(config, host, getCommandLine, customTransformers); - ts.performance.mark("afterEmit"); - ts.performance.measure("Emit", "beforeEmit", "afterEmit"); + performance.mark("afterEmit"); + performance.measure("Emit", "beforeEmit", "afterEmit"); tracing?.pop(); return result; } @@ -5758,7 +5759,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri * or within the NameGenerator. */ function isUniqueName(name: string, privateName: boolean): boolean { - return isFileLevelUniqueName(name, privateName) + return isFileLevelUniqueNameInCurrentFile(name, privateName) && !isReservedName(name, privateName) && !generatedNames.has(name); } @@ -5773,8 +5774,8 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri * @param _isPrivate (unused) this parameter exists to avoid an unnecessary adaptor frame in v8 * when `isfileLevelUniqueName` is passed as a callback to `makeUniqueName`. */ - function isFileLevelUniqueName(name: string, _isPrivate: boolean) { - return currentSourceFile ? ts.isFileLevelUniqueName(currentSourceFile, name, hasGlobalName) : true; + function isFileLevelUniqueNameInCurrentFile(name: string, _isPrivate: boolean) { + return currentSourceFile ? isFileLevelUniqueName(currentSourceFile, name, hasGlobalName) : true; } /** @@ -5925,7 +5926,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri } function makeFileLevelOptimisticUniqueName(name: string) { - return makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); + return makeUniqueName(name, isFileLevelUniqueNameInCurrentFile, /*optimistic*/ true, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } /** @@ -6034,7 +6035,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri case GeneratedIdentifierFlags.Unique: return makeUniqueName( idText(name), - (autoGenerate.flags & GeneratedIdentifierFlags.FileLevel) ? isFileLevelUniqueName : isUniqueName, + (autoGenerate.flags & GeneratedIdentifierFlags.FileLevel) ? isFileLevelUniqueNameInCurrentFile : isUniqueName, !!(autoGenerate.flags & GeneratedIdentifierFlags.Optimistic), !!(autoGenerate.flags & GeneratedIdentifierFlags.ReservedInNestedScopes), isPrivateIdentifier(name), diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ce9163c50cac1..d6c5e2dd6b666 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { AccessorDeclaration, addRange, @@ -139,6 +138,7 @@ import { isExpressionWithTypeArguments, isExternalModuleReference, isFunctionTypeNode, + isIdentifier as isIdentifierNode, isIdentifierText, isImportDeclaration, isImportEqualsDeclaration, @@ -2324,7 +2324,7 @@ namespace Parser { } // Otherwise, if this isn't a well-known keyword-like identifier, give the generic fallback message. - const expressionText = ts.isIdentifier(node) ? idText(node) : undefined; + const expressionText = isIdentifierNode(node) ? idText(node) : undefined; if (!expressionText || !isIdentifierText(expressionText, languageVersion)) { parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken)); return; @@ -6954,7 +6954,7 @@ namespace Parser { let node: ExpressionStatement | LabeledStatement; const hasParen = token() === SyntaxKind.OpenParenToken; const expression = allowInAnd(parseExpression); - if (ts.isIdentifier(expression) && parseOptional(SyntaxKind.ColonToken)) { + if (isIdentifierNode(expression) && parseOptional(SyntaxKind.ColonToken)) { node = factory.createLabeledStatement(expression, parseStatement()); } else { @@ -9070,7 +9070,7 @@ namespace Parser { case SyntaxKind.ArrayType: return isObjectOrObjectArrayTypeReference((node as ArrayTypeNode).elementType); default: - return isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments; + return isTypeReferenceNode(node) && isIdentifierNode(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments; } } @@ -9367,8 +9367,8 @@ namespace Parser { } function escapedTextsEqual(a: EntityName, b: EntityName): boolean { - while (!ts.isIdentifier(a) || !ts.isIdentifier(b)) { - if (!ts.isIdentifier(a) && !ts.isIdentifier(b) && a.right.escapedText === b.right.escapedText) { + while (!isIdentifierNode(a) || !isIdentifierNode(b)) { + if (!isIdentifierNode(a) && !isIdentifierNode(b) && a.right.escapedText === b.right.escapedText) { a = a.left; b = b.left; } @@ -9393,7 +9393,7 @@ namespace Parser { const child = tryParseChildTag(target, indent); if (child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) && target !== PropertyLikeParse.CallbackParameter && - name && (ts.isIdentifier(child.name) || !escapedTextsEqual(name, child.name.left))) { + name && (isIdentifierNode(child.name) || !escapedTextsEqual(name, child.name.left))) { return false; } return child; From 7504dd8d2cfc83dd20acbd0bb44f47f1da649b2a Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:39:19 -0700 Subject: [PATCH 2/5] Easy services --- src/services/services.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6782aa0d6cf1a..bb911a1c69be5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -285,6 +285,7 @@ import { symbolName, SyntaxKind, SyntaxList, + sys, tagNamesAreEquivalent, TextChange, TextChangeRange, @@ -3187,8 +3188,8 @@ function isArgumentOfElementAccessExpression(node: Node) { * The functionality is not supported if the ts module is consumed outside of a node module. */ export function getDefaultLibFilePath(options: CompilerOptions): string { - if (ts.sys) { - return combinePaths(getDirectoryPath(normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); + if (sys) { + return combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)); } throw new Error("getDefaultLibFilePath is only supported when consumed as a node module. "); From e4f0f16e8599ef4bad5fae3fde3f5ddea427e8cb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:52:08 -0700 Subject: [PATCH 3/5] Shift classifier around --- src/services/services.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index bb911a1c69be5..34b98a9332b6c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -18,7 +18,6 @@ import { Classifications, ClassifiedSpan, ClassifiedSpan2020, - classifier, CodeActionCommand, codefix, CodeFixAction, @@ -316,6 +315,8 @@ import { } from "./_namespaces/ts"; import * as NavigateTo from "./_namespaces/ts.NavigateTo"; import * as NavigationBar from "./_namespaces/ts.NavigationBar"; +import * as classifier from "./classifier"; +import * as classifier2020 from "./classifier2020"; /** The version of the language service API */ export const servicesVersion = "0.8"; @@ -2274,10 +2275,10 @@ export function createLanguageService( const responseFormat = format || SemanticClassificationFormat.Original; if (responseFormat === SemanticClassificationFormat.TwentyTwenty) { - return classifier.v2020.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); + return classifier2020.getSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); } else { - return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); + return classifier.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); } } @@ -2286,21 +2287,21 @@ export function createLanguageService( const responseFormat = format || SemanticClassificationFormat.Original; if (responseFormat === SemanticClassificationFormat.Original) { - return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); + return classifier.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span); } else { - return classifier.v2020.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); + return classifier2020.getEncodedSemanticClassifications(program, cancellationToken, getValidSourceFile(fileName), span); } } function getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] { // doesn't use compiler - no need to synchronize with host - return ts.getSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span); + return classifier.getSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span); } function getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications { // doesn't use compiler - no need to synchronize with host - return ts.getEncodedSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span); + return classifier.getEncodedSyntacticClassifications(cancellationToken, syntaxTreeCache.getCurrentSourceFile(fileName), span); } function getOutliningSpans(fileName: string): OutliningSpan[] { From 2d3c75f32b41dad60c3f37bff554d6d00ee19930 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 12 Mar 2023 15:07:30 -0700 Subject: [PATCH 4/5] Do some other harder ones --- src/compiler/builder.ts | 15 +++++++-------- src/compiler/program.ts | 13 ++++++++----- src/compiler/resolutionCache.ts | 4 ++-- src/compiler/tsbuildPublic.ts | 16 +++++++++------- src/compiler/watchPublic.ts | 4 ++-- src/compiler/watchUtilities.ts | 4 ++-- src/executeCommandLine/executeCommandLine.ts | 9 +++++---- src/services/services.ts | 4 ++-- src/services/sourcemaps.ts | 7 ++++--- 9 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index b1597969ad776..d8273b664103b 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { addRange, AffectedFileResult, @@ -453,7 +452,7 @@ function convertToDiagnostics(diagnostics: readonly ReusableDiagnostic[], newPro if (!diagnostics.length) return emptyArray; let buildInfoDirectory: string | undefined; return diagnostics.map(diagnostic => { - const result: Diagnostic = convertToDiagnosticRelatedInformation(diagnostic, newProgram, toPath); + const result: Diagnostic = convertToDiagnosticRelatedInformation(diagnostic, newProgram, toPathInBuildInfoDirectory); result.reportsUnnecessary = diagnostic.reportsUnnecessary; result.reportsDeprecated = diagnostic.reportDeprecated; result.source = diagnostic.source; @@ -461,15 +460,15 @@ function convertToDiagnostics(diagnostics: readonly ReusableDiagnostic[], newPro const { relatedInformation } = diagnostic; result.relatedInformation = relatedInformation ? relatedInformation.length ? - relatedInformation.map(r => convertToDiagnosticRelatedInformation(r, newProgram, toPath)) : + relatedInformation.map(r => convertToDiagnosticRelatedInformation(r, newProgram, toPathInBuildInfoDirectory)) : [] : undefined; return result; }); - function toPath(path: string) { + function toPathInBuildInfoDirectory(path: string) { buildInfoDirectory ??= getDirectoryPath(getNormalizedAbsolutePath(getTsBuildInfoEmitOutputFilePath(newProgram.getCompilerOptions())!, newProgram.getCurrentDirectory())); - return ts.toPath(path, buildInfoDirectory, newProgram.getCanonicalFileName); + return toPath(path, buildInfoDirectory, newProgram.getCanonicalFileName); } } @@ -1697,7 +1696,7 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: BuildInfo, const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames()); let state: ReusableBuilderProgramState; - const filePaths = program.fileNames?.map(toPath); + const filePaths = program.fileNames?.map(toPathInBuildInfoDirectory); let filePathsSetList: Set[] | undefined; const latestChangedDtsFile = program.latestChangedDtsFile ? toAbsolutePath(program.latestChangedDtsFile) : undefined; if (isProgramBundleEmitBuildInfo(program)) { @@ -1777,8 +1776,8 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: BuildInfo, hasChangedEmitSignature: returnFalse, }; - function toPath(path: string) { - return ts.toPath(path, buildInfoDirectory, getCanonicalFileName); + function toPathInBuildInfoDirectory(path: string) { + return toPath(path, buildInfoDirectory, getCanonicalFileName); } function toAbsolutePath(path: string) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 219c87614ccf0..16c5630ddf207 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { __String, addInternalEmitFlags, @@ -104,12 +103,15 @@ import { forEachEmittedFile, forEachEntry, forEachKey, + forEachResolvedProjectReference as ts_forEachResolvedProjectReference, FunctionLikeDeclaration, getAllowJSCompilerOption, getAutomaticTypeDirectiveNames, getBaseFileName, GetCanonicalFileName, + getCommonSourceDirectory as ts_getCommonSourceDirectory, getCommonSourceDirectoryOfConfig, + getDeclarationDiagnostics as ts_getDeclarationDiagnostics, getDefaultLibFileName, getDirectoryPath, getEmitDeclarations, @@ -307,6 +309,7 @@ import { targetOptionDeclaration, toFileNameLowerCase, tokenToString, + toPath as ts_toPath, trace, tracing, trimStringEnd, @@ -1951,13 +1954,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } function toPath(fileName: string): Path { - return ts.toPath(fileName, currentDirectory, getCanonicalFileName); + return ts_toPath(fileName, currentDirectory, getCanonicalFileName); } function getCommonSourceDirectory() { if (commonSourceDirectory === undefined) { const emittedFiles = filter(files, file => sourceFileMayBeEmitted(file, program)); - commonSourceDirectory = ts.getCommonSourceDirectory( + commonSourceDirectory = ts_getCommonSourceDirectory( options, () => mapDefined(emittedFiles, file => file.isDeclarationFile ? undefined : file.fileName), currentDirectory, @@ -3092,7 +3095,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg return runWithCancellationToken(() => { const resolver = getTypeChecker().getEmitResolver(sourceFile, cancellationToken); // Don't actually write any files since we're just getting diagnostics. - return ts.getDeclarationDiagnostics(getEmitHost(noop), resolver, sourceFile) || emptyArray; + return ts_getDeclarationDiagnostics(getEmitHost(noop), resolver, sourceFile) || emptyArray; }); } @@ -3657,7 +3660,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg function forEachResolvedProjectReference( cb: (resolvedProjectReference: ResolvedProjectReference) => T | undefined ): T | undefined { - return ts.forEachResolvedProjectReference(resolvedProjectReferences, cb); + return ts_forEachResolvedProjectReference(resolvedProjectReferences, cb); } function getSourceOfProjectReferenceRedirect(path: Path) { diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 995de60bb2586..1286b4282687b 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { arrayToMap, CachedDirectoryStructureHost, @@ -63,6 +62,7 @@ import { ResolvedModuleWithFailedLookupLocations, ResolvedProjectReference, ResolvedTypeReferenceDirectiveWithFailedLookupLocations, + resolveModuleName as ts_resolveModuleName, returnTrue, some, SourceFile, @@ -463,7 +463,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, redirectedReference?: ResolvedProjectReference, mode?: ResolutionMode): CachedResolvedModuleWithFailedLookupLocations { const host = resolutionHost.getCompilerHost?.() || resolutionHost; - const primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode); + const primaryResult = ts_resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode); // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts if (!resolutionHost.getGlobalCache) { return primaryResult; diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index 572306483c438..d20992fa298b2 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { AffectedFileResult, arrayToMap, @@ -52,6 +51,7 @@ import { ForegroundColorEscapeSequences, formatColorAndReset, getAllProjectOutputs, + getBuildInfo as ts_getBuildInfo, getBuildInfoFileVersionMap, getConfigFileParsingDiagnostics, getDirectoryPath, @@ -60,6 +60,7 @@ import { getFilesInErrorForSummary, getFirstProjectOutput, getLocaleTimeString, + getModifiedTime as ts_getModifiedTime, getNormalizedAbsolutePath, getParsedCommandLineOfConfigFile, getPendingEmitKind, @@ -108,6 +109,7 @@ import { Status, sys, System, + toPath as ts_toPath, TypeReferenceDirectiveResolutionCache, unorderedRemoveItem, updateErrorForNoInputFiles, @@ -525,7 +527,7 @@ function createSolutionBuilderState(watch: boolean, ho } function toPath(state: SolutionBuilderState, fileName: string) { - return ts.toPath(fileName, state.compilerHost.getCurrentDirectory(), state.compilerHost.getCanonicalFileName); + return ts_toPath(fileName, state.compilerHost.getCurrentDirectory(), state.compilerHost.getCanonicalFileName); } function toResolvedConfigFilePath(state: SolutionBuilderState, fileName: ResolvedConfigFileName): ResolvedConfigFilePath { @@ -1150,7 +1152,7 @@ function createBuildOrUpdateInvalidedProject( const path = toPath(state, name); emittedOutputs.set(toPath(state, name), name); if (data?.buildInfo) setBuildInfo(state, data.buildInfo, projectPath, options, resultFlags); - const modifiedTime = data?.differsOnlyInMap ? ts.getModifiedTime(state.host, name) : undefined; + const modifiedTime = data?.differsOnlyInMap ? ts_getModifiedTime(state.host, name) : undefined; writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark); // Revert the timestamp for the d.ts that is same if (data?.differsOnlyInMap) state.host.setModifiedTime(name, modifiedTime!); @@ -1565,7 +1567,7 @@ function getModifiedTime(state: SolutionBuilderState(state: SolutionBuilderState, return existing.buildInfo || undefined; } const value = state.readFileWithCache(buildInfoPath); - const buildInfo = value ? ts.getBuildInfo(buildInfoPath, value) : undefined; + const buildInfo = value ? ts_getBuildInfo(buildInfoPath, value) : undefined; state.buildInfoCache.set(resolvedConfigPath, { path, buildInfo: buildInfo || false, modifiedTime: modifiedTime || missingFileModifiedTime }); return buildInfo; } @@ -1732,7 +1734,7 @@ function getUpToDateStatusWorker(state: SolutionBuilde let buildInfoVersionMap: ReturnType | undefined; if (buildInfoPath) { const buildInfoCacheEntry = getBuildInfoCacheEntry(state, buildInfoPath, resolvedPath); - buildInfoTime = buildInfoCacheEntry?.modifiedTime || ts.getModifiedTime(host, buildInfoPath); + buildInfoTime = buildInfoCacheEntry?.modifiedTime || ts_getModifiedTime(host, buildInfoPath); if (buildInfoTime === missingFileModifiedTime) { if (!buildInfoCacheEntry) { state.buildInfoCache.set(resolvedPath, { @@ -1864,7 +1866,7 @@ function getUpToDateStatusWorker(state: SolutionBuilde // Output is missing; can stop checking let outputTime = outputTimeStampMap?.get(path); if (!outputTime) { - outputTime = ts.getModifiedTime(state.host, output); + outputTime = ts_getModifiedTime(state.host, output); outputTimeStampMap?.set(path, outputTime); } diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 48b50a68a766c..e065d1e26e610 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { BuilderProgram, BuildInfo, @@ -81,6 +80,7 @@ import { sys, System, toPath, + toPath as ts_toPath, updateErrorForNoInputFiles, updateMissingFilePathsWatch, updateSharedExtendedConfigFileWatcher, @@ -672,7 +672,7 @@ export function createWatchProgram(host: WatchCompiler } function toPath(fileName: string) { - return ts.toPath(fileName, currentDirectory, getCanonicalFileName); + return ts_toPath(fileName, currentDirectory, getCanonicalFileName); } function isFileMissingOnHost(hostSourceFile: HostFileInfo | undefined): hostSourceFile is FileMissingOnHost { diff --git a/src/compiler/watchUtilities.ts b/src/compiler/watchUtilities.ts index 62d6ffee46091..1c7eb04b1193f 100644 --- a/src/compiler/watchUtilities.ts +++ b/src/compiler/watchUtilities.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { arrayToMap, binarySearch, @@ -50,6 +49,7 @@ import { SortedReadonlyArray, supportedJSExtensionsFlat, timestamp, + toPath as ts_toPath, WatchDirectoryFlags, WatchFileKind, WatchOptions, @@ -133,7 +133,7 @@ export function createCachedDirectoryStructureHost(host: DirectoryStructureHost, }; function toPath(fileName: string) { - return ts.toPath(fileName, currentDirectory, getCanonicalFileName); + return ts_toPath(fileName, currentDirectory, getCanonicalFileName); } function getCachedFileSystemEntries(rootDirPath: Path) { diff --git a/src/executeCommandLine/executeCommandLine.ts b/src/executeCommandLine/executeCommandLine.ts index 5623c5647e206..7b07faf9f6e00 100644 --- a/src/executeCommandLine/executeCommandLine.ts +++ b/src/executeCommandLine/executeCommandLine.ts @@ -1,5 +1,4 @@ -import * as performance from "../compiler/_namespaces/ts.performance"; -import * as ts from "./_namespaces/ts"; +import * as performance from "../compiler/performance"; import { arrayFrom, BuilderProgram, @@ -30,6 +29,7 @@ import { createWatchCompilerHostOfConfigFile, createWatchCompilerHostOfFilesAndCompilerOptions, createWatchProgram, + createWatchStatusReporter as ts_createWatchStatusReporter, Debug, Diagnostic, DiagnosticMessage, @@ -67,6 +67,7 @@ import { parseCommandLine, parseConfigFileWithSystem, ParsedCommandLine, + performIncrementalCompilation as ts_performIncrementalCompilation, Program, reduceLeftIterator, ReportEmitErrorSummary, @@ -923,7 +924,7 @@ function performIncrementalCompilation( const { options, fileNames, projectReferences } = config; enableStatisticsAndTracing(sys, options, /*isBuildMode*/ false); const host = createIncrementalCompilerHost(options, sys); - const exitStatus = ts.performIncrementalCompilation({ + const exitStatus = ts_performIncrementalCompilation({ host, system: sys, rootNames: fileNames, @@ -984,7 +985,7 @@ function updateWatchCompilationHost( } function createWatchStatusReporter(sys: System, options: CompilerOptions | BuildOptions) { - return ts.createWatchStatusReporter(sys, shouldBePretty(sys, options)); + return ts_createWatchStatusReporter(sys, shouldBePretty(sys, options)); } function createWatchOfConfigFile( diff --git a/src/services/services.ts b/src/services/services.ts index 34b98a9332b6c..298ab226bcaab 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { __String, ApplicableRefactorInfo, @@ -89,6 +88,7 @@ import { getContainerNode, getDefaultLibFileName, getDirectoryPath, + getEditsForFileRename as ts_getEditsForFileRename, getEmitDeclarations, getEscapedTextOfIdentifierOrLiteral, getFileEmitOutput, @@ -2402,7 +2402,7 @@ export function createLanguageService( } function getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences = emptyOptions): readonly FileTextChanges[] { - return ts.getEditsForFileRename(getProgram()!, oldFilePath, newFilePath, host, formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); + return ts_getEditsForFileRename(getProgram()!, oldFilePath, newFilePath, host, formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); } function applyCodeActionCommand(action: CodeActionCommand, formatSettings?: FormatCodeSettings): Promise; diff --git a/src/services/sourcemaps.ts b/src/services/sourcemaps.ts index e77fe30e4acf1..6b0594c1df01a 100644 --- a/src/services/sourcemaps.ts +++ b/src/services/sourcemaps.ts @@ -1,4 +1,3 @@ -import * as ts from "./_namespaces/ts"; import { base64decode, computeLineAndCharacterOfPosition, @@ -10,6 +9,7 @@ import { Extension, getDeclarationEmitOutputFilePathWorker, getDirectoryPath, + getDocumentPositionMapper as ts_getDocumentPositionMapper, getLineInfo, getLineStarts, getNormalizedAbsolutePath, @@ -23,6 +23,7 @@ import { removeFileExtension, SourceFileLike, sys, + toPath as ts_toPath, tryGetSourceMappingURL, tryParseRawSourceMap, } from "./_namespaces/ts"; @@ -58,7 +59,7 @@ export function getSourceMapper(host: SourceMapperHost): SourceMapper { return { tryGetSourcePosition, tryGetGeneratedPosition, toLineColumnOffset, clearCache }; function toPath(fileName: string) { - return ts.toPath(fileName, currentDirectory, getCanonicalFileName); + return ts_toPath(fileName, currentDirectory, getCanonicalFileName); } function getDocumentPositionMapper(generatedFileName: string, sourceFileName?: string) { @@ -72,7 +73,7 @@ export function getSourceMapper(host: SourceMapperHost): SourceMapper { } else if (host.readFile) { const file = getSourceFileLike(generatedFileName); - mapper = file && ts.getDocumentPositionMapper( + mapper = file && ts_getDocumentPositionMapper( { getSourceFileLike, getCanonicalFileName, log: s => host.log(s) }, generatedFileName, getLineInfo(file.text, getLineStarts(file)), From 5a49a0fb1464e1f61ab8ee202d1027817d8ee902 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 12 Mar 2023 15:29:16 -0700 Subject: [PATCH 5/5] Fix tests --- src/compiler/parser.ts | 3 ++- src/compiler/program.ts | 3 ++- src/server/protocol.ts | 4 ++-- tests/baselines/reference/api/tsserverlibrary.d.ts | 12 ++++++------ tests/baselines/reference/api/typescript.d.ts | 12 ++++++------ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d6c5e2dd6b666..23e9770eb7d34 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -264,6 +264,7 @@ import { NewExpression, Node, NodeArray, + NodeFactory, NodeFactoryFlags, NodeFlags, nodeIsMissing, @@ -427,7 +428,7 @@ export const parseBaseNodeFactory: BaseNodeFactory = { }; /** @internal */ -export const parseNodeFactory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules, parseBaseNodeFactory); +export const parseNodeFactory: NodeFactory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules, parseBaseNodeFactory); function visitNode(cbNode: (node: Node) => T, node: Node | undefined): T | undefined { return node && cbNode(node); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 16c5630ddf207..60d4647f8d384 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -306,6 +306,7 @@ import { SymlinkCache, SyntaxKind, sys, + System, targetOptionDeclaration, toFileNameLowerCase, tokenToString, @@ -451,7 +452,7 @@ export function createWriteFileMeasuringIO( } /** @internal */ -export function createCompilerHostWorker(options: CompilerOptions, setParentNodes?: boolean, system = sys): CompilerHost { +export function createCompilerHostWorker(options: CompilerOptions, setParentNodes?: boolean, system: System = sys): CompilerHost { const existingDirectories = new Map(); const getCanonicalFileName = createGetCanonicalFileName(system.useCaseSensitiveFileNames); function directoryExists(directoryPath: string): boolean { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 50546bb8dce8f..a32e179c31603 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -1,5 +1,5 @@ -import * as ts from "./_namespaces/ts"; -import { +import type * as ts from "./_namespaces/ts"; +import type { CompilerOptionsValue, EndOfLineState, FileExtensionInfo, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 44b2efdcbfdfb..8507f14d8afd5 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -9340,7 +9340,7 @@ declare namespace ts { * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. */ - function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ts.ResolutionMode; + function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ResolutionMode; /** * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). @@ -9360,7 +9360,7 @@ declare namespace ts { */ function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMode; - }, usage: StringLiteralLike): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[]; /** * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the @@ -9541,8 +9541,8 @@ declare namespace ts { */ emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult; } - function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined; - function createIncrementalCompilerHost(options: CompilerOptions, system?: ts.System): CompilerHost; + function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined; + function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost; function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; /** * Create the watch compiler host for either configFile or fileNames and its options @@ -9698,8 +9698,8 @@ declare namespace ts { * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic */ function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter; - function createSolutionBuilderHost(system?: ts.System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): ts.SolutionBuilderHost; - function createSolutionBuilderWithWatchHost(system?: ts.System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): ts.SolutionBuilderWithWatchHost; + function createSolutionBuilderHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost; + function createSolutionBuilderWithWatchHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost; function createSolutionBuilder(host: SolutionBuilderHost, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder; function createSolutionBuilderWithWatch(host: SolutionBuilderWithWatchHost, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder; interface BuildOptions { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index d3f3c6897e489..a7ad7f9448614 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5397,7 +5397,7 @@ declare namespace ts { * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. */ - function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ts.ResolutionMode; + function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ResolutionMode; /** * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). @@ -5417,7 +5417,7 @@ declare namespace ts { */ function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMode; - }, usage: StringLiteralLike): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[]; /** * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the @@ -5598,8 +5598,8 @@ declare namespace ts { */ emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult; } - function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined; - function createIncrementalCompilerHost(options: CompilerOptions, system?: ts.System): CompilerHost; + function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined; + function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost; function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; /** * Create the watch compiler host for either configFile or fileNames and its options @@ -5755,8 +5755,8 @@ declare namespace ts { * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic */ function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter; - function createSolutionBuilderHost(system?: ts.System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): ts.SolutionBuilderHost; - function createSolutionBuilderWithWatchHost(system?: ts.System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): ts.SolutionBuilderWithWatchHost; + function createSolutionBuilderHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost; + function createSolutionBuilderWithWatchHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost; function createSolutionBuilder(host: SolutionBuilderHost, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder; function createSolutionBuilderWithWatch(host: SolutionBuilderWithWatchHost, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder; interface BuildOptions {