mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
c6cbe42e17
Pure refactor. TSDown config had got very large with the custom plugins to replace `debugAssert` calls, and hoist globals vars to top level. A PR to follow will make the situation worse, as it adds another plugin. Move the plugins into separate files, to bring the TSDown config back to a manageable size. This PR does not alter the plugin code, just moves it.
17 lines
471 B
TypeScript
17 lines
471 B
TypeScript
import { parseSync } from "oxc-parser";
|
|
|
|
import type { Program } from "@oxc-project/types";
|
|
|
|
/**
|
|
* Parse code and return the AST.
|
|
* @param path - Path to file
|
|
* @param code - Source code
|
|
* @returns AST
|
|
* @throws Error if parsing fails
|
|
*/
|
|
export function parse(path: string, code: string): Program {
|
|
const { program, errors } = parseSync(path, code);
|
|
if (errors.length !== 0) throw new Error(`Failed to parse ${path}: ${errors[0].message}`);
|
|
return program;
|
|
}
|