parsers.typescript
TypeScript / JavaScript regex-based parser. Extracts functions, classes, interfaces, and type aliases from TS/JS files using regular expressions (no Node.js dependency required).
Classes
class
class TypeScriptParser(BaseParser)
Regex-based parser for TypeScript and JavaScript files.
Methods
def
def parse_file(self, filepath: str | Path) -> ModuleDoc | None
Parse a JavaScript file and extract its documentation.
Args:
filepath: The path to the JavaScript file to parse. Can be a string or a Path object.
Returns:
A ModuleDoc object representing the parsed JavaScript file, or None if the file does not exist or cannot be read.
Raises:
OSError: If the file cannot be read due to a system-level error.
UnicodeDecodeError: If the file cannot be read due to encoding issues.
def
def _build_jsdoc_map(self, source: str) -> dict[int, str]
Build mapping: position after JSDoc -> cleaned docstring.
def
def _extract_class_methods(self, source: str, class_body_start: int) -> list[FunctionDoc]
Extract methods from a class body (simplified brace matching).
Functions
def
def _clean_jsdoc(raw: str) -> str
Remove leading * from JSDoc lines, trim whitespace.
def
def _parse_params(raw: str) -> list[ArgInfo]
Parse a TypeScript/JS parameter list string.
def
def _split_params(raw: str) -> list[str]
Split a parameter string respecting nested <> and {} brackets.