From c43e69bfddc051efb06264e0d3a25ac1a12821fc Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:47:45 -0600 Subject: [PATCH] Use CompilerInfo[] in a couple places that were previously any or never (#6029) Depends on #6028 --- app.ts | 5 +++-- lib/options-handler.ts | 7 ++++--- types/cache.interfaces.ts | 4 ++++ types/compiler.interfaces.ts | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app.ts b/app.ts index 13e8d9ad8..dd40f6b55 100755 --- a/app.ts +++ b/app.ts @@ -68,6 +68,7 @@ import {loadSponsorsFromString} from './lib/sponsors.js'; import {getStorageTypeByKey} from './lib/storage/index.js'; import * as utils from './lib/utils.js'; import {ElementType} from './shared/common-utils.js'; +import {CompilerInfo} from './types/compiler.interfaces.js'; import type {Language, LanguageKey} from './types/languages.interfaces.js'; // Used by assert.ts @@ -525,7 +526,7 @@ async function main() { if (gitReleaseName) logger.info(` git release ${gitReleaseName}`); if (releaseBuildNumber) logger.info(` release build ${releaseBuildNumber}`); - let initialCompilers; + let initialCompilers: CompilerInfo[]; let prevCompilers; if (opts.prediscovered) { @@ -581,7 +582,7 @@ async function main() { const noscriptHandler = new NoScriptHandler(router, global.handler_config); const routeApi = new RouteAPI(router, global.handler_config); - async function onCompilerChange(compilers) { + async function onCompilerChange(compilers: CompilerInfo[]) { if (JSON.stringify(prevCompilers) === JSON.stringify(compilers)) { return; } diff --git a/lib/options-handler.ts b/lib/options-handler.ts index 79068bbc8..b9d4be46d 100755 --- a/lib/options-handler.ts +++ b/lib/options-handler.ts @@ -39,6 +39,7 @@ import {Source} from './sources/index.js'; import {BaseTool, getToolTypeByKey} from './tooling/index.js'; import {asSafeVer, getHash, splitArguments, splitIntoArray} from './utils.js'; import {AppDefaultArguments} from '../app.js'; +import {CompilerInfo} from '../types/compiler.interfaces.js'; // TODO: Figure out if same as libraries.interfaces.ts? export type VersionInfo = { @@ -78,7 +79,7 @@ export type ClientOptionsType = { googleShortLinkRewrite: string[]; urlShortenService: string; defaultSource: string; - compilers: never[]; + compilers: CompilerInfo[]; libs: Record>; remoteLibs: Record; tools: Record; @@ -426,7 +427,7 @@ export class ClientOptionsHandler { await this.getRemoteLibraries(language, remote.target); } - async setCompilers(compilers: any[]) { + async setCompilers(compilers: CompilerInfo[]) { const forbiddenKeys = new Set([ 'exe', 'versionFlag', @@ -438,7 +439,7 @@ export class ClientOptionsHandler { 'demanglerType', 'isSemVer', ]); - const copiedCompilers = JSON.parse(JSON.stringify(compilers)); + const copiedCompilers = JSON.parse(JSON.stringify(compilers)) as CompilerInfo[]; const semverGroups: Record = {}; // Reset the supportsExecute flag in case critical compilers change diff --git a/types/cache.interfaces.ts b/types/cache.interfaces.ts index 5656a7e0e..15e1f3e7b 100644 --- a/types/cache.interfaces.ts +++ b/types/cache.interfaces.ts @@ -28,10 +28,14 @@ export type GetResult = { }; // Something that can be used as a value and passed to cache functions. A simple JSON-able type. +// Functions or undefined values are either filtered out or replaced with null +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description export type CacheableValue = | string | number | boolean | undefined + | null + | Function // eslint-disable-line @typescript-eslint/ban-types | {[x: string]: CacheableValue} | Array; diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index 7b5e21807..31ff5c4d0 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -110,7 +110,7 @@ export type CompilerInfo = { tools: Record; unwiseOptions: string[]; hidden: boolean; - buildenvsetup: { + buildenvsetup?: { id: string; props: (name: string, def: string) => string; };