Skip to content

Commit b7594fd

Browse files
committed
shrink panic workaround version range
1 parent 3dff8fe commit b7594fd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/components/Features.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import type { TransformOptions } from 'esbuild'
33
import { Mode, parseOptions } from '../helpers/options'
4+
import { version_in_range } from '../helpers/versions'
45
import { version, input, options, status, output } from '../stores'
56
import { tick } from 'svelte'
67
import Editor from './Editor.svelte'
@@ -131,9 +132,11 @@
131132
}
132133
if (this.cancelled) return
133134
135+
const skip_object_accessors = && version_in_range(esbuild.version, '0.21.0', '0.21.4')
136+
134137
for (const feat of features) {
135-
// Bypass a bug where esbuild >= 0.21.0 will panic without the 'object-accessors' feature.
136-
if (feat === 'object-accessors' && esbuild.version >= '0.21.0') {
138+
// Bypass a bug where esbuild 0.21.0..0.21.4 will panic without the 'object-accessors' feature.
139+
if (skip_object_accessors && feat === 'object-accessors') {
137140
continue
138141
}
139142
options.supported = { [feat]: false }

src/helpers/versions.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,30 @@ export async function fetch_versions(name: string): Promise<string[]> {
2121

2222
throw new Error(`Failed to fetch versions for ${name}`)
2323
}
24+
25+
export function version_in_range(v: string, left: string, right: string): boolean {
26+
const a = parse(v)
27+
const b = parse(left)
28+
const c = parse(right)
29+
return ge(a, b) && le(a, c)
30+
}
31+
32+
function parse(v: string): number[] {
33+
return v.split('.').map((v) => parseInt(v, 10))
34+
}
35+
36+
function ge(a: number[], b: number[]): boolean {
37+
for (let i = 0; i < a.length; i++) {
38+
if (a[i] < b[i]) return false
39+
if (a[i] > b[i]) return true
40+
}
41+
return true
42+
}
43+
44+
function le(a: number[], b: number[]): boolean {
45+
for (let i = 0; i < a.length; i++) {
46+
if (a[i] > b[i]) return false
47+
if (a[i] < b[i]) return true
48+
}
49+
return true
50+
}

0 commit comments

Comments
 (0)