MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / is_ambient_function_signature

Function is_ambient_function_signature

codegraph-kernel/src/tsjs/mod.rs:1321–1343  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1319/// Never a namespace's (`declare namespace`, `module Foo {}`), nor one in an
1320/// ordinary module file's `declare module` body, an augmentation.
1321fn is_ambient_function_signature(node: Node, file_path: &str) -> bool {
1322 if node.kind() != "function_signature" {
1323 return false;
1324 }
1325 let lower = file_path.to_ascii_lowercase();
1326 let declaration_file = lower.ends_with(".d.ts") || lower.ends_with(".d.mts") || lower.ends_with(".d.cts");
1327 let mut ambient = false;
1328 let mut cur = node.parent();
1329 while let Some(p) = cur {
1330 match p.kind() {
1331 "internal_module" => return false,
1332 // `declare module 'x'`; `module Foo {}` is a namespace.
1333 "module" => {
1334 return declaration_file
1335 && p.child_by_field_name("name").is_some_and(|n| n.kind() == "string");
1336 }
1337 "ambient_declaration" => ambient = true,
1338 _ => {}
1339 }
1340 cur = p.parent();
1341 }
1342 ambient || declaration_file
1343}
1344
1345/// hasExportDeclaration: a statement that exports by name or by assignment
1346/// (`export {…}`, `export =`, `export default x`), not by declaring.

Callers 1

visit_nodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected