Skip to content

Commit

Permalink
shrink panic workaround version range
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Jun 11, 2024
1 parent 3dff8fe commit b7594fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/Features.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { TransformOptions } from 'esbuild'
import { Mode, parseOptions } from '../helpers/options'
import { version_in_range } from '../helpers/versions'
import { version, input, options, status, output } from '../stores'
import { tick } from 'svelte'
import Editor from './Editor.svelte'
Expand Down Expand Up @@ -131,9 +132,11 @@
}
if (this.cancelled) return
const skip_object_accessors = && version_in_range(esbuild.version, '0.21.0', '0.21.4')
for (const feat of features) {
// Bypass a bug where esbuild >= 0.21.0 will panic without the 'object-accessors' feature.
if (feat === 'object-accessors' && esbuild.version >= '0.21.0') {
// Bypass a bug where esbuild 0.21.0..0.21.4 will panic without the 'object-accessors' feature.
if (skip_object_accessors && feat === 'object-accessors') {
continue
}
options.supported = { [feat]: false }
Expand Down
27 changes: 27 additions & 0 deletions src/helpers/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,30 @@ export async function fetch_versions(name: string): Promise<string[]> {

throw new Error(`Failed to fetch versions for ${name}`)
}

export function version_in_range(v: string, left: string, right: string): boolean {
const a = parse(v)
const b = parse(left)
const c = parse(right)
return ge(a, b) && le(a, c)
}

function parse(v: string): number[] {
return v.split('.').map((v) => parseInt(v, 10))
}

function ge(a: number[], b: number[]): boolean {
for (let i = 0; i < a.length; i++) {
if (a[i] < b[i]) return false
if (a[i] > b[i]) return true
}
return true
}

function le(a: number[], b: number[]): boolean {
for (let i = 0; i < a.length; i++) {
if (a[i] > b[i]) return false
if (a[i] < b[i]) return true
}
return true
}

0 comments on commit b7594fd

Please sign in to comment.