Extract a struct-like declaration without conflating its semantic kind.
(node: SyntaxNode, kind: 'struct' | 'union')
| 1890 | |
| 1891 | /** Extract a struct-like declaration without conflating its semantic kind. */ |
| 1892 | private extractAggregate(node: SyntaxNode, kind: 'struct' | 'union'): void { |
| 1893 | if (!this.extractor) return; |
| 1894 | |
| 1895 | // Skip forward declarations and type references (no body = not a definition) |
| 1896 | // — EXCEPT C# positional records (`record struct M(decimal Amount);`), |
| 1897 | // complete definitions with no body block. (#831) |
| 1898 | const body = getChildByField(node, this.extractor.bodyField); |
| 1899 | if (!body && node.type !== 'record_declaration') return; |
| 1900 | |
| 1901 | const name = extractName(node, this.source, this.extractor); |
| 1902 | const docstring = getPrecedingDocstring(node, this.source); |
| 1903 | const visibility = this.extractor.getVisibility?.(node); |
| 1904 | const isExported = this.extractor.isExported?.(node, this.source); |
| 1905 | |
| 1906 | const aggregateNode = this.createNode(kind, name, node, { |
| 1907 | docstring, |
| 1908 | visibility, |
| 1909 | isExported, |
| 1910 | }); |
| 1911 | if (!aggregateNode) return; |
| 1912 | |
| 1913 | // Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable) |
| 1914 | this.extractInheritance(node, aggregateNode.id); |
| 1915 | |
| 1916 | // C# primary-constructor parameter dependencies (`struct P(int x)`, and |
| 1917 | // `record struct M(decimal Amount)` which the grammar nests here). |
| 1918 | this.extractCsharpPrimaryCtorParamRefs(node, aggregateNode.id); |
| 1919 | |
| 1920 | // Push to stack for field extraction (bodiless positional records have |
| 1921 | // no members to visit) |
| 1922 | if (body) { |
| 1923 | this.nodeStack.push(aggregateNode.id); |
| 1924 | for (let i = 0; i < body.namedChildCount; i++) { |
| 1925 | const child = body.namedChild(i); |
| 1926 | if (child) { |
| 1927 | this.visitNode(child); |
| 1928 | } |
| 1929 | } |
| 1930 | this.nodeStack.pop(); |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Extract an enum |
no test coverage detected