1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![allow(non_upper_case_globals)] mod id;
mod tree;
use bitflags::bitflags;
use oxc_ast::AstKind;
pub use self::{id::AstNodeId, tree::AstNodes};
use crate::scope::{Scope, ScopeId};
pub type AstNode<'a> = indextree::Node<SemanticNode<'a>>;
#[derive(Debug, Clone, Copy)]
pub struct SemanticNode<'a> {
kind: AstKind<'a>,
scope_id: ScopeId,
flags: NodeFlags,
}
bitflags! {
#[derive(Default)]
pub struct NodeFlags: u8 {
const Class = 1 << 0; }
}
impl<'a> SemanticNode<'a> {
#[must_use]
pub fn new(kind: AstKind<'a>, scope_id: ScopeId, flags: NodeFlags) -> Self {
Self { kind, scope_id, flags }
}
#[must_use]
pub fn kind(&self) -> AstKind<'a> {
self.kind
}
#[must_use]
pub fn scope_id(&self) -> ScopeId {
self.scope_id
}
#[must_use]
pub fn strict_mode(&self, scope: &Scope) -> bool {
scope.strict_mode() || self.in_class()
}
#[must_use]
pub fn in_class(self) -> bool {
self.flags.contains(NodeFlags::Class)
}
}