* Extract a type alias (e.g. `export type X = ...` in TypeScript). * For languages like Go, resolveTypeAliasKind detects when the type_spec * wraps a struct or interface definition and creates the correct node kind. * Returns true if children should be skipped (struct/interface handled body
(node: SyntaxNode)
| 2888 | * Returns true if children should be skipped (struct/interface handled body visiting). |
| 2889 | */ |
| 2890 | private extractTypeAlias(node: SyntaxNode): boolean { |
| 2891 | if (!this.extractor) return false; |
| 2892 | |
| 2893 | const name = extractName(node, this.source, this.extractor); |
| 2894 | if (name === '<anonymous>') return false; |
| 2895 | const docstring = getPrecedingDocstring(node, this.source); |
| 2896 | const isExported = this.extractor.isExported?.(node, this.source); |
| 2897 | |
| 2898 | // Check if this type alias is actually a struct or interface definition |
| 2899 | // (e.g. Go: `type Foo struct { ... }` is a type_spec wrapping struct_type) |
| 2900 | const resolvedKind = this.extractor.resolveTypeAliasKind?.(node, this.source); |
| 2901 | |
| 2902 | if (resolvedKind === 'struct') { |
| 2903 | const structNode = this.createNode('struct', name, node, { docstring, isExported }); |
| 2904 | if (!structNode) return true; |
| 2905 | // Visit body children for field extraction |
| 2906 | this.nodeStack.push(structNode.id); |
| 2907 | // Try Go-style 'type' field first, then find inner struct child (C typedef struct) |
| 2908 | const typeChild = getChildByField(node, 'type') |
| 2909 | || this.findChildByTypes(node, this.extractor.structTypes); |
| 2910 | if (typeChild) { |
| 2911 | // Extract struct embedding (e.g. Go: `type DB struct { *Head; Queryable }`) |
| 2912 | this.extractInheritance(typeChild, structNode.id); |
| 2913 | const body = getChildByField(typeChild, this.extractor.bodyField) || typeChild; |
| 2914 | for (let i = 0; i < body.namedChildCount; i++) { |
| 2915 | const child = body.namedChild(i); |
| 2916 | if (child) this.visitNode(child); |
| 2917 | } |
| 2918 | } |
| 2919 | this.nodeStack.pop(); |
| 2920 | return true; |
| 2921 | } |
| 2922 | |
| 2923 | if (resolvedKind === 'enum') { |
| 2924 | const enumNode = this.createNode('enum', name, node, { docstring, isExported }); |
| 2925 | if (!enumNode) return true; |
| 2926 | this.nodeStack.push(enumNode.id); |
| 2927 | // Find the inner enum type child (e.g. C: typedef enum { ... } name) |
| 2928 | const innerEnum = this.findChildByTypes(node, this.extractor.enumTypes); |
| 2929 | if (innerEnum) { |
| 2930 | this.extractInheritance(innerEnum, enumNode.id); |
| 2931 | const body = this.extractor.resolveBody?.(innerEnum, this.extractor.bodyField) |
| 2932 | ?? getChildByField(innerEnum, this.extractor.bodyField); |
| 2933 | if (body) { |
| 2934 | const memberTypes = this.extractor.enumMemberTypes; |
| 2935 | for (let i = 0; i < body.namedChildCount; i++) { |
| 2936 | const child = body.namedChild(i); |
| 2937 | if (!child) continue; |
| 2938 | if (memberTypes?.includes(child.type)) { |
| 2939 | this.extractEnumMembers(child); |
| 2940 | } else { |
| 2941 | this.visitNode(child); |
| 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | } |
| 2946 | this.nodeStack.pop(); |
| 2947 | return true; |
no test coverage detected