Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl<'a> Codegen<'a> {
fn get_binding_identifier_name(&self, ident: &BindingIdentifier<'a>) -> &'a str {
if let Some(symbol_table) = &self.symbol_table {
if let Some(symbol_id) = ident.symbol_id.get() {
let name = symbol_table.get_name(symbol_id);
let name = symbol_table.symbol_name(symbol_id);
// SAFETY: Hack the lifetime to be part of the allocator.
return unsafe { std::mem::transmute_copy(&name) };
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn get_declaration_of_variable<'a, 'b>(
) -> Option<&'b AstNode<'a>> {
let symbol_id = get_symbol_id_of_variable(ident, semantic)?;
let symbol_table = semantic.symbols();
Some(semantic.nodes().get_node(symbol_table.get_declaration(symbol_id)))
Some(semantic.nodes().get_node(symbol_table.get_symbol_declaration(symbol_id)))
}

pub fn get_declaration_from_reference_id<'a, 'b>(
Expand All @@ -293,7 +293,7 @@ pub fn get_declaration_from_reference_id<'a, 'b>(
) -> Option<&'b AstNode<'a>> {
let symbol_table = semantic.symbols();
let symbol_id = symbol_table.get_reference(reference_id).symbol_id()?;
Some(semantic.nodes().get_node(symbol_table.get_declaration(symbol_id)))
Some(semantic.nodes().get_node(symbol_table.get_symbol_declaration(symbol_id)))
}

pub fn get_symbol_id_of_variable(
Expand Down Expand Up @@ -569,7 +569,7 @@ pub fn could_be_error(ctx: &LintContext, expr: &Expression) -> bool {
let Some(symbol_id) = reference.symbol_id() else {
return true;
};
let decl = ctx.nodes().get_node(ctx.symbols().get_declaration(symbol_id));
let decl = ctx.nodes().get_node(ctx.symbols().get_symbol_declaration(symbol_id));
match decl.kind() {
AstKind::VariableDeclarator(decl) => {
if let Some(init) = &decl.init {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn is_global_this_ref_or_global_window<'a>(
expr: &Expression<'a>,
) -> bool {
if let Expression::ThisExpression(_) = expr {
if ctx.scopes().get_flags(scope_id).is_top() {
if ctx.scopes().scope_flags(scope_id).is_top() {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_class_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ declare_oxc_lint!(
impl Rule for NoClassAssign {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let symbol_table = ctx.semantic().symbols();
if symbol_table.get_flags(symbol_id).is_class() {
if symbol_table.symbol_flags(symbol_id).is_class() {
for reference in symbol_table.get_resolved_references(symbol_id) {
if reference.is_write() {
ctx.diagnostic(no_class_assign_diagnostic(
symbol_table.get_name(symbol_id),
symbol_table.get_span(symbol_id),
symbol_table.symbol_name(symbol_id),
symbol_table.symbol_span(symbol_id),
ctx.semantic().reference_span(reference),
));
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_const_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ declare_oxc_lint!(
impl Rule for NoConstAssign {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let symbol_table = ctx.semantic().symbols();
if symbol_table.get_flags(symbol_id).is_const_variable() {
if symbol_table.symbol_flags(symbol_id).is_const_variable() {
for reference in symbol_table.get_resolved_references(symbol_id) {
if reference.is_write() {
ctx.diagnostic(no_const_assign_diagnostic(
symbol_table.get_name(symbol_id),
symbol_table.get_span(symbol_id),
symbol_table.symbol_name(symbol_id),
symbol_table.symbol_span(symbol_id),
ctx.semantic().reference_span(reference),
));
}
Expand Down
11 changes: 6 additions & 5 deletions crates/oxc_linter/src/rules/eslint/no_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ impl Rule for NoEval {
let Some((span, name)) = mem_expr.static_property_info() else { return };

if name == "eval" {
let scope_id = ctx.scopes().ancestors(parent.scope_id()).find(|scope_id| {
let scope_flags = ctx.scopes().get_flags(*scope_id);
scope_flags.is_var() && !scope_flags.is_arrow()
});
let scope_id =
ctx.scopes().scope_ancestors(parent.scope_id()).find(|scope_id| {
let scope_flags = ctx.scopes().scope_flags(*scope_id);
scope_flags.is_var() && !scope_flags.is_arrow()
});

let scope_id = scope_id.unwrap();
let scope_flags = ctx.scopes().get_flags(scope_id);
let scope_flags = ctx.scopes().scope_flags(scope_id);

// The `TsModuleBlock` shouldn't be considered
if scope_flags.is_ts_module_block() {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_ex_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare_oxc_lint!(
impl Rule for NoExAssign {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let symbol_table = ctx.semantic().symbols();
if symbol_table.get_flags(symbol_id).is_catch_variable() {
if symbol_table.symbol_flags(symbol_id).is_catch_variable() {
for reference in symbol_table.get_resolved_references(symbol_id) {
if reference.is_write() {
ctx.diagnostic(no_ex_assign_diagnostic(
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_func_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ declare_oxc_lint!(
impl Rule for NoFuncAssign {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let symbol_table = ctx.semantic().symbols();
let decl = symbol_table.get_declaration(symbol_id);
let decl = symbol_table.get_symbol_declaration(symbol_id);
if let AstKind::Function(_) = ctx.nodes().kind(decl) {
for reference in symbol_table.get_resolved_references(symbol_id) {
if reference.is_write() {
ctx.diagnostic(no_func_assign_diagnostic(
symbol_table.get_name(symbol_id),
symbol_table.symbol_name(symbol_id),
ctx.semantic().reference_span(reference),
));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_import_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const REFLECT_MUTATION_METHODS: phf::Set<&'static str> =
impl Rule for NoImportAssign {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let symbol_table = ctx.semantic().symbols();
if symbol_table.get_flags(symbol_id).is_import() {
let kind = ctx.nodes().kind(symbol_table.get_declaration(symbol_id));
if symbol_table.symbol_flags(symbol_id).is_import() {
let kind = ctx.nodes().kind(symbol_table.get_symbol_declaration(symbol_id));
let is_namespace_specifier = matches!(kind, AstKind::ImportNamespaceSpecifier(_));
for reference in symbol_table.get_resolved_references(symbol_id) {
if is_namespace_specifier {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_label_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Rule for NoLabelVar {
if let Some(symbol_id) =
ctx.scopes().find_binding(node.scope_id(), &labeled_stmt.label.name)
{
let decl_span = ctx.symbols().get_span(symbol_id);
let decl_span = ctx.symbols().symbol_span(symbol_id);
let label_decl = labeled_stmt.span.start;
ctx.diagnostic(no_label_var_diagnostic(
&labeled_stmt.label.name,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_obj_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn resolve_global_binding<'a, 'b: 'a>(
return None;
};

let decl = nodes.get_node(symbols.get_declaration(binding_id));
let decl = nodes.get_node(symbols.get_symbol_declaration(binding_id));
match decl.kind() {
AstKind::VariableDeclarator(parent_decl) => {
if !parent_decl.id.kind.is_binding_identifier() {
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_linter/src/rules/eslint/no_redeclare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ impl Rule for NoRedeclare {

fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext) {
let symbol_table = ctx.semantic().symbols();
let decl_node_id = symbol_table.get_declaration(symbol_id);
let decl_node_id = symbol_table.get_symbol_declaration(symbol_id);
match ctx.nodes().kind(decl_node_id) {
AstKind::VariableDeclarator(var) => {
if let BindingPatternKind::BindingIdentifier(ident) = &var.id.kind {
let symbol_name = symbol_table.get_name(symbol_id);
let symbol_name = symbol_table.symbol_name(symbol_id);
if symbol_name == ident.name.as_str() {
for span in ctx.symbols().get_redeclarations(symbol_id) {
for span in ctx.symbols().get_symbol_redeclarations(symbol_id) {
self.report_diagnostic(ctx, *span, ident);
}
}
}
}
AstKind::FormalParameter(param) => {
if let BindingPatternKind::BindingIdentifier(ident) = &param.pattern.kind {
let symbol_name = symbol_table.get_name(symbol_id);
let symbol_name = symbol_table.symbol_name(symbol_id);
if symbol_name == ident.name.as_str() {
for span in ctx.symbols().get_redeclarations(symbol_id) {
for span in ctx.symbols().get_symbol_redeclarations(symbol_id) {
self.report_diagnostic(ctx, *span, ident);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_setter_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl Rule for NoSetterReturn {
return;
}

for scope_id in ctx.scopes().ancestors(node.scope_id()) {
let flags = ctx.scopes().get_flags(scope_id);
for scope_id in ctx.scopes().scope_ancestors(node.scope_id()) {
let flags = ctx.scopes().scope_flags(scope_id);
if flags.is_set_accessor() {
ctx.diagnostic(no_setter_return_diagnostic(stmt.span));
} else if flags.is_function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ declare_oxc_lint!(

impl Rule for NoShadowRestrictedNames {
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
let name = ctx.symbols().get_name(symbol_id);
let name = ctx.symbols().symbol_name(symbol_id);

if !PRE_DEFINE_VAR.contains_key(name) {
return;
}

if name == "undefined" {
// Allow to declare `undefined` variable but not allow to assign value to it.
let node_id = ctx.semantic().symbols().get_declaration(symbol_id);
let node_id = ctx.semantic().symbols().get_symbol_declaration(symbol_id);
if let AstKind::VariableDeclarator(declarator) = ctx.nodes().kind(node_id) {
if declarator.init.is_none()
&& ctx
Expand All @@ -98,10 +98,10 @@ impl Rule for NoShadowRestrictedNames {
}
}

let span = ctx.symbols().get_span(symbol_id);
let span = ctx.symbols().symbol_span(symbol_id);
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));

for &span in ctx.symbols().get_redeclarations(symbol_id) {
for &span in ctx.symbols().get_symbol_redeclarations(symbol_id) {
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Symbol<'_, '_> {
pub fn is_in_declared_module(&self) -> bool {
let scopes = self.scopes();
let nodes = self.nodes();
scopes.ancestors(self.scope_id())
scopes.scope_ancestors(self.scope_id())
.map(|scope_id| scopes.get_node_id(scope_id))
.map(|node_id| nodes.get_node(node_id))
.any(|node| matches!(node.kind(), AstKind::TSModuleDeclaration(namespace) if is_ambient_namespace(namespace)))
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ impl Symbol<'_, '_> {

fn is_in_declare_global(&self) -> bool {
self.scopes()
.ancestors(self.scope_id())
.scope_ancestors(self.scope_id())
.filter(|&scope_id| {
let flags = self.scopes().get_flags(scope_id);
let flags = self.scopes().scope_flags(scope_id);
flags.contains(ScopeFlags::TsModuleBlock)
})
.any(|ambient_module_scope_id| {
Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
module_record: &'s ModuleRecord,
symbol_id: SymbolId,
) -> Self {
let flags = semantic.symbols().get_flags(symbol_id);
let flags = semantic.symbols().symbol_flags(symbol_id);
Self { semantic, module_record, id: symbol_id, flags, span: OnceCell::new() }
}

Expand All @@ -48,7 +48,7 @@ impl<'s, 'a> Symbol<'s, 'a> {

#[inline]
pub fn name(&self) -> &str {
self.symbols().get_name(self.id)
self.symbols().symbol_name(self.id)
}

#[inline]
Expand All @@ -58,7 +58,7 @@ impl<'s, 'a> Symbol<'s, 'a> {

#[inline]
pub fn scope_id(&self) -> ScopeId {
self.symbols().get_scope_id(self.id)
self.symbols().get_symbol_scope_id(self.id)
}

#[inline]
Expand All @@ -80,12 +80,12 @@ impl<'s, 'a> Symbol<'s, 'a> {

/// Is this [`Symbol`] declared in the root scope?
pub fn is_root(&self) -> bool {
self.symbols().get_scope_id(self.id) == self.scopes().root_scope_id()
self.symbols().get_symbol_scope_id(self.id) == self.scopes().root_scope_id()
}

#[inline]
fn declaration_id(&self) -> NodeId {
self.symbols().get_declaration(self.id)
self.symbols().get_symbol_declaration(self.id)
}

#[inline]
Expand Down Expand Up @@ -159,13 +159,13 @@ impl<'s, 'a> Symbol<'s, 'a> {
_ => break,
}
}
self.symbols().get_span(self.id)
self.symbols().symbol_span(self.id)
}

/// <https://github.com/oxc-project/oxc/issues/4739>
fn clean_binding_id(&self, binding: &BindingPattern) -> Span {
if binding.kind.is_destructuring_pattern() {
return self.symbols().get_span(self.id);
return self.symbols().symbol_span(self.id);
}
let own = binding.kind.span();
binding.type_annotation.as_ref().map_or(own, |ann| Span::new(own.start, ann.span.start))
Expand All @@ -185,7 +185,7 @@ impl<'a> Symbol<'_, 'a> {

#[inline]
fn is_in_ts_namespace(&self) -> bool {
self.scopes().get_flags(self.scope_id()).is_ts_module_block()
self.scopes().scope_flags(self.scope_id()).is_ts_module_block()
}

/// We need to do this due to limitations of [`Semantic`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl<'a> Symbol<'_, 'a> {
return false;
}

for scope_id in self.scopes().ancestors(call_scope_id) {
for scope_id in self.scopes().scope_ancestors(call_scope_id) {
if scope_id == container_id {
return true;
} else if scope_id == decl_scope_id {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn handle_jest_set_time_out<'a>(
};

if expr.property.name == "setTimeout" {
if !scopes.get_flags(parent_node.scope_id()).is_top() {
if !scopes.scope_flags(parent_node.scope_id()).is_top() {
ctx.diagnostic(no_global_set_timeout_diagnostic(member_expr.span()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Rule for PreferLowercaseTitle {
}

if matches!(jest_fn_call.kind, JestFnKind::General(JestGeneralFnKind::Describe)) {
if self.ignore_top_level_describe && scopes.get_flags(node.scope_id()).is_top() {
if self.ignore_top_level_describe && scopes.scope_flags(node.scope_id()).is_top() {
return;
}
} else if !matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl RequireTopLevelDescribe {
) {
let node = possible_jest_node.node;
let scopes = ctx.scopes();
let is_top = scopes.get_flags(node.scope_id()).is_top();
let is_top = scopes.scope_flags(node.scope_id()).is_top();

let AstKind::CallExpression(call_expr) = node.kind() else {
return;
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ declare_oxc_lint!(
impl Rule for NoDuplicateHead {
fn run_on_symbol(&self, symbol_id: oxc_semantic::SymbolId, ctx: &LintContext<'_>) {
let symbols = ctx.symbols();
let name = symbols.get_name(symbol_id);
let name = symbols.symbol_name(symbol_id);
if name != "Head" {
return;
}

let flags = symbols.get_flags(symbol_id);
let flags = symbols.symbol_flags(symbol_id);
if !flags.is_import() {
return;
}

let scope_id = symbols.get_scope_id(symbol_id);
let scope_id = symbols.get_symbol_scope_id(symbol_id);
if scope_id != ctx.scopes().root_scope_id() {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Rule for NoAccumulatingSpread {
let Some(referenced_symbol_id) = reference.symbol_id() else {
return;
};
let declaration_id = symbols.get_declaration(referenced_symbol_id);
let declaration_id = symbols.get_symbol_declaration(referenced_symbol_id);
let Some(declaration) = ctx.semantic().nodes().parent_node(declaration_id) else {
return;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ impl NoAsyncEndpointHandlers {
};

// Cannot check imported handlers without cross-file analysis.
let flags = ctx.symbols().get_flags(symbol_id);
let flags = ctx.symbols().symbol_flags(symbol_id);
if flags.is_import() {
return;
}

let decl_id = ctx.symbols().get_declaration(symbol_id);
let decl_id = ctx.symbols().get_symbol_declaration(symbol_id);
let decl_node = ctx.nodes().get_node(decl_id);
let registered_at = registered_at.or(Some(handler.span));
match decl_node.kind() {
Expand Down
Loading
Loading