Check if a node matches the `fun interface` misparse pattern
(node: SyntaxNode)
| 153 | |
| 154 | /** Check if a node matches the `fun interface` misparse pattern */ |
| 155 | function isFunInterfaceNode(node: SyntaxNode): boolean { |
| 156 | let hasFun = false; |
| 157 | let hasInterfaceType = false; |
| 158 | for (let i = 0; i < node.childCount; i++) { |
| 159 | const child = node.child(i); |
| 160 | if (!child) continue; |
| 161 | if (child.type === 'fun' && !child.isNamed) hasFun = true; |
| 162 | if (child.type === 'user_type') { |
| 163 | const typeId = child.namedChildren.find((c: SyntaxNode) => c.type === 'type_identifier'); |
| 164 | if (typeId && typeId.text === 'interface') hasInterfaceType = true; |
| 165 | } |
| 166 | // Pattern 2b: user_type("interface") is inside an ERROR child |
| 167 | if (child.type === 'ERROR') { |
| 168 | for (let j = 0; j < child.childCount; j++) { |
| 169 | const gc = child.child(j); |
| 170 | if (gc && gc.type === 'user_type') { |
| 171 | const typeId = gc.namedChildren.find((c: SyntaxNode) => c.type === 'type_identifier'); |
| 172 | if (typeId && typeId.text === 'interface') hasInterfaceType = true; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | return hasFun && hasInterfaceType; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * tree-sitter-kotlin predates functional interfaces (Kotlin 1.4): `fun |