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

Function is_ambient_function_signature

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

1205/// Never a namespace's (`declare namespace`, `module Foo {}`), nor one in an
1206/// ordinary module file's `declare module` body, an augmentation.
1207fn is_ambient_function_signature(node: Node, file_path: &str) -> bool {
1208 if node.kind() != "function_signature" {
1209 return false;
1210 }
1211 let lower = file_path.to_ascii_lowercase();
1212 let declaration_file = lower.ends_with(".d.ts") || lower.ends_with(".d.mts") || lower.ends_with(".d.cts");
1213 let mut ambient = false;
1214 let mut cur = node.parent();
1215 while let Some(p) = cur {
1216 match p.kind() {
1217 "internal_module" => return false,
1218 // `declare module 'x'`; `module Foo {}` is a namespace.
1219 "module" => {
1220 return declaration_file
1221 && p.child_by_field_name("name").is_some_and(|n| n.kind() == "string");
1222 }
1223 "ambient_declaration" => ambient = true,
1224 _ => {}
1225 }
1226 cur = p.parent();
1227 }
1228 ambient || declaration_file
1229}
1230
1231/// hasExportDeclaration: a statement that exports by name or by assignment
1232/// (`export {…}`, `export =`, `export default x`), not by declaring.

Callers 1

visit_nodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected