|
5 | 5 |
|
6 | 6 |
|
7 | 7 | def extract_type_info(type_str: str) -> Dict[str, Any]: |
8 | | - """ |
9 | | - Extract detailed type information from a JSDoc type string. |
| 8 | + """Extract detailed type information from a JSDoc type string. |
| 9 | + |
| 10 | + This function parses the input type string to determine if it represents a |
| 11 | + union of types, a generic/template type with parameters, or a simple type. It |
| 12 | + returns a dictionary containing the parsed type information. |
10 | 13 | |
11 | 14 | Args: |
12 | | - type_str (str): The type string from a JSDoc tag |
13 | | - |
| 15 | + type_str (str): The type string from a JSDoc tag. |
| 16 | + |
14 | 17 | Returns: |
15 | | - Dict[str, Any]: A dictionary with parsed type information |
16 | | - |
17 | | - Example: |
18 | | - >>> extract_type_info('Array<string>') |
19 | | - {'name': 'Array', 'params': ['string']} |
20 | | - >>> extract_type_info('Object<string, number>') |
21 | | - {'name': 'Object', 'params': ['string', 'number']} |
22 | | - >>> extract_type_info('string|number') |
23 | | - {'union': ['string', 'number']} |
| 18 | + Dict[str, Any]: A dictionary with parsed type information. |
| 19 | + - If the type is a union, it includes a 'union' key with a list of types. |
| 20 | + - If the type is generic/template, it includes 'name' and 'params' keys. |
| 21 | + - If the type is simple, it only includes a 'name' key. |
24 | 22 | """ |
25 | 23 | result = {} |
26 | 24 |
|
@@ -65,15 +63,19 @@ def extract_type_info(type_str: str) -> Dict[str, Any]: |
65 | 63 |
|
66 | 64 |
|
67 | 65 | def merge_jsdoc_objects(base: Dict[str, Any], overlay: Dict[str, Any]) -> Dict[str, Any]: |
68 | | - """ |
69 | | - Merge two JSDoc objects, with the overlay taking precedence. |
| 66 | + """Merge two JSDoc objects, with the overlay taking precedence. |
| 67 | + |
| 68 | + The function merges two dictionaries representing JSDoc objects. If a key |
| 69 | + exists in both the base and overlay, the value from the overlay takes |
| 70 | + precedence. For keys like 'params' and 'throws', it combines the lists while |
| 71 | + ensuring that items with matching names are updated rather than duplicated. |
70 | 72 | |
71 | 73 | Args: |
72 | | - base (Dict[str, Any]): The base JSDoc object |
73 | | - overlay (Dict[str, Any]): The overlay JSDoc object that takes precedence |
74 | | - |
| 74 | + base (Dict[str, Any]): The base JSDoc object. |
| 75 | + overlay (Dict[str, Any]): The overlay JSDoc object that takes precedence. |
| 76 | + |
75 | 77 | Returns: |
76 | | - Dict[str, Any]: The merged JSDoc object |
| 78 | + Dict[str, Any]: The merged JSDoc object. |
77 | 79 | """ |
78 | 80 | result = base.copy() |
79 | 81 |
|
@@ -128,16 +130,21 @@ def merge_jsdoc_objects(base: Dict[str, Any], overlay: Dict[str, Any]) -> Dict[s |
128 | 130 |
|
129 | 131 |
|
130 | 132 | def remove_jsdoc_component(jsdoc_obj: Dict[str, Any], component_type: str, identifier: Optional[str] = None) -> Dict[str, Any]: |
131 | | - """ |
132 | | - Remove a component from a JSDoc object. |
| 133 | + """Remove a specified component from a JSDoc object. |
| 134 | + |
| 135 | + This function modifies the provided JSDoc object by removing a component based |
| 136 | + on the given type and identifier. If no identifier is provided, it removes all |
| 137 | + instances of the component type. The function handles various component types |
| 138 | + such as 'description', 'param', 'returns', 'throws', 'example', and 'tag'. |
133 | 139 | |
134 | 140 | Args: |
135 | | - jsdoc_obj (Dict[str, Any]): The JSDoc object |
136 | | - component_type (str): The component type to remove ('param', 'returns', 'throws', 'example', 'tag') |
137 | | - identifier (Optional[str]): The identifier of the component (e.g., param name, tag name) |
138 | | - |
| 141 | + jsdoc_obj (Dict[str, Any]): The JSDoc object to be modified. |
| 142 | + component_type (str): The type of component to remove ('param', 'returns', 'throws', 'example', |
| 143 | + 'tag'). |
| 144 | + identifier (Optional[str]): An optional identifier to specify which instance of the component to remove. |
| 145 | + |
139 | 146 | Returns: |
140 | | - Dict[str, Any]: The modified JSDoc object |
| 147 | + Dict[str, Any]: The modified JSDoc object with the specified component removed. |
141 | 148 | """ |
142 | 149 | result = jsdoc_obj.copy() |
143 | 150 |
|
|
0 commit comments