Files
RSSHub/lib/utils/parse-js.worker.ts
Tony 3bc1cc248d chore: bump to msw v3 (#23463)
* chore: bump to msw v3

* refactor: anti-slop

* test: use vi.stubEnv for REDIS_URL in redis error test

* refactor: move remote debugging registration into a conditional block

* chore: add code coverage upload for github
2026-10-03 06:36:19 +08:00

20 lines
752 B
TypeScript

import parserWasm from '@oxc-parser/binding-wasm32-wasip1/wasm.wasm';
import { instantiate } from '@oxc-parser/binding-wasm32-wasip1/workerd';
import { type OxcError, type Program } from 'oxc-parser';
import { wrap } from 'oxc-parser/src-js/wrap.js';
let bindingPromise: ReturnType<typeof instantiate> | undefined;
export const parseScriptSource = async (source: string): Promise<{ program: Program; errors: OxcError[] }> => {
bindingPromise ??= instantiate(parserWasm);
const binding = await bindingPromise;
const { program, errors } = wrap(
binding.parseSync('script.js', source, {
lang: 'js',
sourceType: 'script',
preserveParens: false,
})
);
return { program, errors };
};