jy.ts_parse#
Tools to parse TS code
Functions
|
Default handler for nodes that don't have a specific handler. |
|
Generator function that yields parameter dictionaries. |
|
Recursively search for a 'function_type' node within a given node. |
|
Handle 'interface_declaration' nodes by traversing their members. |
|
Handle 'method_signature' nodes, yielding (method name, method info) tuples. |
|
Handle 'property_signature' nodes, yielding (property name, property info) tuples. |
|
Generator function that traverses the syntax tree and yields (name, info dict) tuples. |
|
Parse TypeScript code using the OpenAI API. |
|
- jy.ts_parse.default_handler(code, node)[source]#
Default handler for nodes that don’t have a specific handler.
- jy.ts_parse.extract_parameters(code, parameters_node)[source]#
Generator function that yields parameter dictionaries.
- jy.ts_parse.find_function_type_node(node)[source]#
Recursively search for a ‘function_type’ node within a given node.
- jy.ts_parse.handle_interface_declaration(code, node)[source]#
Handle ‘interface_declaration’ nodes by traversing their members.
- jy.ts_parse.handle_method_signature(code, node)[source]#
Handle ‘method_signature’ nodes, yielding (method name, method info) tuples.
- jy.ts_parse.handle_property_signature(code, node)[source]#
Handle ‘property_signature’ nodes, yielding (property name, property info) tuples.
- jy.ts_parse.parse_ts(code, node=None)[source]#
Generator function that traverses the syntax tree and yields (name, info dict) tuples.
If ‘node’ is None, it parses the code and starts traversal from the root node.
Example
>>> code = ''' ... interface Example { ... prop1: string; ... func1(a: number): void; ... } ... ''' >>> items = list(parse_ts(code)) >>> for name, info in items: ... print(f"Name: {name}, Kind: {info['kind']}") Name: prop1, Kind: property Name: func1, Kind: function