mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Remove redundant checker functions and use patterns more friendly to modules (#35399)
* Remove redundant checker functions, use patterns more friendly to modules * Also use a helper for localizedDiagnosticMessages * Move types into same file as consts * Accept slightly changed api baseline * Whitespace!
This commit is contained in:
parent
85ec9bf175
commit
7bfffa745f
@ -546,7 +546,6 @@ namespace ts {
|
||||
getNeverType: () => neverType,
|
||||
getOptionalType: () => optionalType,
|
||||
isSymbolAccessible,
|
||||
getObjectFlags,
|
||||
isArrayType,
|
||||
isTupleType,
|
||||
isArrayLikeType,
|
||||
|
||||
@ -336,6 +336,7 @@ namespace ts {
|
||||
emitSkipped = true;
|
||||
return;
|
||||
}
|
||||
const version = ts.version; // Extracted into a const so the form is stable between namespace and module
|
||||
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
|
||||
}
|
||||
|
||||
|
||||
@ -382,6 +382,11 @@ namespace ts {
|
||||
/*@internal*/
|
||||
export let sysLog: (s: string) => void = noop; // eslint-disable-line prefer-const
|
||||
|
||||
/*@internal*/
|
||||
export function setSysLog(logger: typeof sysLog) {
|
||||
sysLog = logger;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export interface RecursiveDirectoryWatcherHost {
|
||||
watchDirectory: HostWatchDirectory;
|
||||
|
||||
@ -3473,7 +3473,6 @@ namespace ts {
|
||||
/* @internal */ isArrayType(type: Type): boolean;
|
||||
/* @internal */ isTupleType(type: Type): boolean;
|
||||
/* @internal */ isArrayLikeType(type: Type): boolean;
|
||||
/* @internal */ getObjectFlags(type: Type): ObjectFlags;
|
||||
|
||||
/**
|
||||
* True if `contextualType` should not be considered for completions because
|
||||
|
||||
@ -4964,6 +4964,11 @@ namespace ts {
|
||||
|
||||
export let localizedDiagnosticMessages: MapLike<string> | undefined;
|
||||
|
||||
/* @internal */
|
||||
export function setLocalizedDiagnosticMessages(messages: typeof localizedDiagnosticMessages) {
|
||||
localizedDiagnosticMessages = messages;
|
||||
}
|
||||
|
||||
export function getLocaleSpecificMessage(message: DiagnosticMessage) {
|
||||
return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message;
|
||||
}
|
||||
|
||||
@ -370,9 +370,8 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
// making clear this is a global mutation!
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-qualifier
|
||||
ts.localizedDiagnosticMessages = JSON.parse(fileContents!);
|
||||
// this is a global mutation (or live binding update)!
|
||||
setLocalizedDiagnosticMessages(JSON.parse(fileContents!));
|
||||
}
|
||||
catch {
|
||||
if (errors) {
|
||||
|
||||
@ -371,7 +371,7 @@ namespace ts {
|
||||
const createFilePathWatcher: CreateFileWatcher<WatchFileHost, PollingInterval, FileWatcherEventKind, Path, X, Y> = watchLogLevel === WatchLogLevel.None ? watchFilePath : createFileWatcher;
|
||||
const createDirectoryWatcher: CreateFileWatcher<WatchDirectoryHost, WatchDirectoryFlags, undefined, never, X, Y> = getCreateFileWatcher(watchLogLevel, watchDirectory);
|
||||
if (watchLogLevel === WatchLogLevel.Verbose && sysLog === noop) {
|
||||
sysLog = s => log(s);
|
||||
setSysLog(s => log(s));
|
||||
}
|
||||
return {
|
||||
watchFile: (host, file, callback, pollingInterval, detailInfo1, detailInfo2) =>
|
||||
|
||||
@ -1,13 +1,27 @@
|
||||
/* @internal */
|
||||
namespace ts.server {
|
||||
export type ActionSet = "action::set";
|
||||
export type ActionInvalidate = "action::invalidate";
|
||||
export type ActionPackageInstalled = "action::packageInstalled";
|
||||
export type EventTypesRegistry = "event::typesRegistry";
|
||||
export type EventBeginInstallTypes = "event::beginInstallTypes";
|
||||
export type EventEndInstallTypes = "event::endInstallTypes";
|
||||
export type EventInitializationFailed = "event::initializationFailed";
|
||||
/* @internal */
|
||||
export const ActionSet: ActionSet = "action::set";
|
||||
/* @internal */
|
||||
export const ActionInvalidate: ActionInvalidate = "action::invalidate";
|
||||
/* @internal */
|
||||
export const ActionPackageInstalled: ActionPackageInstalled = "action::packageInstalled";
|
||||
/* @internal */
|
||||
export const EventTypesRegistry: EventTypesRegistry = "event::typesRegistry";
|
||||
/* @internal */
|
||||
export const EventBeginInstallTypes: EventBeginInstallTypes = "event::beginInstallTypes";
|
||||
/* @internal */
|
||||
export const EventEndInstallTypes: EventEndInstallTypes = "event::endInstallTypes";
|
||||
/* @internal */
|
||||
export const EventInitializationFailed: EventInitializationFailed = "event::initializationFailed";
|
||||
|
||||
/* @internal */
|
||||
export namespace Arguments {
|
||||
export const GlobalCacheLocation = "--globalTypingsCacheLocation";
|
||||
export const LogFile = "--logFile";
|
||||
@ -26,10 +40,12 @@ namespace ts.server {
|
||||
export const ValidateDefaultNpmLocation = "--validateDefaultNpmLocation";
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function hasArgument(argumentName: string) {
|
||||
return sys.args.indexOf(argumentName) >= 0;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function findArgument(argumentName: string): string | undefined {
|
||||
const index = sys.args.indexOf(argumentName);
|
||||
return index >= 0 && index < sys.args.length - 1
|
||||
@ -37,6 +53,7 @@ namespace ts.server {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function nowString() {
|
||||
// E.g. "12:34:56.789"
|
||||
const d = new Date();
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
declare namespace ts.server {
|
||||
export type ActionSet = "action::set";
|
||||
export type ActionInvalidate = "action::invalidate";
|
||||
export type ActionPackageInstalled = "action::packageInstalled";
|
||||
export type EventTypesRegistry = "event::typesRegistry";
|
||||
export type EventBeginInstallTypes = "event::beginInstallTypes";
|
||||
export type EventEndInstallTypes = "event::endInstallTypes";
|
||||
export type EventInitializationFailed = "event::initializationFailed";
|
||||
|
||||
export interface TypingInstallerResponse {
|
||||
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
|
||||
}
|
||||
|
||||
@ -899,13 +899,13 @@ namespace ts.codefix {
|
||||
low: t => !!(t.flags & (TypeFlags.Any | TypeFlags.Void))
|
||||
},
|
||||
{
|
||||
high: t => !(t.flags & (TypeFlags.Nullable | TypeFlags.Any | TypeFlags.Void)) && !(checker.getObjectFlags(t) & ObjectFlags.Anonymous),
|
||||
low: t => !!(checker.getObjectFlags(t) & ObjectFlags.Anonymous)
|
||||
high: t => !(t.flags & (TypeFlags.Nullable | TypeFlags.Any | TypeFlags.Void)) && !(getObjectFlags(t) & ObjectFlags.Anonymous),
|
||||
low: t => !!(getObjectFlags(t) & ObjectFlags.Anonymous)
|
||||
}];
|
||||
let good = removeLowPriorityInferences(inferences, priorities);
|
||||
const anons = good.filter(i => checker.getObjectFlags(i) & ObjectFlags.Anonymous) as AnonymousType[];
|
||||
const anons = good.filter(i => getObjectFlags(i) & ObjectFlags.Anonymous) as AnonymousType[];
|
||||
if (anons.length) {
|
||||
good = good.filter(i => !(checker.getObjectFlags(i) & ObjectFlags.Anonymous));
|
||||
good = good.filter(i => !(getObjectFlags(i) & ObjectFlags.Anonymous));
|
||||
good.push(combineAnonymousTypes(anons));
|
||||
}
|
||||
return checker.getWidenedType(checker.getUnionType(good.map(checker.getBaseTypeOfLiteralType), UnionReduction.Subtype));
|
||||
|
||||
@ -1145,7 +1145,7 @@ namespace ts {
|
||||
const currentDirectory = host.getCurrentDirectory();
|
||||
// Check if the localized messages json is set, otherwise query the host for it
|
||||
if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) {
|
||||
localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
|
||||
setLocalizedDiagnosticMessages(host.getLocalizedDiagnosticMessages());
|
||||
}
|
||||
|
||||
function log(message: string) {
|
||||
|
||||
@ -4783,6 +4783,8 @@ declare namespace ts.server {
|
||||
type EventBeginInstallTypes = "event::beginInstallTypes";
|
||||
type EventEndInstallTypes = "event::endInstallTypes";
|
||||
type EventInitializationFailed = "event::initializationFailed";
|
||||
}
|
||||
declare namespace ts.server {
|
||||
interface TypingInstallerResponse {
|
||||
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
|
||||
}
|
||||
|
||||
@ -4783,6 +4783,8 @@ declare namespace ts.server {
|
||||
type EventBeginInstallTypes = "event::beginInstallTypes";
|
||||
type EventEndInstallTypes = "event::endInstallTypes";
|
||||
type EventInitializationFailed = "event::initializationFailed";
|
||||
}
|
||||
declare namespace ts.server {
|
||||
interface TypingInstallerResponse {
|
||||
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user