Skip to main content

hotspots_core/
ast.rs

1//! AST adapter layer for function discovery
2//!
3//! Global invariants enforced:
4//! - Deterministic traversal order by (file, span.start)
5//! - Formatting, comments, and whitespace must not affect results
6
7use crate::language::{FunctionBody, SourceSpan};
8
9/// Function identifier: (file_index, local_index)
10///
11/// IDs are internal only and must never appear in user output.
12/// Generated deterministically during traversal.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct FunctionId {
15    pub file_index: usize,
16    pub local_index: usize,
17}
18
19/// Stable abstraction for a function node in the AST
20#[derive(Debug, Clone)]
21pub struct FunctionNode {
22    pub id: FunctionId,
23    pub name: Option<String>,
24    pub span: SourceSpan,
25    pub body: FunctionBody,
26    pub suppression_reason: Option<String>,
27}
28
29impl FunctionNode {
30    /// Extract the start line number from the span
31    ///
32    /// Note: For backwards compatibility, this method still exists but now
33    /// simply returns the line number from the SourceSpan.
34    pub fn start_line(&self, _source_map: &swc_common::SourceMap) -> u32 {
35        self.span.start_line
36    }
37
38    /// Get the start line number directly from the span
39    pub fn line(&self) -> u32 {
40        self.span.start_line
41    }
42}