oxc_syntax/node.rs
1//! AST Node ID and flags.
2use bitflags::bitflags;
3use oxc_index::define_nonmax_u32_index_type;
4
5define_nonmax_u32_index_type! {
6 /// AST Node ID
7 pub struct NodeId;
8}
9
10impl NodeId {
11 /// Mock node id.
12 ///
13 /// This is used for synthetically-created AST nodes, among other things.
14 pub const DUMMY: Self = NodeId::new(0);
15
16 /// Node id of the Program node.
17 pub const ROOT: Self = NodeId::new(0);
18}
19
20bitflags! {
21 /// Contains additional information about an AST node.
22 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
23 pub struct NodeFlags: u8 {
24 /// Set if the Node has a JSDoc comment attached
25 const JSDoc = 1 << 0;
26 /// Set on Nodes inside classes
27 const Class = 1 << 1;
28 /// Set functions containing yield statements
29 const HasYield = 1 << 2;
30 /// Set for `export { specifier }`
31 const ExportSpecifier = 1 << 3;
32 }
33}
34
35impl NodeFlags {
36 /// Returns `true` if this node has a JSDoc comment attached to it.
37 #[inline]
38 pub fn has_jsdoc(self) -> bool {
39 self.contains(Self::JSDoc)
40 }
41
42 /// Returns `true` if this node is inside a class.
43 #[inline]
44 pub fn has_class(self) -> bool {
45 self.contains(Self::Class)
46 }
47
48 /// Returns `true` if this function has a yield statement.
49 #[inline]
50 pub fn has_yield(self) -> bool {
51 self.contains(Self::HasYield)
52 }
53
54 /// Returns `true` if this function has an export specifier.
55 #[inline]
56 pub fn has_export_specifier(self) -> bool {
57 self.contains(Self::ExportSpecifier)
58 }
59}