mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-17 05:11:57 +08:00
3bc1cc248d
* 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
20 lines
752 B
TypeScript
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 };
|
|
};
|