check_syntax

Function check_syntax 

Source
pub fn check_syntax(code: String, filepath: String) -> SyntaxCheckResult
Expand description

Checks if the given TypeScript code has valid syntax.

This function attempts to parse the code using SWC’s TypeScript parser without performing any macro expansion.

§Arguments

  • code - The TypeScript source code to check
  • filepath - The file path (used to determine if it’s TSX based on extension)

§Returns

A SyntaxCheckResult indicating success or containing the parse error.

§Example

const result = check_syntax("const x: number = 42;", "test.ts");
if (!result.ok) {
    console.error("Syntax error:", result.error);
}