mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Remove most "import * as ts" imports, except for const enum reverse mapping and plugins (#53329)
This commit is contained in:
@@ -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<Path>[] | 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) {
|
||||
|
||||
+10
-9
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
@@ -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<T>(cbNode: (node: Node) => T, node: Node | undefined): T | undefined {
|
||||
return node && cbNode(node);
|
||||
@@ -2324,7 +2325,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 +6955,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 +9071,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 +9368,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 +9394,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;
|
||||
|
||||
+10
-6
@@ -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,
|
||||
@@ -304,9 +306,11 @@ import {
|
||||
SymlinkCache,
|
||||
SyntaxKind,
|
||||
sys,
|
||||
System,
|
||||
targetOptionDeclaration,
|
||||
toFileNameLowerCase,
|
||||
tokenToString,
|
||||
toPath as ts_toPath,
|
||||
trace,
|
||||
tracing,
|
||||
trimStringEnd,
|
||||
@@ -448,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<string, boolean>();
|
||||
const getCanonicalFileName = createGetCanonicalFileName(system.useCaseSensitiveFileNames);
|
||||
function directoryExists(directoryPath: string): boolean {
|
||||
@@ -1951,13 +1955,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 +3096,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 +3661,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
function forEachResolvedProjectReference<T>(
|
||||
cb: (resolvedProjectReference: ResolvedProjectReference) => T | undefined
|
||||
): T | undefined {
|
||||
return ts.forEachResolvedProjectReference(resolvedProjectReferences, cb);
|
||||
return ts_forEachResolvedProjectReference(resolvedProjectReferences, cb);
|
||||
}
|
||||
|
||||
function getSourceOfProjectReferenceRedirect(path: Path) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T extends BuilderProgram>(watch: boolean, ho
|
||||
}
|
||||
|
||||
function toPath<T extends BuilderProgram>(state: SolutionBuilderState<T>, fileName: string) {
|
||||
return ts.toPath(fileName, state.compilerHost.getCurrentDirectory(), state.compilerHost.getCanonicalFileName);
|
||||
return ts_toPath(fileName, state.compilerHost.getCurrentDirectory(), state.compilerHost.getCanonicalFileName);
|
||||
}
|
||||
|
||||
function toResolvedConfigFilePath<T extends BuilderProgram>(state: SolutionBuilderState<T>, fileName: ResolvedConfigFileName): ResolvedConfigFilePath {
|
||||
@@ -1150,7 +1152,7 @@ function createBuildOrUpdateInvalidedProject<T extends BuilderProgram>(
|
||||
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<T extends BuilderProgram>(state: SolutionBuilderState<T
|
||||
// In watch mode we store the modified times in the cache
|
||||
// This is either Date | FileWatcherWithModifiedTime because we query modified times first and
|
||||
// then after complete compilation of the project, watch the files so we dont want to loose these modified times.
|
||||
const result = ts.getModifiedTime(state.host, fileName);
|
||||
const result = ts_getModifiedTime(state.host, fileName);
|
||||
if (state.watch) {
|
||||
if (existing) (existing as FileWatcherWithModifiedTime).modifiedTime = result;
|
||||
else state.filesWatched.set(path, result);
|
||||
@@ -1657,7 +1659,7 @@ function getBuildInfo<T extends BuilderProgram>(state: SolutionBuilderState<T>,
|
||||
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<T extends BuilderProgram>(state: SolutionBuilde
|
||||
let buildInfoVersionMap: ReturnType<typeof getBuildInfoFileVersionMap> | 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<T extends BuilderProgram>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T extends BuilderProgram>(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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as ts from "./_namespaces/ts";
|
||||
import {
|
||||
import type * as ts from "./_namespaces/ts";
|
||||
import type {
|
||||
CompilerOptionsValue,
|
||||
EndOfLineState,
|
||||
FileExtensionInfo,
|
||||
|
||||
+13
-11
@@ -1,4 +1,3 @@
|
||||
import * as ts from "./_namespaces/ts";
|
||||
import {
|
||||
__String,
|
||||
ApplicableRefactorInfo,
|
||||
@@ -18,7 +17,6 @@ import {
|
||||
Classifications,
|
||||
ClassifiedSpan,
|
||||
ClassifiedSpan2020,
|
||||
classifier,
|
||||
CodeActionCommand,
|
||||
codefix,
|
||||
CodeFixAction,
|
||||
@@ -90,6 +88,7 @@ import {
|
||||
getContainerNode,
|
||||
getDefaultLibFileName,
|
||||
getDirectoryPath,
|
||||
getEditsForFileRename as ts_getEditsForFileRename,
|
||||
getEmitDeclarations,
|
||||
getEscapedTextOfIdentifierOrLiteral,
|
||||
getFileEmitOutput,
|
||||
@@ -285,6 +284,7 @@ import {
|
||||
symbolName,
|
||||
SyntaxKind,
|
||||
SyntaxList,
|
||||
sys,
|
||||
tagNamesAreEquivalent,
|
||||
TextChange,
|
||||
TextChangeRange,
|
||||
@@ -315,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";
|
||||
@@ -2273,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2285,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[] {
|
||||
@@ -2400,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<ApplyCodeActionCommandResult>;
|
||||
@@ -3187,8 +3189,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. ");
|
||||
|
||||
@@ -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)),
|
||||
|
||||
+6
-6
@@ -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<EmitResult>;
|
||||
}
|
||||
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<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions<T>): 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<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: ts.System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): ts.SolutionBuilderHost<T>;
|
||||
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: ts.System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): ts.SolutionBuilderWithWatchHost<T>;
|
||||
function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost<T>;
|
||||
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost<T>;
|
||||
function createSolutionBuilder<T extends BuilderProgram>(host: SolutionBuilderHost<T>, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder<T>;
|
||||
function createSolutionBuilderWithWatch<T extends BuilderProgram>(host: SolutionBuilderWithWatchHost<T>, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder<T>;
|
||||
interface BuildOptions {
|
||||
|
||||
+6
-6
@@ -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<EmitResult>;
|
||||
}
|
||||
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<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions<T>): 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<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: ts.System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): ts.SolutionBuilderHost<T>;
|
||||
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: ts.System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): ts.SolutionBuilderWithWatchHost<T>;
|
||||
function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost<T>;
|
||||
function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system?: System, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost<T>;
|
||||
function createSolutionBuilder<T extends BuilderProgram>(host: SolutionBuilderHost<T>, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder<T>;
|
||||
function createSolutionBuilderWithWatch<T extends BuilderProgram>(host: SolutionBuilderWithWatchHost<T>, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder<T>;
|
||||
interface BuildOptions {
|
||||
|
||||
Reference in New Issue
Block a user