|
1 | 1 | use std::iter::FusedIterator; |
2 | 2 |
|
3 | | -use oxc_allocator::{Address, GetAddress}; |
4 | 3 | use oxc_ast::{AstKind, AstType, ast::Program}; |
5 | 4 | #[cfg(feature = "cfg")] |
6 | 5 | use oxc_cfg::BlockNodeId; |
7 | 6 | use oxc_index::{IndexSlice, IndexVec}; |
8 | | -use oxc_span::{GetSpan, Span}; |
9 | 7 | use oxc_syntax::{ |
10 | 8 | node::{NodeFlags, NodeId}, |
11 | 9 | scope::ScopeId, |
12 | 10 | }; |
13 | 11 |
|
| 12 | +use super::AstNode; |
14 | 13 | use crate::ast_types_bitset::AstTypesBitset; |
15 | 14 |
|
16 | | -/// Semantic node contains all the semantic information about an ast node. |
17 | | -#[derive(Debug, Clone, Copy)] |
18 | | -pub struct AstNode<'a> { |
19 | | - id: NodeId, |
20 | | - /// A pointer to the ast node, which resides in the `bumpalo` memory arena. |
21 | | - kind: AstKind<'a>, |
22 | | - |
23 | | - /// Associated Scope (initialized by binding) |
24 | | - scope_id: ScopeId, |
25 | | -} |
26 | | - |
27 | | -impl<'a> AstNode<'a> { |
28 | | - #[inline] |
29 | | - #[cfg(feature = "cfg")] |
30 | | - pub(crate) fn new( |
31 | | - kind: AstKind<'a>, |
32 | | - scope_id: ScopeId, |
33 | | - _cfg_id: BlockNodeId, |
34 | | - id: NodeId, |
35 | | - ) -> Self { |
36 | | - Self { id, kind, scope_id } |
37 | | - } |
38 | | - |
39 | | - #[cfg(not(feature = "cfg"))] |
40 | | - pub(crate) fn new(kind: AstKind<'a>, scope_id: ScopeId, _cfg_id: (), id: NodeId) -> Self { |
41 | | - Self { id, kind, scope_id } |
42 | | - } |
43 | | - |
44 | | - /// This node's unique identifier. |
45 | | - #[inline] |
46 | | - pub fn id(&self) -> NodeId { |
47 | | - self.id |
48 | | - } |
49 | | - |
50 | | - /// Access the underlying struct from [`oxc_ast`]. |
51 | | - #[inline] |
52 | | - pub fn kind(&self) -> AstKind<'a> { |
53 | | - self.kind |
54 | | - } |
55 | | - |
56 | | - /// The scope in which this node was declared. |
57 | | - /// |
58 | | - /// It is important to note that this is _not_ the scope created _by_ the |
59 | | - /// node. For example, given a function declaration, this is the scope where |
60 | | - /// the function is declared, not the scope created by its body. |
61 | | - #[inline] |
62 | | - pub fn scope_id(&self) -> ScopeId { |
63 | | - self.scope_id |
64 | | - } |
65 | | -} |
66 | | - |
67 | | -impl GetSpan for AstNode<'_> { |
68 | | - #[inline] |
69 | | - fn span(&self) -> Span { |
70 | | - self.kind.span() |
71 | | - } |
72 | | -} |
73 | | - |
74 | | -impl GetAddress for AstNode<'_> { |
75 | | - #[inline] |
76 | | - fn address(&self) -> Address { |
77 | | - self.kind.address() |
78 | | - } |
79 | | -} |
80 | | - |
81 | 15 | /// Untyped AST nodes flattened into an vec |
82 | 16 | #[derive(Debug, Default)] |
83 | 17 | pub struct AstNodes<'a> { |
@@ -146,7 +80,7 @@ impl<'a> AstNodes<'a> { |
146 | 80 | /// Access the underlying struct from [`oxc_ast`]. |
147 | 81 | #[inline] |
148 | 82 | pub fn kind(&self, node_id: NodeId) -> AstKind<'a> { |
149 | | - self.nodes[node_id].kind |
| 83 | + self.nodes[node_id].kind() |
150 | 84 | } |
151 | 85 |
|
152 | 86 | /// Get id of this node's parent. |
@@ -200,7 +134,7 @@ impl<'a> AstNodes<'a> { |
200 | 134 | #[inline] |
201 | 135 | pub fn program(&self) -> &'a Program<'a> { |
202 | 136 | if let Some(node) = self.nodes.first() |
203 | | - && let AstKind::Program(program) = node.kind |
| 137 | + && let AstKind::Program(program) = node.kind() |
204 | 138 | { |
205 | 139 | return program; |
206 | 140 | } |
|
0 commit comments