Extract an import declaration: `const X = @import("module")`.
(
state: &mut ExtractionState,
decl_node: TsNode<'_>,
builtin_node: TsNode<'_>,
name: &str,
)
| 249 | |
| 250 | /// Extract an import declaration: `const X = @import("module")`. |
| 251 | fn visit_import( |
| 252 | state: &mut ExtractionState, |
| 253 | decl_node: TsNode<'_>, |
| 254 | builtin_node: TsNode<'_>, |
| 255 | name: &str, |
| 256 | ) { |
| 257 | // Extract the module path from the string argument. |
| 258 | let module_name = |
| 259 | Self::extract_import_module(state, builtin_node).unwrap_or_else(|| name.to_string()); |
| 260 | |
| 261 | let start_line = decl_node.start_position().row as u32; |
| 262 | let end_line = decl_node.end_position().row as u32; |
| 263 | let start_column = decl_node.start_position().column as u32; |
| 264 | let end_column = decl_node.end_position().column as u32; |
| 265 | let qualified_name = format!("{}::{}", state.qualified_prefix(), module_name); |
| 266 | let id = generate_node_id(&state.file_path, &NodeKind::Use, &module_name, start_line); |
| 267 | |
| 268 | let graph_node = Node { |
| 269 | id: id.clone(), |
| 270 | kind: NodeKind::Use, |
| 271 | name: module_name, |
| 272 | qualified_name, |
| 273 | file_path: state.file_path.clone(), |
| 274 | start_line, |
| 275 | attrs_start_line: start_line, |
| 276 | end_line, |
| 277 | start_column, |
| 278 | end_column, |
| 279 | signature: Some(state.node_text(decl_node).trim().to_string()), |
| 280 | docstring: None, |
| 281 | visibility: Visibility::Private, |
| 282 | is_async: false, |
| 283 | branches: 0, |
| 284 | loops: 0, |
| 285 | returns: 0, |
| 286 | max_nesting: 0, |
| 287 | unsafe_blocks: 0, |
| 288 | unchecked_calls: 0, |
| 289 | assertions: 0, |
| 290 | updated_at: state.timestamp, |
| 291 | parent_id: None, |
| 292 | }; |
| 293 | state.nodes.push(graph_node); |
| 294 | |
| 295 | // Contains edge from parent. |
| 296 | if let Some(parent_id) = state.parent_node_id() { |
| 297 | state.edges.push(Edge { |
| 298 | source: parent_id.to_string(), |
| 299 | target: id, |
| 300 | kind: EdgeKind::Contains, |
| 301 | line: Some(start_line), |
| 302 | }); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /// Extract the module name from an @import `builtin_function` node. |
| 307 | /// |
nothing calls this directly
no test coverage detected