isAmbientFunctionSignature (languages/typescript.ts): a bodiless `function_signature` that is a function's declaration, not an overload of an implementation that follows it — a `declare function`, one in a `declare global` body, a declaration file's (`.d.ts`, `.d.mts`, `.d.cts`) own, and one a declaration file's `declare module 'x'` body declares. Never a namespace's (`declare namespace`, `module
(node: Node, file_path: &str)
| 1194 | /// Never a namespace's (`declare namespace`, `module Foo {}`), nor one in an |
| 1195 | /// ordinary module file's `declare module` body, an augmentation. |
| 1196 | fn is_ambient_function_signature(node: Node, file_path: &str) -> bool { |
| 1197 | if node.kind() != "function_signature" { |
| 1198 | return false; |
| 1199 | } |
| 1200 | let lower = file_path.to_ascii_lowercase(); |
| 1201 | let declaration_file = lower.ends_with(".d.ts") || lower.ends_with(".d.mts") || lower.ends_with(".d.cts"); |
| 1202 | let mut ambient = false; |
| 1203 | let mut cur = node.parent(); |
| 1204 | while let Some(p) = cur { |
| 1205 | match p.kind() { |
| 1206 | "internal_module" => return false, |
| 1207 | // `declare module 'x'`; `module Foo {}` is a namespace. |
| 1208 | "module" => { |
| 1209 | return declaration_file |
| 1210 | && p.child_by_field_name("name").is_some_and(|n| n.kind() == "string"); |
| 1211 | } |
| 1212 | "ambient_declaration" => ambient = true, |
| 1213 | _ => {} |
| 1214 | } |
| 1215 | cur = p.parent(); |
| 1216 | } |
| 1217 | ambient || declaration_file |
| 1218 | } |
| 1219 | |
| 1220 | /// hasExportDeclaration: a statement that exports by name or by assignment |
| 1221 | /// (`export {…}`, `export =`, `export default x`), not by declaring. |