Skip to main content

krait/lang/
typescript.rs

1/// Returns true if the extracted lines represent a TypeScript overload stub
2/// (or `.d.ts` declaration) rather than a real implementation body.
3///
4/// The definitive signal: a real implementation always contains `{`.
5/// Overload signatures and abstract declarations have no body brace.
6#[must_use]
7pub fn is_overload_stub(lines: &[&str]) -> bool {
8    !lines.iter().any(|l| l.contains('{'))
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14
15    #[test]
16    fn stub_has_no_brace() {
17        assert!(is_overload_stub(&["function foo(x: number): string;"]));
18    }
19
20    #[test]
21    fn implementation_has_brace() {
22        assert!(!is_overload_stub(&[
23            "function foo(x: number): string {",
24            "  return x.toString();",
25            "}"
26        ]));
27    }
28
29    #[test]
30    fn empty_is_stub() {
31        assert!(is_overload_stub(&[]));
32    }
33}