diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index b41e89e9915..48ac670c8be 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -499,12 +499,16 @@ namespace ts { /*@internal*/ export const ignoredPaths = ["/node_modules/.", "/.git", "/.#"]; + let curSysLog: (s: string) => void = noop; // eslint-disable-line prefer-const + /*@internal*/ - export let sysLog: (s: string) => void = noop; // eslint-disable-line prefer-const + export function sysLog(s: string) { + return curSysLog(s); + } /*@internal*/ export function setSysLog(logger: typeof sysLog) { - sysLog = logger; + curSysLog = logger; } /*@internal*/ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e77e13df623..c9c2cb1ce55 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5899,7 +5899,7 @@ namespace ts { } // eslint-disable-next-line prefer-const - export let objectAllocator: ObjectAllocator = { + export const objectAllocator: ObjectAllocator = { getNodeConstructor: () => Node as any, getTokenConstructor: () => Token as any, getIdentifierConstructor: () => Identifier as any, @@ -5912,20 +5912,27 @@ namespace ts { }; export function setObjectAllocator(alloc: ObjectAllocator) { - objectAllocator = alloc; + Object.assign(objectAllocator, alloc); } export function formatStringFromArgs(text: string, args: ArrayLike, baseIndex = 0): string { return text.replace(/{(\d+)}/g, (_match, index: string) => "" + Debug.checkDefined(args[+index + baseIndex])); } - export let localizedDiagnosticMessages: MapLike | undefined; + let localizedDiagnosticMessages: MapLike | undefined; /* @internal */ export function setLocalizedDiagnosticMessages(messages: typeof localizedDiagnosticMessages) { localizedDiagnosticMessages = messages; } + /* @internal */ + export function maybeSetLocalizedDiagnosticMessages(getMessages: undefined | (() => typeof localizedDiagnosticMessages)) { + if (!localizedDiagnosticMessages && getMessages) { + localizedDiagnosticMessages = getMessages(); + } + } + export function getLocaleSpecificMessage(message: DiagnosticMessage) { return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message; } diff --git a/src/services/services.ts b/src/services/services.ts index c43c55dfd5b..56e72c6aadd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1259,10 +1259,9 @@ namespace ts { : NoopCancellationToken; const currentDirectory = host.getCurrentDirectory(); - // Check if the localized messages json is set, otherwise query the host for it - if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { - setLocalizedDiagnosticMessages(host.getLocalizedDiagnosticMessages()); - } + + // Checks if the localized messages json is set, and if not, query the host for it + maybeSetLocalizedDiagnosticMessages(host.getLocalizedDiagnosticMessages?.bind(host)); function log(message: string) { if (host.log) {