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

Function is_ambient_function_signature

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

1220/// Never a namespace's (`declare namespace`, `module Foo {}`), nor one in an
1221/// ordinary module file's `declare module` body, an augmentation.
1222fn is_ambient_function_signature(node: Node, file_path: &str) -> bool {
1223 if node.kind() != "function_signature" {
1224 return false;
1225 }
1226 let lower = file_path.to_ascii_lowercase();
1227 let declaration_file = lower.ends_with(".d.ts") || lower.ends_with(".d.mts") || lower.ends_with(".d.cts");
1228 let mut ambient = false;
1229 let mut cur = node.parent();
1230 while let Some(p) = cur {
1231 match p.kind() {
1232 "internal_module" => return false,
1233 // `declare module 'x'`; `module Foo {}` is a namespace.
1234 "module" => {
1235 return declaration_file
1236 && p.child_by_field_name("name").is_some_and(|n| n.kind() == "string");
1237 }
1238 "ambient_declaration" => ambient = true,
1239 _ => {}
1240 }
1241 cur = p.parent();
1242 }
1243 ambient || declaration_file
1244}
1245
1246/// hasExportDeclaration: a statement that exports by name or by assignment
1247/// (`export {…}`, `export =`, `export default x`), not by declaring.

Callers 1

visit_nodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected