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

Function is_ambient_function_signature

codegraph-kernel/src/tsjs/mod.rs:1196–1218  ·  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

1194/// Never a namespace's (`declare namespace`, `module Foo {}`), nor one in an
1195/// ordinary module file's `declare module` body, an augmentation.
1196fn 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.

Callers 1

visit_nodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected