Skip to content

Remove redundant checker functions and use patterns more friendly to modules #35399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ namespace ts {
getNeverType: () => neverType,
getOptionalType: () => optionalType,
isSymbolAccessible,
getObjectFlags,
isArrayType,
isTupleType,
isArrayLikeType,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/watchUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
19 changes: 18 additions & 1 deletion src/jsTyping/shared.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -26,17 +40,20 @@ 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
? sys.args[index + 1]
: undefined;
}

/* @internal */
export function nowString() {
// E.g. "12:34:56.789"
const d = new Date();
Expand Down
8 changes: 0 additions & 8 deletions src/jsTyping/types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/services/codefixes/inferFromUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down