mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
chore(app): drop core-js polyfills (#59007)
This commit is contained in:
committed by
GitHub
Unverified
parent
9aeaa3c3b5
commit
798971cfd9
@@ -83,7 +83,6 @@
|
||||
"@solidjs/router": "catalog:",
|
||||
"@tanstack/solid-query": "5.91.4",
|
||||
"@tanstack/solid-virtual": "catalog:",
|
||||
"core-js": "3.50.0",
|
||||
"effect": "catalog:",
|
||||
"fuzzysort": "catalog:",
|
||||
"qr-scanner": "1.4.2",
|
||||
@@ -3308,8 +3307,6 @@
|
||||
|
||||
"cookie-es": ["cookie-es@2.0.1", "", {}, "sha512-aVf4A4hI2w70LnF7GG+7xDQUkliwiXWXFvTjkip4+b64ygDQ2sJPRSKFDHbxn8o0xu9QzPkMuuiWIXyFSE2slA=="],
|
||||
|
||||
"core-js": ["core-js@3.50.0", "", {}, "sha512-BRWgOLKkFeCgRudR6zrs8p9XJZcE14grzKMMssoYrk6krtuEZ7MTKPIY5RzOnqsEKIR9kst7wNzphttraT+Yqw=="],
|
||||
|
||||
"core-js-compat": ["core-js-compat@3.50.0", "", { "dependencies": { "browserslist": "^4.28.7" } }, "sha512-XGpFGbMLHwSt74YLTKho7Ib242qi6O8MSX+sRokV4oz7iKXvQWGYZthjIhjRGMxjzVkAubBO512dKGYcefmX3Q=="],
|
||||
|
||||
"core-util-is": ["core-util-is@1.0.3", "", {}, "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="],
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
"@solidjs/router": "catalog:",
|
||||
"@tanstack/solid-query": "5.91.4",
|
||||
"@tanstack/solid-virtual": "catalog:",
|
||||
"core-js": "3.50.0",
|
||||
"effect": "catalog:",
|
||||
"fuzzysort": "catalog:",
|
||||
"qr-scanner": "1.4.2",
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { afterEach, beforeEach, expect, test } from "bun:test"
|
||||
|
||||
const native = { groupBy: Map.groupBy, withResolvers: Promise.withResolvers, try: Promise.try }
|
||||
|
||||
const maps: Partial<typeof Map> = Map
|
||||
|
||||
const promises: Partial<typeof Promise> = Promise
|
||||
|
||||
beforeEach(async () => {
|
||||
delete maps.groupBy
|
||||
delete promises.withResolvers
|
||||
delete promises.try
|
||||
await import(`./polyfills?${Math.random()}`)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Map.groupBy = native.groupBy
|
||||
Promise.withResolvers = native.withResolvers
|
||||
Promise.try = native.try
|
||||
})
|
||||
|
||||
test("Map.groupBy keeps first-seen key order and passes the index", () => {
|
||||
const groups = Map.groupBy([1, 2, 3, 4, 5], (n) => (n % 2 ? "odd" : "even"))
|
||||
expect([...groups]).toEqual([
|
||||
["odd", [1, 3, 5]],
|
||||
["even", [2, 4]],
|
||||
])
|
||||
expect([...Map.groupBy(["a", "b"], (_, index) => index).keys()]).toEqual([0, 1])
|
||||
})
|
||||
|
||||
test("Promise.withResolvers settles from outside", async () => {
|
||||
const resolved = Promise.withResolvers<number>()
|
||||
resolved.resolve(1)
|
||||
expect(await resolved.promise).toBe(1)
|
||||
|
||||
const rejected = Promise.withResolvers<number>()
|
||||
rejected.reject(new Error("no"))
|
||||
|
||||
await expect(rejected.promise).rejects.toThrow("no")
|
||||
})
|
||||
|
||||
test("Promise.try runs synchronously and isolates a throw", async () => {
|
||||
let ran = false
|
||||
|
||||
const value = Promise.try(() => {
|
||||
ran = true
|
||||
|
||||
return 2
|
||||
})
|
||||
|
||||
expect(ran).toBe(true)
|
||||
expect(await value).toBe(2)
|
||||
|
||||
expect(await Promise.try((a: number, b: number) => a + b, 1, 2)).toBe(3)
|
||||
|
||||
await expect(
|
||||
Promise.try(() => {
|
||||
throw new Error("boom")
|
||||
}),
|
||||
).rejects.toThrow("boom")
|
||||
})
|
||||
@@ -1,4 +1,39 @@
|
||||
// Safari before 17.4 does not provide these runtime APIs; Promise.try arrived in Safari 18.2.
|
||||
import "core-js/es/map/group-by"
|
||||
import "core-js/es/promise/with-resolvers"
|
||||
import "core-js/es/promise/try"
|
||||
// Safari before 17.4 lacks Map.groupBy and Promise.withResolvers, and Promise.try arrived in Safari 18.2. Electron's
|
||||
// Chromium has all three, so these only matter for the web app.
|
||||
if (!Map.groupBy) {
|
||||
Map.groupBy = function groupBy<K, T>(items: Iterable<T>, callback: (item: T, index: number) => K) {
|
||||
const groups = new Map<K, T[]>()
|
||||
let index = 0
|
||||
|
||||
for (const item of items) {
|
||||
const key = callback(item, index++)
|
||||
const group = groups.get(key)
|
||||
|
||||
if (group) group.push(item)
|
||||
else groups.set(key, [item])
|
||||
}
|
||||
|
||||
return groups
|
||||
}
|
||||
}
|
||||
|
||||
if (!Promise.withResolvers) {
|
||||
Promise.withResolvers = function withResolvers<T>() {
|
||||
let resolve!: (value: T | PromiseLike<T>) => void
|
||||
let reject!: (reason?: Error) => void
|
||||
|
||||
const promise = new Promise<T>((res, rej) => {
|
||||
resolve = res
|
||||
reject = rej
|
||||
})
|
||||
|
||||
return { promise, resolve, reject }
|
||||
}
|
||||
}
|
||||
|
||||
if (!Promise.try) {
|
||||
// SAFETY: the callback's return type is carried through unchanged, which is all Promise.try promises.
|
||||
Promise.try = function tryCall<T, U extends unknown[]>(callback: (...args: U) => T | PromiseLike<T>, ...args: U) {
|
||||
return new Promise<T>((resolve) => resolve(callback(...args)))
|
||||
} as typeof Promise.try
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user