mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-11-25 00:28:06 +08:00
* style: use cloudflare/oxlint-config * style: fix no-known-value-widening * style: fix typescript/only-throw-error * style: fix typescript/no-floating-promises * style: fix typescript/use-unknown-in-catch-callback-variable * style: fix typescript/no-misused-promises * style: fix typescript/no-unsafe-unary-minus * style: fix typescript/no-for-in-array * style: fix react/purity * style: fix typescript/switch-exhaustiveness-check * style: fix typescript/unbound-method * style: fix react/rules-of-hooks * style: fix typescript/return-await * style: fix react/button-has-type * style: fix react/no-unescaped-entities * style: fix import/no-namespace * style: fix typescript/no-import-type-side-effects * style: fix no-promise-executor-return * style: fix no-useless-assignment * style: fix typescript/no-misused-spread * style: fix react/jsx-no-target-blank * style: fix typescript/await-thenable * style: fix typescript/no-unnecessary-type-assertion * style: fix import/consistent-type-specifier-style * style: fix react/no-unknown-property * style: remove unused disable directive * style: merge region * style: enable prefer-smaller-scope * style: add react/no-danger * style: add unicorn-js/prefer-uint8array-base64/hex * style: move non-recommended unicorn rules to custom region
20 lines
747 B
TypeScript
20 lines
747 B
TypeScript
import parserWasm from '@oxc-parser/binding-wasm32-wasip1/wasm.wasm';
|
|
import { instantiate } from '@oxc-parser/binding-wasm32-wasip1/workerd';
|
|
import type { OxcError, 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 };
|
|
};
|