mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
1 parent
7dfcdfced6
commit
cc0408b5d4
45 files changed
+176
-188
No files matched your search
@@ -2,7 +2,7 @@ mod context;
|
||||
|
||||
use context::Ctx;
|
||||
pub use context::{CtxCursor, CtxFlags};
|
||||
use oxc_syntax::node::AstNodeId;
|
||||
use oxc_syntax::node::NodeId;
|
||||
use petgraph::Direction;
|
||||
|
||||
use super::{
|
||||
@@ -107,11 +107,11 @@ impl<'a> ControlFlowGraphBuilder<'a> {
|
||||
self.graph.add_edge(a, b, weight);
|
||||
}
|
||||
|
||||
pub fn push_statement(&mut self, stmt: AstNodeId) {
|
||||
pub fn push_statement(&mut self, stmt: NodeId) {
|
||||
self.push_instruction(InstructionKind::Statement, Some(stmt));
|
||||
}
|
||||
|
||||
pub fn push_return(&mut self, kind: ReturnInstructionKind, node: AstNodeId) {
|
||||
pub fn push_return(&mut self, kind: ReturnInstructionKind, node: NodeId) {
|
||||
self.push_instruction(InstructionKind::Return(kind), Some(node));
|
||||
}
|
||||
|
||||
@@ -166,20 +166,20 @@ impl<'a> ControlFlowGraphBuilder<'a> {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn append_condition_to(&mut self, block: BasicBlockId, node: Option<AstNodeId>) {
|
||||
pub fn append_condition_to(&mut self, block: BasicBlockId, node: Option<NodeId>) {
|
||||
self.push_instruction_to(block, InstructionKind::Condition, node);
|
||||
}
|
||||
|
||||
pub fn append_iteration(&mut self, node: Option<AstNodeId>, kind: IterationInstructionKind) {
|
||||
pub fn append_iteration(&mut self, node: Option<NodeId>, kind: IterationInstructionKind) {
|
||||
self.push_instruction(InstructionKind::Iteration(kind), node);
|
||||
}
|
||||
|
||||
pub fn append_throw(&mut self, node: AstNodeId) {
|
||||
pub fn append_throw(&mut self, node: NodeId) {
|
||||
self.push_instruction(InstructionKind::Throw, Some(node));
|
||||
self.append_unreachable();
|
||||
}
|
||||
|
||||
pub fn append_break(&mut self, node: AstNodeId, label: Option<&'a str>) {
|
||||
pub fn append_break(&mut self, node: NodeId, label: Option<&'a str>) {
|
||||
let kind = match label {
|
||||
Some(_) => LabeledInstruction::Labeled,
|
||||
None => LabeledInstruction::Unlabeled,
|
||||
@@ -193,7 +193,7 @@ impl<'a> ControlFlowGraphBuilder<'a> {
|
||||
self.ctx(label).r#break(bb);
|
||||
}
|
||||
|
||||
pub fn append_continue(&mut self, node: AstNodeId, label: Option<&'a str>) {
|
||||
pub fn append_continue(&mut self, node: NodeId, label: Option<&'a str>) {
|
||||
let kind = match label {
|
||||
Some(_) => LabeledInstruction::Labeled,
|
||||
None => LabeledInstruction::Unlabeled,
|
||||
@@ -221,7 +221,7 @@ impl<'a> ControlFlowGraphBuilder<'a> {
|
||||
|
||||
/// # Panics
|
||||
#[inline]
|
||||
pub(self) fn push_instruction(&mut self, kind: InstructionKind, node_id: Option<AstNodeId>) {
|
||||
pub(self) fn push_instruction(&mut self, kind: InstructionKind, node_id: Option<NodeId>) {
|
||||
self.push_instruction_to(self.current_node_ix, kind, node_id);
|
||||
}
|
||||
|
||||
@@ -230,12 +230,12 @@ impl<'a> ControlFlowGraphBuilder<'a> {
|
||||
&mut self,
|
||||
block: BasicBlockId,
|
||||
kind: InstructionKind,
|
||||
node_id: Option<AstNodeId>,
|
||||
node_id: Option<NodeId>,
|
||||
) {
|
||||
self.basic_block_mut(block).instructions.push(Instruction { kind, node_id });
|
||||
}
|
||||
|
||||
pub fn enter_statement(&mut self, stmt: AstNodeId) {
|
||||
pub fn enter_statement(&mut self, stmt: NodeId) {
|
||||
self.push_statement(stmt);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ mod dot;
|
||||
pub mod visit;
|
||||
|
||||
use itertools::Itertools;
|
||||
use oxc_syntax::node::AstNodeId;
|
||||
use oxc_syntax::node::NodeId;
|
||||
use petgraph::{
|
||||
stable_graph::NodeIndex,
|
||||
visit::{Control, DfsEvent, EdgeRef},
|
||||
@@ -44,11 +44,11 @@ impl BasicBlock {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Instruction {
|
||||
pub kind: InstructionKind,
|
||||
pub node_id: Option<AstNodeId>,
|
||||
pub node_id: Option<NodeId>,
|
||||
}
|
||||
|
||||
impl Instruction {
|
||||
pub fn new(kind: InstructionKind, node_id: Option<AstNodeId>) -> Self {
|
||||
pub fn new(kind: InstructionKind, node_id: Option<NodeId>) -> Self {
|
||||
Self { kind, node_id }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use oxc_cfg::{ControlFlowGraphBuilder, CtxCursor};
|
||||
use oxc_syntax::node::AstNodeId;
|
||||
use oxc_syntax::node::NodeId;
|
||||
/// same as but just the skeleton
|
||||
/// ```js
|
||||
/// A: {
|
||||
@@ -29,7 +29,7 @@ fn labeled_statement_with_multiple_loops_continue_and_break() {
|
||||
cfg.ctx(None).default().allow_break().allow_continue();
|
||||
cfg.ctx(None).mark_break(c2).mark_continue(c2).resolve_with_upper_label();
|
||||
|
||||
cfg.append_break(AstNodeId::DUMMY, A);
|
||||
cfg.append_break(NodeId::DUMMY, A);
|
||||
|
||||
// labeled block end
|
||||
cfg.ctx(A).mark_break(labeled).resolve();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use oxc_ast::{ast::BindingIdentifier, AstKind};
|
||||
use oxc_semantic::{AstNode, AstNodeId, IsGlobalReference, SymbolId};
|
||||
use oxc_semantic::{AstNode, IsGlobalReference, NodeId, SymbolId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator};
|
||||
|
||||
@@ -246,7 +246,7 @@ pub fn nth_outermost_paren_parent<'a, 'b>(
|
||||
/// [`Expression::get_inner_expression`].
|
||||
pub fn iter_outer_expressions<'a, 'ctx>(
|
||||
ctx: &'ctx LintContext<'a>,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
) -> impl Iterator<Item = &'ctx AstNode<'a>> + 'ctx {
|
||||
ctx.nodes().iter_parents(node_id).skip(1).filter(|parent| {
|
||||
!matches!(
|
||||
|
||||
@@ -9,7 +9,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::{Atom, GetSpan, Span};
|
||||
use oxc_syntax::identifier::is_identifier_name;
|
||||
use phf::phf_set;
|
||||
@@ -479,7 +479,7 @@ impl Rule for FuncNames {
|
||||
}
|
||||
}
|
||||
|
||||
fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: AstNodeId) -> Option<Cow<'a, str>> {
|
||||
fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: NodeId) -> Option<Cow<'a, str>> {
|
||||
for parent_kind in ctx.nodes().iter_parents(parent_id).map(AstNode::kind) {
|
||||
match parent_kind {
|
||||
AstKind::ParenthesizedExpression(_)
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -65,7 +65,7 @@ fn is_constructor(node: &AstNode<'_>) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
fn is_definitely_in_constructor(ctx: &LintContext, node_id: AstNodeId) -> bool {
|
||||
fn is_definitely_in_constructor(ctx: &LintContext, node_id: NodeId) -> bool {
|
||||
ctx.nodes()
|
||||
.ancestors(node_id)
|
||||
.map(|id| ctx.nodes().get_node(id))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use oxc_ast::{ast::Expression, AstKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNodeId, SymbolId};
|
||||
use oxc_semantic::{NodeId, SymbolId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_syntax::operator::UnaryOperator;
|
||||
use phf::phf_set;
|
||||
@@ -106,7 +106,7 @@ impl Rule for NoImportAssign {
|
||||
/// - `Reflect.deleteProperty`
|
||||
/// - `Reflect.set`
|
||||
/// - `Reflect.setPrototypeOf`
|
||||
fn is_argument_of_well_known_mutation_function(node_id: AstNodeId, ctx: &LintContext<'_>) -> bool {
|
||||
fn is_argument_of_well_known_mutation_function(node_id: NodeId, ctx: &LintContext<'_>) -> bool {
|
||||
let current_node = ctx.nodes().get_node(node_id);
|
||||
let call_expression_node =
|
||||
ctx.nodes().parent_node(node_id).and_then(|node| ctx.nodes().parent_kind(node.id()));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -52,7 +52,7 @@ impl Rule for NoMultiStr {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_within_jsx_attribute_item(id: AstNodeId, ctx: &LintContext) -> bool {
|
||||
fn is_within_jsx_attribute_item(id: NodeId, ctx: &LintContext) -> bool {
|
||||
if matches!(ctx.nodes().parent_kind(id), Some(AstKind::JSXAttributeItem(_))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use oxc_cfg::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -62,7 +62,7 @@ impl Rule for NoThisBeforeSuper {
|
||||
// first pass -> find super calls and local violations
|
||||
let mut wanted_nodes = Vec::new();
|
||||
let mut basic_blocks_with_super_called = HashSet::<BasicBlockId>::new();
|
||||
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<AstNodeId>>::new();
|
||||
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<NodeId>>::new();
|
||||
for node in semantic.nodes().iter() {
|
||||
match node.kind() {
|
||||
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
|
||||
@@ -153,7 +153,7 @@ impl NoThisBeforeSuper {
|
||||
cfg: &ControlFlowGraph,
|
||||
id: BasicBlockId,
|
||||
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
|
||||
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
|
||||
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
|
||||
follow_join: bool,
|
||||
) -> Vec<DefinitelyCallsThisBeforeSuper> {
|
||||
neighbors_filtered_by_edge_weight(
|
||||
@@ -212,7 +212,7 @@ impl NoThisBeforeSuper {
|
||||
cfg: &ControlFlowGraph,
|
||||
output: Vec<DefinitelyCallsThisBeforeSuper>,
|
||||
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
|
||||
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
|
||||
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
|
||||
) -> bool {
|
||||
// Deciding whether we definitely call this before super in all
|
||||
// codepaths is as simple as seeing if any individual codepath
|
||||
|
||||
@@ -2,7 +2,7 @@ use itertools::Itertools;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNode, AstNodeId, AstNodes};
|
||||
use oxc_semantic::{AstNode, AstNodes, NodeId};
|
||||
use oxc_span::Span;
|
||||
use oxc_syntax::class::ElementKind;
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Rule for NoUnusedPrivateClassMembers {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_read(current_node_id: AstNodeId, nodes: &AstNodes) -> bool {
|
||||
fn is_read(current_node_id: NodeId, nodes: &AstNodes) -> bool {
|
||||
for (curr, parent) in nodes
|
||||
.iter_parents(nodes.parent_id(current_node_id).unwrap_or(current_node_id))
|
||||
.tuple_windows::<(&AstNode<'_>, &AstNode<'_>)>()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! consider variables ignored by name pattern, but by where they are declared.
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::{ast::*, AstKind};
|
||||
use oxc_semantic::{AstNode, AstNodeId, Semantic};
|
||||
use oxc_semantic::{AstNode, NodeId, Semantic};
|
||||
use oxc_span::GetSpan;
|
||||
|
||||
use super::{options::ArgsOption, NoUnusedVars, Symbol};
|
||||
@@ -154,7 +154,7 @@ impl NoUnusedVars {
|
||||
pub(super) fn is_allowed_type_parameter(
|
||||
&self,
|
||||
symbol: &Symbol<'_, '_>,
|
||||
declaration_id: AstNodeId,
|
||||
declaration_id: NodeId,
|
||||
) -> bool {
|
||||
matches!(symbol.nodes().parent_kind(declaration_id), Some(AstKind::TSMappedType(_)))
|
||||
}
|
||||
@@ -234,7 +234,7 @@ impl NoUnusedVars {
|
||||
.any(|p| p.has_modifier() || p.pattern.has_any_used_binding(ctx))
|
||||
}
|
||||
|
||||
/// `params_id` is the [`AstNodeId`] to a [`AstKind::FormalParameters`] node.
|
||||
/// `params_id` is the [`NodeId`] to a [`AstKind::FormalParameters`] node.
|
||||
///
|
||||
/// The following allowed conditions are handled:
|
||||
/// 1. setter parameters - removing them causes a syntax error.
|
||||
@@ -242,7 +242,7 @@ impl NoUnusedVars {
|
||||
fn is_allowed_param_because_of_method<'a>(
|
||||
semantic: &Semantic<'a>,
|
||||
param: &FormalParameter<'a>,
|
||||
params_id: AstNodeId,
|
||||
params_id: NodeId,
|
||||
) -> bool {
|
||||
let mut parents_iter = semantic.nodes().iter_parents(params_id).skip(1).map(AstNode::kind);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use oxc_ast::{
|
||||
ast::{Expression, VariableDeclarator},
|
||||
AstKind,
|
||||
};
|
||||
use oxc_semantic::{AstNode, AstNodeId};
|
||||
use oxc_semantic::{AstNode, NodeId};
|
||||
use oxc_span::CompactStr;
|
||||
use regex::Regex;
|
||||
|
||||
@@ -28,7 +28,7 @@ impl NoUnusedVars {
|
||||
fixer: RuleFixer<'_, 'a>,
|
||||
symbol: &Symbol<'_, 'a>,
|
||||
decl: &VariableDeclarator<'a>,
|
||||
decl_id: AstNodeId,
|
||||
decl_id: NodeId,
|
||||
) -> RuleFix<'a> {
|
||||
if decl.init.as_ref().is_some_and(|init| is_skipped_init(symbol, init)) {
|
||||
return fixer.noop();
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_ast::{
|
||||
AstKind,
|
||||
};
|
||||
use oxc_semantic::{
|
||||
AstNode, AstNodeId, AstNodes, Reference, ScopeId, ScopeTree, Semantic, SymbolFlags, SymbolId,
|
||||
AstNode, AstNodes, NodeId, Reference, ScopeId, ScopeTree, Semantic, SymbolFlags, SymbolId,
|
||||
SymbolTable,
|
||||
};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
@@ -77,7 +77,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn declaration_id(&self) -> AstNodeId {
|
||||
fn declaration_id(&self) -> NodeId {
|
||||
self.symbols().get_declaration(self.id)
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||
|
||||
pub fn iter_relevant_parents(
|
||||
&self,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
) -> impl Iterator<Item = &AstNode<'a>> + Clone + '_ {
|
||||
self.nodes().iter_parents(node_id).skip(1).filter(|n| Self::is_relevant_kind(n.kind()))
|
||||
}
|
||||
|
||||
pub fn iter_relevant_parent_and_grandparent_kinds(
|
||||
&self,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
) -> impl Iterator<Item = (/* parent */ AstKind<'a>, /* grandparent */ AstKind<'a>)> + Clone + '_
|
||||
{
|
||||
let parents_iter = self
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::{ast::*, AstKind};
|
||||
use oxc_semantic::{AstNode, AstNodeId, Reference, ScopeId, SymbolFlags, SymbolId};
|
||||
use oxc_semantic::{AstNode, NodeId, Reference, ScopeId, SymbolFlags, SymbolId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use super::{ignored::FoundStatus, NoUnusedVars, Symbol};
|
||||
@@ -427,7 +427,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||
}
|
||||
|
||||
/// Check if a [`AstNode`] is within a return statement or implicit return.
|
||||
fn is_in_return_statement(&self, node_id: AstNodeId) -> bool {
|
||||
fn is_in_return_statement(&self, node_id: NodeId) -> bool {
|
||||
for parent in self.iter_relevant_parents(node_id).map(AstNode::kind) {
|
||||
match parent {
|
||||
AstKind::ReturnStatement(_) => return true,
|
||||
@@ -660,7 +660,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||
|
||||
/// Find the [`SymbolId`] for the nearest function declaration or expression
|
||||
/// that is a parent of `node_id`.
|
||||
fn get_nearest_function(&self, node_id: AstNodeId) -> Option<SymbolId> {
|
||||
fn get_nearest_function(&self, node_id: NodeId) -> Option<SymbolId> {
|
||||
// set to `true` when we find an arrow function and we want to get its
|
||||
// name from the variable its assigned to.
|
||||
let mut needs_variable_identifier = false;
|
||||
|
||||
@@ -2,7 +2,7 @@ use memchr::memmem;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -103,7 +103,7 @@ impl Rule for NoUselessEscape {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_within_jsx_attribute_item(id: AstNodeId, ctx: &LintContext) -> bool {
|
||||
fn is_within_jsx_attribute_item(id: NodeId, ctx: &LintContext) -> bool {
|
||||
if matches!(ctx.nodes().parent_kind(id), Some(AstKind::JSXAttributeItem(_))) {
|
||||
return true;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ fn is_within_jsx_attribute_item(id: AstNodeId, ctx: &LintContext) -> bool {
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn check(ctx: &LintContext<'_>, node_id: AstNodeId, start: u32, offsets: &[usize]) {
|
||||
fn check(ctx: &LintContext<'_>, node_id: NodeId, start: u32, offsets: &[usize]) {
|
||||
let source_text = ctx.source_text();
|
||||
for offset in offsets {
|
||||
let offset = start as usize + offset;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNode, AstNodeId};
|
||||
use oxc_semantic::{AstNode, NodeId};
|
||||
use oxc_span::Span;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
@@ -98,7 +98,7 @@ fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>)
|
||||
|
||||
fn check_parents<'a>(
|
||||
node: &AstNode<'a>,
|
||||
visited: &mut FxHashSet<AstNodeId>,
|
||||
visited: &mut FxHashSet<NodeId>,
|
||||
in_conditional: InConditional,
|
||||
ctx: &LintContext<'a>,
|
||||
) -> InConditional {
|
||||
|
||||
@@ -4,7 +4,7 @@ use cow_utils::CowUtils;
|
||||
use oxc_ast::{ast::MemberExpression, AstKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNode, AstNodeId, ReferenceId};
|
||||
use oxc_semantic::{AstNode, NodeId, ReferenceId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{
|
||||
@@ -151,7 +151,7 @@ fn handle_jest_set_time_out<'a>(
|
||||
reference_id_list: impl Iterator<Item = ReferenceId>,
|
||||
jest_reference_id_list: &Vec<(ReferenceId, Span)>,
|
||||
seen_jest_set_timeout: &mut bool,
|
||||
id_to_jest_node_map: &HashMap<AstNodeId, &PossibleJestNode<'a, '_>>,
|
||||
id_to_jest_node_map: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
|
||||
) {
|
||||
let nodes = ctx.nodes();
|
||||
let scopes = ctx.scopes();
|
||||
@@ -199,7 +199,7 @@ fn handle_jest_set_time_out<'a>(
|
||||
|
||||
fn is_jest_fn_call<'a>(
|
||||
parent_node: &AstNode<'a>,
|
||||
id_to_jest_node_map: &HashMap<AstNodeId, &PossibleJestNode<'a, '_>>,
|
||||
id_to_jest_node_map: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
|
||||
ctx: &LintContext<'a>,
|
||||
) -> bool {
|
||||
let mut id = parent_node.id();
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{
|
||||
@@ -104,7 +104,7 @@ impl Rule for NoDuplicateHooks {
|
||||
let Some(root_node) = ctx.nodes().root_node() else {
|
||||
return;
|
||||
};
|
||||
let mut hook_contexts: HashMap<AstNodeId, Vec<HashMap<String, i32>>> = HashMap::new();
|
||||
let mut hook_contexts: HashMap<NodeId, Vec<HashMap<String, i32>>> = HashMap::new();
|
||||
hook_contexts.insert(root_node.id(), Vec::new());
|
||||
|
||||
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
|
||||
@@ -119,8 +119,8 @@ impl Rule for NoDuplicateHooks {
|
||||
impl NoDuplicateHooks {
|
||||
fn run<'a>(
|
||||
possible_jest_node: &PossibleJestNode<'a, '_>,
|
||||
root_node_id: AstNodeId,
|
||||
hook_contexts: &mut HashMap<AstNodeId, Vec<HashMap<String, i32>>>,
|
||||
root_node_id: NodeId,
|
||||
hook_contexts: &mut HashMap<NodeId, Vec<HashMap<String, i32>>>,
|
||||
ctx: &LintContext<'a>,
|
||||
) {
|
||||
let node = possible_jest_node.node;
|
||||
|
||||
@@ -6,7 +6,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{
|
||||
@@ -100,7 +100,7 @@ impl Rule for NoIdenticalTitle {
|
||||
let parent = span_to_parent_mapping.get(span)?;
|
||||
Some((*span, *kind, *parent))
|
||||
})
|
||||
.collect::<Vec<(Span, JestFnKind, AstNodeId)>>();
|
||||
.collect::<Vec<(Span, JestFnKind, NodeId)>>();
|
||||
// After being sorted by parent_id, the span with the same parent will be placed nearby.
|
||||
kind_and_spans.sort_by(|a, b| a.2.cmp(&b.2));
|
||||
|
||||
@@ -129,7 +129,7 @@ fn filter_and_process_jest_result<'a>(
|
||||
call_expr: &'a CallExpression<'a>,
|
||||
possible_jest_node: &PossibleJestNode<'a, '_>,
|
||||
ctx: &LintContext<'a>,
|
||||
) -> Option<(Span, &'a str, JestFnKind, AstNodeId)> {
|
||||
) -> Option<(Span, &'a str, JestFnKind, NodeId)> {
|
||||
let result = parse_general_jest_fn_call(call_expr, possible_jest_node, ctx)?;
|
||||
let kind = result.kind;
|
||||
// we only need check `describe` or `test` block
|
||||
@@ -154,7 +154,7 @@ fn filter_and_process_jest_result<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn get_closest_block(node: &AstNode, ctx: &LintContext) -> Option<AstNodeId> {
|
||||
fn get_closest_block(node: &AstNode, ctx: &LintContext) -> Option<NodeId> {
|
||||
match node.kind() {
|
||||
AstKind::BlockStatement(_) | AstKind::FunctionBody(_) | AstKind::Program(_) => {
|
||||
Some(node.id())
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{
|
||||
@@ -91,7 +91,7 @@ impl NoStandaloneExpect {
|
||||
fn run<'a>(
|
||||
&self,
|
||||
possible_jest_node: &PossibleJestNode<'a, '_>,
|
||||
id_nodes_mapping: &HashMap<AstNodeId, &PossibleJestNode<'a, '_>>,
|
||||
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
|
||||
ctx: &LintContext<'a>,
|
||||
) {
|
||||
let node = possible_jest_node.node;
|
||||
@@ -129,7 +129,7 @@ impl NoStandaloneExpect {
|
||||
fn is_correct_place_to_call_expect<'a>(
|
||||
node: &AstNode<'a>,
|
||||
additional_test_block_functions: &[String],
|
||||
id_nodes_mapping: &HashMap<AstNodeId, &PossibleJestNode<'a, '_>>,
|
||||
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
|
||||
ctx: &LintContext<'a>,
|
||||
) -> Option<()> {
|
||||
let mut parent = ctx.nodes().parent_node(node.id())?;
|
||||
@@ -197,7 +197,7 @@ fn is_correct_place_to_call_expect<'a>(
|
||||
fn is_var_declarator_or_test_block<'a>(
|
||||
node: &AstNode<'a>,
|
||||
additional_test_block_functions: &[String],
|
||||
id_nodes_mapping: &HashMap<AstNodeId, &PossibleJestNode<'a, '_>>,
|
||||
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
|
||||
ctx: &LintContext<'a>,
|
||||
) -> bool {
|
||||
match node.kind() {
|
||||
|
||||
@@ -7,7 +7,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNodeId, SymbolId};
|
||||
use oxc_semantic::{NodeId, SymbolId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{
|
||||
@@ -198,7 +198,7 @@ fn check_loop_usage<'a>(
|
||||
declaration_node: &AstNode<'a>,
|
||||
declarator: &AstNode<'a>,
|
||||
referenced_symbol_id: SymbolId,
|
||||
spread_node_id: AstNodeId,
|
||||
spread_node_id: NodeId,
|
||||
spread_span: Span,
|
||||
ctx: &LintContext<'a>,
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -49,7 +49,7 @@ impl Rule for NoAsyncAwait {
|
||||
}
|
||||
}
|
||||
|
||||
fn report(node_id: AstNodeId, func_span: Span, ctx: &LintContext<'_>) {
|
||||
fn report(node_id: NodeId, func_span: Span, ctx: &LintContext<'_>) {
|
||||
/// "async".len()
|
||||
const ASYNC_LEN: u32 = 5;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::{Error, LabeledSpan, OxcDiagnostic};
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::{GetSpan as _, Span};
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -470,7 +470,7 @@ fn is_allowed_string_like<'a>(
|
||||
ctx: &LintContext<'a>,
|
||||
s: &'a str,
|
||||
container: &JSXExpressionContainer<'a>,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
is_prop: bool,
|
||||
) -> bool {
|
||||
is_whitespace(s)
|
||||
@@ -530,7 +530,7 @@ fn report_unnecessary_curly<'a>(
|
||||
fn has_adjacent_jsx_expression_containers<'a>(
|
||||
ctx: &LintContext<'a>,
|
||||
container: &JSXExpressionContainer<'a>,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
// element: &JSXElement<'a>,
|
||||
) -> bool {
|
||||
let Some(parent) = ctx.semantic().nodes().parent_kind(node_id) else { return false };
|
||||
|
||||
@@ -7,7 +7,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -200,7 +200,7 @@ fn has_less_than_two_children(children: &oxc_allocator::Vec<'_, JSXChild<'_>>) -
|
||||
}
|
||||
|
||||
fn is_fragment_with_only_text_and_is_not_child<'a>(
|
||||
id: AstNodeId,
|
||||
id: NodeId,
|
||||
node: &oxc_allocator::Vec<'a, JSXChild<'a>>,
|
||||
ctx: &LintContext,
|
||||
) -> bool {
|
||||
|
||||
@@ -9,7 +9,7 @@ use oxc_cfg::{
|
||||
ControlFlowGraph, EdgeType, ErrorEdgeKind, InstructionKind,
|
||||
};
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNodeId, AstNodes};
|
||||
use oxc_semantic::{AstNodes, NodeId};
|
||||
use oxc_syntax::operator::AssignmentOperator;
|
||||
|
||||
use crate::{
|
||||
@@ -331,7 +331,7 @@ fn parent_func<'a>(nodes: &'a AstNodes<'a>, node: &AstNode) -> Option<&'a AstNod
|
||||
/// And that function isn't a `React.memo` or `React.forwardRef`.
|
||||
/// Returns `true` if this node is a function argument and that isn't a React special function.
|
||||
/// Otherwise it would return `false`.
|
||||
fn is_non_react_func_arg(nodes: &AstNodes, node_id: AstNodeId) -> bool {
|
||||
fn is_non_react_func_arg(nodes: &AstNodes, node_id: NodeId) -> bool {
|
||||
let argument = match nodes.parent_node(node_id) {
|
||||
Some(parent) if matches!(parent.kind(), AstKind::Argument(_)) => parent,
|
||||
_ => return false,
|
||||
@@ -344,7 +344,7 @@ fn is_non_react_func_arg(nodes: &AstNodes, node_id: AstNodeId) -> bool {
|
||||
!(is_react_function_call(call, "forwardRef") || is_react_function_call(call, "memo"))
|
||||
}
|
||||
|
||||
fn is_somewhere_inside_component_or_hook(nodes: &AstNodes, node_id: AstNodeId) -> bool {
|
||||
fn is_somewhere_inside_component_or_hook(nodes: &AstNodes, node_id: NodeId) -> bool {
|
||||
nodes
|
||||
.ancestors(node_id)
|
||||
.map(|id| nodes.get_node(id))
|
||||
@@ -370,7 +370,7 @@ fn is_somewhere_inside_component_or_hook(nodes: &AstNodes, node_id: AstNodeId) -
|
||||
|
||||
fn get_declaration_identifier<'a>(
|
||||
nodes: &'a AstNodes<'a>,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
) -> Option<Cow<'a, str>> {
|
||||
nodes.ancestors(node_id).map(|id| nodes.kind(id)).find_map(|kind| {
|
||||
match kind {
|
||||
@@ -397,7 +397,7 @@ fn get_declaration_identifier<'a>(
|
||||
})
|
||||
}
|
||||
|
||||
fn is_export_default<'a>(nodes: &'a AstNodes<'a>, node_id: AstNodeId) -> bool {
|
||||
fn is_export_default<'a>(nodes: &'a AstNodes<'a>, node_id: NodeId) -> bool {
|
||||
nodes
|
||||
.ancestors(node_id)
|
||||
.map(|id| nodes.get_node(id))
|
||||
@@ -407,7 +407,7 @@ fn is_export_default<'a>(nodes: &'a AstNodes<'a>, node_id: AstNodeId) -> bool {
|
||||
|
||||
/// # Panics
|
||||
/// `node_id` should always point to a valid `Function`.
|
||||
fn is_memo_or_forward_ref_callback(nodes: &AstNodes, node_id: AstNodeId) -> bool {
|
||||
fn is_memo_or_forward_ref_callback(nodes: &AstNodes, node_id: NodeId) -> bool {
|
||||
nodes.ancestors(node_id).map(|id| nodes.get_node(id)).any(|node| {
|
||||
if let AstKind::CallExpression(call) = node.kind() {
|
||||
call.callee_name().is_some_and(|name| matches!(name, "forwardRef" | "memo"))
|
||||
|
||||
+2
-7
@@ -15,7 +15,7 @@ use oxc_ast::{
|
||||
},
|
||||
AstKind,
|
||||
};
|
||||
use oxc_semantic::{AstNode, AstNodeId};
|
||||
use oxc_semantic::{AstNode, NodeId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_syntax::operator::{LogicalOperator, UnaryOperator};
|
||||
|
||||
@@ -302,12 +302,7 @@ impl<'a> ListenerMap for AstNode<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_on_imported_call(
|
||||
span: Span,
|
||||
name: &str,
|
||||
node_id: AstNodeId,
|
||||
options: &NodeListenerOptions,
|
||||
) {
|
||||
fn report_on_imported_call(span: Span, name: &str, node_id: NodeId, options: &NodeListenerOptions) {
|
||||
if has_comment_about_side_effect_check(span, options.ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{ast_util::is_method_call, context::LintContext, rule::Rule, AstNode};
|
||||
@@ -125,7 +125,7 @@ fn is_promise_method_with_single_argument(call_expr: &CallExpression) -> bool {
|
||||
is_method_call(call_expr, Some(&["Promise"]), Some(&["all", "any", "race"]), Some(1), Some(1))
|
||||
}
|
||||
|
||||
fn is_fixable(call_node_id: AstNodeId, ctx: &LintContext<'_>) -> bool {
|
||||
fn is_fixable(call_node_id: NodeId, ctx: &LintContext<'_>) -> bool {
|
||||
for parent in ctx.semantic().nodes().iter_parents(call_node_id).skip(1) {
|
||||
match parent.kind() {
|
||||
AstKind::CallExpression(_)
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, utils::get_first_parameter_name, AstNode};
|
||||
@@ -188,7 +188,7 @@ fn is_matching_native_coercion_function_call(
|
||||
}
|
||||
|
||||
fn check_array_callback_methods(
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
arg: &FormalParameters,
|
||||
function_body: &FunctionBody,
|
||||
is_arrow: bool,
|
||||
|
||||
@@ -5,7 +5,7 @@ use oxc_ast::{
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::AstNodeId;
|
||||
use oxc_semantic::NodeId;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
@@ -102,7 +102,7 @@ fn get_replacement(node: &str) -> Option<&'static str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn is_jsx_meta_elem_with_charset_attr(id: AstNodeId, ctx: &LintContext) -> bool {
|
||||
fn is_jsx_meta_elem_with_charset_attr(id: NodeId, ctx: &LintContext) -> bool {
|
||||
let Some(parent) = ctx.nodes().parent_node(id) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashSet;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNode, AstNodeId};
|
||||
use oxc_semantic::{AstNode, NodeId};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{
|
||||
@@ -19,7 +19,7 @@ fn use_prefer_each(span: Span, fn_name: &str) -> OxcDiagnostic {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_in_test(ctx: &LintContext<'_>, id: AstNodeId) -> bool {
|
||||
fn is_in_test(ctx: &LintContext<'_>, id: NodeId) -> bool {
|
||||
ctx.nodes().iter_parents(id).any(|node| {
|
||||
let AstKind::CallExpression(ancestor_call_expr) = node.kind() else { return false };
|
||||
let Some(ancestor_member_expr) = ancestor_call_expr.callee.as_member_expression() else {
|
||||
@@ -70,7 +70,7 @@ declare_oxc_lint!(
|
||||
|
||||
impl Rule for PreferEach {
|
||||
fn run_once(&self, ctx: &LintContext<'_>) {
|
||||
let mut skip = HashSet::<AstNodeId>::new();
|
||||
let mut skip = HashSet::<NodeId>::new();
|
||||
ctx.nodes().iter().for_each(|node| {
|
||||
Self::run(node, ctx, &mut skip);
|
||||
});
|
||||
@@ -78,7 +78,7 @@ impl Rule for PreferEach {
|
||||
}
|
||||
|
||||
impl PreferEach {
|
||||
fn run<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>, skip: &mut HashSet<AstNodeId>) {
|
||||
fn run<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>, skip: &mut HashSet<NodeId>) {
|
||||
let kind = node.kind();
|
||||
|
||||
let AstKind::CallExpression(call_expr) = kind else { return };
|
||||
|
||||
@@ -5,7 +5,7 @@ use oxc_ast::{
|
||||
ast::{Expression, IdentifierReference, StaticMemberExpression},
|
||||
AstKind, CommentKind,
|
||||
};
|
||||
use oxc_semantic::{AstNode, AstNodeId, SymbolId};
|
||||
use oxc_semantic::{AstNode, NodeId, SymbolId};
|
||||
use oxc_span::{CompactStr, GetSpan, Span};
|
||||
use oxc_syntax::operator::{BinaryOperator, LogicalOperator, UnaryOperator};
|
||||
use rustc_hash::FxHashSet;
|
||||
@@ -135,7 +135,7 @@ impl Value {
|
||||
}
|
||||
|
||||
pub fn get_write_expr<'a, 'b>(
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
ctx: &'b LintContext<'a>,
|
||||
) -> Option<&'b Expression<'a>> {
|
||||
let parent = ctx.nodes().parent_node(node_id)?;
|
||||
|
||||
@@ -27,7 +27,7 @@ use crate::{
|
||||
jsdoc::JSDocBuilder,
|
||||
label::UnusedLabels,
|
||||
module_record::ModuleRecordBuilder,
|
||||
node::{AstNodeId, AstNodes, NodeFlags},
|
||||
node::{AstNodes, NodeFlags, NodeId},
|
||||
reference::{Reference, ReferenceFlags, ReferenceId},
|
||||
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
|
||||
symbol::{SymbolFlags, SymbolId, SymbolTable},
|
||||
@@ -72,12 +72,12 @@ pub struct SemanticBuilder<'a> {
|
||||
errors: RefCell<Vec<OxcDiagnostic>>,
|
||||
|
||||
// states
|
||||
pub(crate) current_node_id: AstNodeId,
|
||||
pub(crate) current_node_id: NodeId,
|
||||
pub(crate) current_node_flags: NodeFlags,
|
||||
pub(crate) current_symbol_flags: SymbolFlags,
|
||||
pub(crate) current_scope_id: ScopeId,
|
||||
/// Stores current `AstKind::Function` and `AstKind::ArrowFunctionExpression` during AST visit
|
||||
pub(crate) function_stack: Vec<AstNodeId>,
|
||||
pub(crate) function_stack: Vec<NodeId>,
|
||||
// To make a namespace/module value like
|
||||
// we need the to know the modules we are inside
|
||||
// and when we reach a value declaration we set it
|
||||
@@ -108,7 +108,7 @@ pub struct SemanticBuilder<'a> {
|
||||
|
||||
pub(crate) class_table_builder: ClassTableBuilder,
|
||||
|
||||
ast_node_records: Vec<AstNodeId>,
|
||||
ast_node_records: Vec<NodeId>,
|
||||
}
|
||||
|
||||
/// Data returned by [`SemanticBuilder::build`].
|
||||
@@ -128,7 +128,7 @@ impl<'a> SemanticBuilder<'a> {
|
||||
source_type: SourceType::default(),
|
||||
trivias: trivias.clone(),
|
||||
errors: RefCell::new(vec![]),
|
||||
current_node_id: AstNodeId::new(0),
|
||||
current_node_id: NodeId::new(0),
|
||||
current_node_flags: NodeFlags::empty(),
|
||||
current_symbol_flags: SymbolFlags::empty(),
|
||||
current_reference_flags: ReferenceFlags::empty(),
|
||||
@@ -218,7 +218,7 @@ impl<'a> SemanticBuilder<'a> {
|
||||
pub fn build(mut self, program: &Program<'a>) -> SemanticBuilderReturn<'a> {
|
||||
self.source_type = program.source_type;
|
||||
if self.source_type.is_typescript_definition() {
|
||||
let scope_id = self.scope.add_scope(None, AstNodeId::DUMMY, ScopeFlags::Top);
|
||||
let scope_id = self.scope.add_scope(None, NodeId::DUMMY, ScopeFlags::Top);
|
||||
program.scope_id.set(Some(scope_id));
|
||||
} else {
|
||||
// Count the number of nodes, scopes, symbols, and references.
|
||||
@@ -314,13 +314,13 @@ impl<'a> SemanticBuilder<'a> {
|
||||
#[inline]
|
||||
fn record_ast_nodes(&mut self) {
|
||||
if self.cfg.is_some() {
|
||||
self.ast_node_records.push(AstNodeId::DUMMY);
|
||||
self.ast_node_records.push(NodeId::DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn retrieve_recorded_ast_node(&mut self) -> Option<AstNodeId> {
|
||||
fn retrieve_recorded_ast_node(&mut self) -> Option<NodeId> {
|
||||
if self.cfg.is_some() {
|
||||
Some(self.ast_node_records.pop().expect("there is no ast node record to stop."))
|
||||
} else {
|
||||
@@ -335,7 +335,7 @@ impl<'a> SemanticBuilder<'a> {
|
||||
// <https://github.com/oxc-project/oxc/pull/4273>
|
||||
if self.cfg.is_some() {
|
||||
if let Some(record) = self.ast_node_records.last_mut() {
|
||||
if *record == AstNodeId::DUMMY {
|
||||
if *record == NodeId::DUMMY {
|
||||
*record = self.current_node_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_ast::{
|
||||
use oxc_span::GetSpan;
|
||||
use oxc_syntax::class::{ClassId, ElementKind};
|
||||
|
||||
use crate::{AstNodeId, AstNodes};
|
||||
use crate::{AstNodes, NodeId};
|
||||
|
||||
use super::{
|
||||
table::{Element, PrivateIdentifierReference},
|
||||
@@ -33,7 +33,7 @@ impl ClassTableBuilder {
|
||||
pub fn declare_class_body(
|
||||
&mut self,
|
||||
class: &ClassBody,
|
||||
current_node_id: AstNodeId,
|
||||
current_node_id: NodeId,
|
||||
nodes: &AstNodes,
|
||||
) {
|
||||
let parent_id = nodes.parent_id(current_node_id).unwrap_or_else(|| unreachable!());
|
||||
@@ -98,7 +98,7 @@ impl ClassTableBuilder {
|
||||
pub fn add_private_identifier_reference(
|
||||
&mut self,
|
||||
ident: &PrivateIdentifier,
|
||||
current_node_id: AstNodeId,
|
||||
current_node_id: NodeId,
|
||||
nodes: &AstNodes,
|
||||
) {
|
||||
let parent_kind = nodes.parent_kind(current_node_id);
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxc_index::IndexVec;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
use oxc_syntax::class::{ClassId, ElementId, ElementKind};
|
||||
|
||||
use crate::node::AstNodeId;
|
||||
use crate::node::NodeId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Element {
|
||||
@@ -29,14 +29,14 @@ impl Element {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PrivateIdentifierReference {
|
||||
pub id: AstNodeId,
|
||||
pub id: NodeId,
|
||||
pub name: CompactStr,
|
||||
pub span: Span,
|
||||
pub element_ids: Vec<ElementId>,
|
||||
}
|
||||
|
||||
impl PrivateIdentifierReference {
|
||||
pub fn new(id: AstNodeId, name: CompactStr, span: Span, element_ids: Vec<ElementId>) -> Self {
|
||||
pub fn new(id: NodeId, name: CompactStr, span: Span, element_ids: Vec<ElementId>) -> Self {
|
||||
Self { id, name, span, element_ids }
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl PrivateIdentifierReference {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ClassTable {
|
||||
pub parent_ids: FxHashMap<ClassId, ClassId>,
|
||||
pub declarations: IndexVec<ClassId, AstNodeId>,
|
||||
pub declarations: IndexVec<ClassId, NodeId>,
|
||||
pub elements: IndexVec<ClassId, IndexVec<ElementId, Element>>,
|
||||
// PrivateIdentifier reference
|
||||
pub private_identifiers: IndexVec<ClassId, Vec<PrivateIdentifierReference>>,
|
||||
@@ -62,7 +62,7 @@ impl ClassTable {
|
||||
self.declarations.raw.len()
|
||||
}
|
||||
|
||||
pub fn iter_enumerated(&self) -> impl Iterator<Item = (ClassId, &AstNodeId)> + '_ {
|
||||
pub fn iter_enumerated(&self) -> impl Iterator<Item = (ClassId, &NodeId)> + '_ {
|
||||
self.declarations.iter_enumerated()
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ impl ClassTable {
|
||||
self.private_identifiers[class_id].iter()
|
||||
}
|
||||
|
||||
pub fn get_node_id(&self, class_id: ClassId) -> AstNodeId {
|
||||
pub fn get_node_id(&self, class_id: ClassId) -> NodeId {
|
||||
self.declarations[class_id]
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ impl ClassTable {
|
||||
self.elements[class_id].iter().any(|p| p.is_private && p.name == name)
|
||||
}
|
||||
|
||||
pub fn declare_class(&mut self, parent_id: Option<ClassId>, ast_node_id: AstNodeId) -> ClassId {
|
||||
pub fn declare_class(&mut self, parent_id: Option<ClassId>, ast_node_id: NodeId) -> ClassId {
|
||||
let class_id = self.declarations.push(ast_node_id);
|
||||
if let Some(parent_id) = parent_id {
|
||||
self.parent_ids.insert(class_id, parent_id);
|
||||
|
||||
@@ -10,7 +10,7 @@ use oxc_cfg::{
|
||||
BasicBlock, ControlFlowGraph, EdgeType, Instruction, InstructionKind, IterationInstructionKind,
|
||||
LabeledInstruction, ReturnInstructionKind,
|
||||
};
|
||||
use oxc_syntax::node::AstNodeId;
|
||||
use oxc_syntax::node::NodeId;
|
||||
|
||||
use crate::{AstNode, AstNodes};
|
||||
|
||||
@@ -26,11 +26,11 @@ pub trait DebugDot {
|
||||
pub struct DebugDotContext<'a, 'b>(&'b AstNodes<'a>);
|
||||
|
||||
impl<'a, 'b> DebugDotContext<'a, 'b> {
|
||||
fn debug_ast_kind(self, id: AstNodeId) -> String {
|
||||
fn debug_ast_kind(self, id: NodeId) -> String {
|
||||
self.0.kind(id).debug_name().into_owned()
|
||||
}
|
||||
|
||||
fn try_eval_literal(self, id: AstNodeId) -> Option<String> {
|
||||
fn try_eval_literal(self, id: NodeId) -> Option<String> {
|
||||
match self.0.kind(id) {
|
||||
AstKind::NumericLiteral(lit) => Some(lit.value.to_string()),
|
||||
AstKind::BooleanLiteral(lit) => Some(lit.value.to_string()),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::AstNodeId;
|
||||
use crate::NodeId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LabeledScope<'a> {
|
||||
@@ -11,7 +11,7 @@ pub struct LabeledScope<'a> {
|
||||
pub struct UnusedLabels<'a> {
|
||||
pub scopes: Vec<LabeledScope<'a>>,
|
||||
pub curr_scope: usize,
|
||||
pub labels: Vec<AstNodeId>,
|
||||
pub labels: Vec<NodeId>,
|
||||
}
|
||||
|
||||
impl<'a> UnusedLabels<'a> {
|
||||
@@ -27,7 +27,7 @@ impl<'a> UnusedLabels<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_unused(&mut self, current_node_id: AstNodeId) {
|
||||
pub fn mark_unused(&mut self, current_node_id: NodeId) {
|
||||
let scope = &self.scopes[self.curr_scope];
|
||||
if !scope.used {
|
||||
self.labels.push(current_node_id);
|
||||
|
||||
@@ -37,7 +37,7 @@ mod unresolved_stack;
|
||||
pub use crate::{
|
||||
builder::{SemanticBuilder, SemanticBuilderReturn},
|
||||
jsdoc::{JSDoc, JSDocFinder, JSDocTag},
|
||||
node::{AstNode, AstNodeId, AstNodes},
|
||||
node::{AstNode, AstNodes, NodeId},
|
||||
reference::{Reference, ReferenceFlags, ReferenceId},
|
||||
scope::ScopeTree,
|
||||
symbol::{IsGlobalReference, SymbolTable},
|
||||
@@ -83,7 +83,7 @@ pub struct Semantic<'a> {
|
||||
/// Parsed JSDoc comments.
|
||||
jsdoc: JSDocFinder<'a>,
|
||||
|
||||
unused_labels: Vec<AstNodeId>,
|
||||
unused_labels: Vec<NodeId>,
|
||||
|
||||
/// Control flow graph. Only present if [`Semantic`] is built with cfg
|
||||
/// creation enabled using [`SemanticBuilder::with_cfg`].
|
||||
@@ -150,7 +150,7 @@ impl<'a> Semantic<'a> {
|
||||
&self.symbols
|
||||
}
|
||||
|
||||
pub fn unused_labels(&self) -> &Vec<AstNodeId> {
|
||||
pub fn unused_labels(&self) -> &Vec<NodeId> {
|
||||
&self.unused_labels
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ impl<'a> Semantic<'a> {
|
||||
self.cfg.as_ref()
|
||||
}
|
||||
|
||||
pub fn is_unresolved_reference(&self, node_id: AstNodeId) -> bool {
|
||||
pub fn is_unresolved_reference(&self, node_id: NodeId) -> bool {
|
||||
let reference_node = self.nodes.get_node(node_id);
|
||||
let AstKind::IdentifierReference(id) = reference_node.kind() else {
|
||||
return false;
|
||||
|
||||
@@ -2,14 +2,14 @@ use oxc_ast::AstKind;
|
||||
use oxc_cfg::BasicBlockId;
|
||||
use oxc_index::IndexVec;
|
||||
use oxc_span::GetSpan;
|
||||
pub use oxc_syntax::node::{AstNodeId, NodeFlags};
|
||||
pub use oxc_syntax::node::{NodeFlags, NodeId};
|
||||
|
||||
use crate::scope::ScopeId;
|
||||
|
||||
/// Semantic node contains all the semantic information about an ast node.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct AstNode<'a> {
|
||||
id: AstNodeId,
|
||||
id: NodeId,
|
||||
/// A pointer to the ast node, which resides in the `bumpalo` memory arena.
|
||||
kind: AstKind<'a>,
|
||||
|
||||
@@ -29,13 +29,13 @@ impl<'a> AstNode<'a> {
|
||||
scope_id: ScopeId,
|
||||
cfg_id: BasicBlockId,
|
||||
flags: NodeFlags,
|
||||
id: AstNodeId,
|
||||
id: NodeId,
|
||||
) -> Self {
|
||||
Self { id, kind, scope_id, cfg_id, flags }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> AstNodeId {
|
||||
pub fn id(&self) -> NodeId {
|
||||
self.id
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ pub struct AstNodes<'a> {
|
||||
/// The root node should always point to a `Program`, which is the real
|
||||
/// root of the tree. It isn't possible to statically check for this, so
|
||||
/// users should beware.
|
||||
root: Option<AstNodeId>,
|
||||
nodes: IndexVec<AstNodeId, AstNode<'a>>,
|
||||
parent_ids: IndexVec<AstNodeId, Option<AstNodeId>>,
|
||||
root: Option<NodeId>,
|
||||
nodes: IndexVec<NodeId, AstNode<'a>>,
|
||||
parent_ids: IndexVec<NodeId, Option<NodeId>>,
|
||||
}
|
||||
|
||||
impl<'a> AstNodes<'a> {
|
||||
@@ -103,45 +103,42 @@ impl<'a> AstNodes<'a> {
|
||||
/// The first node produced by this iterator is the first parent of the node
|
||||
/// pointed to by `node_id`. The last node will usually be a `Program`.
|
||||
#[inline]
|
||||
pub fn iter_parents(
|
||||
&self,
|
||||
node_id: AstNodeId,
|
||||
) -> impl Iterator<Item = &AstNode<'a>> + Clone + '_ {
|
||||
pub fn iter_parents(&self, node_id: NodeId) -> impl Iterator<Item = &AstNode<'a>> + Clone + '_ {
|
||||
AstNodeParentIter { current_node_id: Some(node_id), nodes: self }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(&self, ast_node_id: AstNodeId) -> AstKind<'a> {
|
||||
pub fn kind(&self, ast_node_id: NodeId) -> AstKind<'a> {
|
||||
self.nodes[ast_node_id].kind
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn parent_id(&self, ast_node_id: AstNodeId) -> Option<AstNodeId> {
|
||||
pub fn parent_id(&self, ast_node_id: NodeId) -> Option<NodeId> {
|
||||
self.parent_ids[ast_node_id]
|
||||
}
|
||||
|
||||
pub fn parent_kind(&self, ast_node_id: AstNodeId) -> Option<AstKind<'a>> {
|
||||
pub fn parent_kind(&self, ast_node_id: NodeId) -> Option<AstKind<'a>> {
|
||||
self.parent_id(ast_node_id).map(|node_id| self.kind(node_id))
|
||||
}
|
||||
|
||||
pub fn parent_node(&self, ast_node_id: AstNodeId) -> Option<&AstNode<'a>> {
|
||||
pub fn parent_node(&self, ast_node_id: NodeId) -> Option<&AstNode<'a>> {
|
||||
self.parent_id(ast_node_id).map(|node_id| self.get_node(node_id))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_node(&self, ast_node_id: AstNodeId) -> &AstNode<'a> {
|
||||
pub fn get_node(&self, ast_node_id: NodeId) -> &AstNode<'a> {
|
||||
&self.nodes[ast_node_id]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_node_mut(&mut self, ast_node_id: AstNodeId) -> &mut AstNode<'a> {
|
||||
pub fn get_node_mut(&mut self, ast_node_id: NodeId) -> &mut AstNode<'a> {
|
||||
&mut self.nodes[ast_node_id]
|
||||
}
|
||||
|
||||
/// Get the root `AstNodeId`, It is always pointing to a `Program`.
|
||||
/// Get the root `NodeId`, It is always pointing to a `Program`.
|
||||
/// Returns `None` if root node isn't set.
|
||||
#[inline]
|
||||
pub fn root(&self) -> Option<AstNodeId> {
|
||||
pub fn root(&self) -> Option<NodeId> {
|
||||
self.root
|
||||
}
|
||||
|
||||
@@ -163,36 +160,36 @@ impl<'a> AstNodes<'a> {
|
||||
///
|
||||
/// The first node produced by this iterator is the first parent of the node
|
||||
/// pointed to by `node_id`. The last node will usually be a `Program`.
|
||||
pub fn ancestors(&self, ast_node_id: AstNodeId) -> impl Iterator<Item = AstNodeId> + '_ {
|
||||
pub fn ancestors(&self, ast_node_id: NodeId) -> impl Iterator<Item = NodeId> + '_ {
|
||||
let parent_ids = &self.parent_ids;
|
||||
std::iter::successors(Some(ast_node_id), |node_id| parent_ids[*node_id])
|
||||
}
|
||||
|
||||
/// Create and add an `AstNode` to the `AstNodes` tree and returns its `AstNodeId`.
|
||||
/// Create and add an `AstNode` to the `AstNodes` tree and returns its `NodeId`.
|
||||
/// Node must not be `Program`. Use `add_program_node` instead.
|
||||
#[inline]
|
||||
pub fn add_node(
|
||||
&mut self,
|
||||
kind: AstKind<'a>,
|
||||
scope_id: ScopeId,
|
||||
parent_node_id: AstNodeId,
|
||||
parent_node_id: NodeId,
|
||||
cfg_id: BasicBlockId,
|
||||
flags: NodeFlags,
|
||||
) -> AstNodeId {
|
||||
) -> NodeId {
|
||||
let ast_node_id = self.parent_ids.push(Some(parent_node_id));
|
||||
let node = AstNode::new(kind, scope_id, cfg_id, flags, ast_node_id);
|
||||
self.nodes.push(node);
|
||||
ast_node_id
|
||||
}
|
||||
|
||||
/// Create and add an `AstNode` to the `AstNodes` tree and returns its `AstNodeId`.
|
||||
/// Create and add an `AstNode` to the `AstNodes` tree and returns its `NodeId`.
|
||||
pub fn add_program_node(
|
||||
&mut self,
|
||||
kind: AstKind<'a>,
|
||||
scope_id: ScopeId,
|
||||
cfg_id: BasicBlockId,
|
||||
flags: NodeFlags,
|
||||
) -> AstNodeId {
|
||||
) -> NodeId {
|
||||
let ast_node_id = self.parent_ids.push(None);
|
||||
self.root = Some(ast_node_id);
|
||||
let node = AstNode::new(kind, scope_id, cfg_id, flags, ast_node_id);
|
||||
@@ -208,7 +205,7 @@ impl<'a> AstNodes<'a> {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AstNodeParentIter<'s, 'a> {
|
||||
current_node_id: Option<AstNodeId>,
|
||||
current_node_id: Option<NodeId>,
|
||||
nodes: &'s AstNodes<'a>,
|
||||
}
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ impl<'s> PostTransformChecker<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
// NB: Skip checking node IDs match - transformer does not set `AstNodeId`s
|
||||
// NB: Skip checking node IDs match - transformer does not set `NodeId`s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ impl<'s> PostTransformChecker<'s> {
|
||||
self.errors.push_mismatch("Symbol scope ID mismatch", symbol_ids, scope_ids);
|
||||
}
|
||||
|
||||
// NB: Skip checking declarations match - transformer does not set `AstNodeId`s
|
||||
// NB: Skip checking declarations match - transformer does not set `NodeId`s
|
||||
|
||||
// Check resolved references match
|
||||
let reference_ids = self.get_pair(symbol_ids, |scoping, symbol_id| {
|
||||
|
||||
@@ -8,7 +8,7 @@ use tsify::Tsify;
|
||||
|
||||
pub use oxc_syntax::reference::{ReferenceFlags, ReferenceId};
|
||||
|
||||
use crate::{symbol::SymbolId, AstNodeId};
|
||||
use crate::{symbol::SymbolId, NodeId};
|
||||
|
||||
/// Describes where and how a Symbol is used in the AST.
|
||||
///
|
||||
@@ -37,7 +37,7 @@ use crate::{symbol::SymbolId, AstNodeId};
|
||||
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||
pub struct Reference {
|
||||
/// The AST node making the reference.
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
/// The symbol being referenced.
|
||||
///
|
||||
/// This will be [`None`] if no symbol could be found within
|
||||
@@ -52,17 +52,13 @@ pub struct Reference {
|
||||
impl Reference {
|
||||
/// Create a new unresolved reference.
|
||||
#[inline]
|
||||
pub fn new(node_id: AstNodeId, flags: ReferenceFlags) -> Self {
|
||||
pub fn new(node_id: NodeId, flags: ReferenceFlags) -> Self {
|
||||
Self { node_id, symbol_id: None, flags }
|
||||
}
|
||||
|
||||
/// Create a new resolved reference on a symbol.
|
||||
#[inline]
|
||||
pub fn new_with_symbol_id(
|
||||
node_id: AstNodeId,
|
||||
symbol_id: SymbolId,
|
||||
flags: ReferenceFlags,
|
||||
) -> Self {
|
||||
pub fn new_with_symbol_id(node_id: NodeId, symbol_id: SymbolId, flags: ReferenceFlags) -> Self {
|
||||
Self { node_id, symbol_id: Some(symbol_id), flags }
|
||||
}
|
||||
|
||||
@@ -74,7 +70,7 @@ impl Reference {
|
||||
/// [`IdentifierReference`]: oxc_ast::ast::IdentifierReference
|
||||
/// [`JSXIdentifier`]: oxc_ast::ast::JSXIdentifier
|
||||
#[inline]
|
||||
pub fn node_id(&self) -> AstNodeId {
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
self.node_id
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_span::CompactStr;
|
||||
use oxc_syntax::reference::ReferenceId;
|
||||
pub use oxc_syntax::scope::{ScopeFlags, ScopeId};
|
||||
|
||||
use crate::{symbol::SymbolId, AstNodeId};
|
||||
use crate::{symbol::SymbolId, NodeId};
|
||||
|
||||
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct ScopeTree {
|
||||
pub(crate) build_child_ids: bool,
|
||||
|
||||
/// Maps a scope to its node id.
|
||||
node_ids: IndexVec<ScopeId, AstNodeId>,
|
||||
node_ids: IndexVec<ScopeId, NodeId>,
|
||||
|
||||
flags: IndexVec<ScopeId, ScopeFlags>,
|
||||
|
||||
@@ -223,7 +223,7 @@ impl ScopeTree {
|
||||
///
|
||||
/// [`AstNode`]: crate::AstNode
|
||||
#[inline]
|
||||
pub fn get_node_id(&self, scope_id: ScopeId) -> AstNodeId {
|
||||
pub fn get_node_id(&self, scope_id: ScopeId) -> NodeId {
|
||||
self.node_ids[scope_id]
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ impl ScopeTree {
|
||||
pub fn add_scope(
|
||||
&mut self,
|
||||
parent_id: Option<ScopeId>,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
flags: ScopeFlags,
|
||||
) -> ScopeId {
|
||||
let scope_id = self.parent_ids.push(parent_id);
|
||||
|
||||
@@ -14,7 +14,7 @@ pub use oxc_syntax::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
node::AstNodeId,
|
||||
node::NodeId,
|
||||
reference::{Reference, ReferenceId},
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct SymbolTable {
|
||||
pub flags: IndexVec<SymbolId, SymbolFlags>,
|
||||
pub scope_ids: IndexVec<SymbolId, ScopeId>,
|
||||
/// Pointer to the AST Node where this symbol is declared
|
||||
pub declarations: IndexVec<SymbolId, AstNodeId>,
|
||||
pub declarations: IndexVec<SymbolId, NodeId>,
|
||||
pub resolved_references: IndexVec<SymbolId, Vec<ReferenceId>>,
|
||||
redeclarations: IndexVec<SymbolId, Option<RedeclarationId>>,
|
||||
|
||||
@@ -124,7 +124,7 @@ impl SymbolTable {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_declaration(&self, symbol_id: SymbolId) -> AstNodeId {
|
||||
pub fn get_declaration(&self, symbol_id: SymbolId) -> NodeId {
|
||||
self.declarations[symbol_id]
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ impl SymbolTable {
|
||||
name: CompactStr,
|
||||
flags: SymbolFlags,
|
||||
scope_id: ScopeId,
|
||||
node_id: AstNodeId,
|
||||
node_id: NodeId,
|
||||
) -> SymbolId {
|
||||
self.spans.push(span);
|
||||
self.names.push(name);
|
||||
|
||||
@@ -5,12 +5,12 @@ use oxc_index::Idx;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct AstNodeId(NonMaxU32);
|
||||
pub struct NodeId(NonMaxU32);
|
||||
|
||||
impl AstNodeId {
|
||||
pub const DUMMY: Self = AstNodeId::new(0);
|
||||
impl NodeId {
|
||||
pub const DUMMY: Self = NodeId::new(0);
|
||||
|
||||
/// Create `AstNodeId` from `u32`.
|
||||
/// Create `NodeId` from `u32`.
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if `idx` is `u32::MAX`.
|
||||
@@ -22,7 +22,7 @@ impl AstNodeId {
|
||||
unsafe { Self::new_unchecked(idx) }
|
||||
}
|
||||
|
||||
/// Create `AstNodeId` from `u32` unchecked.
|
||||
/// Create `NodeId` from `u32` unchecked.
|
||||
///
|
||||
/// # SAFETY
|
||||
/// `idx` must not be `u32::MAX`.
|
||||
@@ -33,7 +33,7 @@ impl AstNodeId {
|
||||
}
|
||||
}
|
||||
|
||||
impl Idx for AstNodeId {
|
||||
impl Idx for NodeId {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn from_usize(idx: usize) -> Self {
|
||||
assert!(idx < u32::MAX as usize);
|
||||
@@ -47,7 +47,7 @@ impl Idx for AstNodeId {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl Serialize for AstNodeId {
|
||||
impl Serialize for NodeId {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@@ -59,7 +59,7 @@ impl Serialize for AstNodeId {
|
||||
#[cfg(feature = "serialize")]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
|
||||
const TS_APPEND_CONTENT: &'static str = r#"
|
||||
export type AstNodeId = number;
|
||||
export type NodeId = number;
|
||||
export type NodeFlags = {
|
||||
JSDoc: 1,
|
||||
Class: 2,
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxc_allocator::Vec;
|
||||
use oxc_ast::{ast::*, visit::walk_mut, VisitMut, NONE};
|
||||
use oxc_span::{Atom, Span, SPAN};
|
||||
use oxc_syntax::{
|
||||
node::AstNodeId,
|
||||
node::NodeId,
|
||||
number::{NumberBase, ToJsInt32, ToJsString},
|
||||
operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator},
|
||||
reference::ReferenceFlags,
|
||||
@@ -85,7 +85,7 @@ impl<'a> TypeScriptEnum<'a> {
|
||||
enum_name.to_compact_str(),
|
||||
SymbolFlags::FunctionScopedVariable,
|
||||
func_scope_id,
|
||||
AstNodeId::DUMMY,
|
||||
NodeId::DUMMY,
|
||||
);
|
||||
ctx.scopes_mut().add_binding(func_scope_id, enum_name.to_compact_str(), param_symbol_id);
|
||||
let ident = BindingIdentifier {
|
||||
|
||||
@@ -6,7 +6,7 @@ use rustc_hash::FxHashSet;
|
||||
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::{ast::*, visit::Visit};
|
||||
use oxc_semantic::{AstNodeId, Reference, ScopeTree, SymbolTable};
|
||||
use oxc_semantic::{NodeId, Reference, ScopeTree, SymbolTable};
|
||||
use oxc_span::{Atom, CompactStr, Span, SPAN};
|
||||
use oxc_syntax::{
|
||||
reference::{ReferenceFlags, ReferenceId},
|
||||
@@ -82,7 +82,7 @@ impl TraverseScoping {
|
||||
/// `flags` provided are amended to inherit from parent scope's flags.
|
||||
pub fn create_child_scope(&mut self, parent_id: ScopeId, flags: ScopeFlags) -> ScopeId {
|
||||
let flags = self.scopes.get_new_scope_flags(flags, parent_id);
|
||||
self.scopes.add_scope(Some(parent_id), AstNodeId::DUMMY, flags)
|
||||
self.scopes.add_scope(Some(parent_id), NodeId::DUMMY, flags)
|
||||
}
|
||||
|
||||
/// Create new scope as child of current scope.
|
||||
@@ -222,7 +222,7 @@ impl TraverseScoping {
|
||||
|
||||
// Add binding to scope
|
||||
let symbol_id =
|
||||
self.symbols.create_symbol(SPAN, name.clone(), flags, scope_id, AstNodeId::DUMMY);
|
||||
self.symbols.create_symbol(SPAN, name.clone(), flags, scope_id, NodeId::DUMMY);
|
||||
self.scopes.add_binding(scope_id, name, symbol_id);
|
||||
symbol_id
|
||||
}
|
||||
@@ -281,7 +281,7 @@ impl TraverseScoping {
|
||||
symbol_id: SymbolId,
|
||||
flags: ReferenceFlags,
|
||||
) -> ReferenceId {
|
||||
let reference = Reference::new_with_symbol_id(AstNodeId::DUMMY, symbol_id, flags);
|
||||
let reference = Reference::new_with_symbol_id(NodeId::DUMMY, symbol_id, flags);
|
||||
let reference_id = self.symbols.create_reference(reference);
|
||||
self.symbols.resolved_references[symbol_id].push(reference_id);
|
||||
reference_id
|
||||
@@ -305,7 +305,7 @@ impl TraverseScoping {
|
||||
name: CompactStr,
|
||||
flags: ReferenceFlags,
|
||||
) -> ReferenceId {
|
||||
let reference = Reference::new(AstNodeId::DUMMY, flags);
|
||||
let reference = Reference::new(NodeId::DUMMY, flags);
|
||||
let reference_id = self.symbols.create_reference(reference);
|
||||
self.scopes.add_root_unresolved_reference(name, reference_id);
|
||||
reference_id
|
||||
|
||||
Reference in new issue
Block a user