From 52ea7c2a0586cabb04c312686f122d6fc31a0343 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 2 Nov 2021 12:54:06 +1000 Subject: [PATCH] avoid Object.fromEntries() and some instances of globalThis Not supported on early iOS 12. This can be reverted after iOS 12 support is dropped, which should be soon. --- ts/lib/i18n/bundles.ts | 11 ++++++++--- ts/lib/runtime-require.ts | 2 +- ts/reviewer/reviewer_extras.ts | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ts/lib/i18n/bundles.ts b/ts/lib/i18n/bundles.ts index f60aadedc..a38e99952 100644 --- a/ts/lib/i18n/bundles.ts +++ b/ts/lib/i18n/bundles.ts @@ -23,12 +23,17 @@ function toFluentNumber(num: number): FluentNumber { function formatArgs( args: Record, ): Record { - return Object.fromEntries( - Object.entries(args).map(([key, value]) => [ + const entries: [string, FluentVariable][] = Object.entries(args).map( + ([key, value]) => [ key, typeof value === "number" ? toFluentNumber(value) : value, - ]), + ], ); + const out: Record = {}; + for (const [key, value] of entries) { + out[key] = value; + } + return out; } export function getMessage( diff --git a/ts/lib/runtime-require.ts b/ts/lib/runtime-require.ts index 336b0270c..bcbb7be8a 100644 --- a/ts/lib/runtime-require.ts +++ b/ts/lib/runtime-require.ts @@ -10,7 +10,7 @@ export const runtimeLibraries = {}; // Export require() as a global. -(globalThis as any).require = function (name: string): unknown { +(window as any).require = function (name: string): unknown { const lib = runtimeLibraries[name]; if (lib === undefined) { throw new Error(`Cannot require(${name}) at runtime.`); diff --git a/ts/reviewer/reviewer_extras.ts b/ts/reviewer/reviewer_extras.ts index 926ccd5db..fb4477063 100644 --- a/ts/reviewer/reviewer_extras.ts +++ b/ts/reviewer/reviewer_extras.ts @@ -1,9 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +/* eslint +@typescript-eslint/no-explicit-any: "off", + */ + // A standalone bundle that adds mutateNextCardStates to the anki namespace. // When all clients are using reviewer.js directly, we can get rid of this. import { mutateNextCardStates } from "./answering"; -globalThis.anki.mutateNextCardStates = mutateNextCardStates; +(window as any).anki.mutateNextCardStates = mutateNextCardStates;