Skip to content

Commit 98d7946

Browse files
committed
refactor(semantic): import flags and ID types from oxc_syntax (#7887)
`oxc_semantic` had a bit of a mess of modules importing and re-exporting symbols from `oxc_syntax` all over the place. I assume this is a leftover from when our crates were structured differently. Make this consistent by always importing `oxc_syntax`'s symbols from `oxc_syntax`, and only re-export them from the crate root.
1 parent b9322c6 commit 98d7946

File tree

9 files changed

+35
-27
lines changed

9 files changed

+35
-27
lines changed

crates/oxc_semantic/src/binder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::ptr;
55
use oxc_ast::{ast::*, AstKind};
66
use oxc_ecmascript::{BoundNames, IsSimpleParameterList};
77
use oxc_span::{GetSpan, SourceType};
8-
9-
use crate::{
8+
use oxc_syntax::{
109
scope::{ScopeFlags, ScopeId},
1110
symbol::SymbolFlags,
12-
SemanticBuilder,
1311
};
1412

13+
use crate::SemanticBuilder;
14+
1515
pub(crate) trait Binder<'a> {
1616
#[allow(unused_variables)]
1717
fn bind(&self, builder: &mut SemanticBuilder<'a>) {}

crates/oxc_semantic/src/builder.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use oxc_cfg::{
99
};
1010
use oxc_diagnostics::OxcDiagnostic;
1111
use oxc_span::{Atom, CompactStr, SourceType, Span};
12+
use oxc_syntax::{
13+
node::{NodeFlags, NodeId},
14+
reference::{ReferenceFlags, ReferenceId},
15+
scope::{ScopeFlags, ScopeId},
16+
symbol::{SymbolFlags, SymbolId},
17+
};
1218
use rustc_hash::FxHashMap;
1319

1420
use crate::{
@@ -18,11 +24,11 @@ use crate::{
1824
diagnostics::redeclaration,
1925
jsdoc::JSDocBuilder,
2026
label::UnusedLabels,
21-
node::{AstNodes, NodeFlags, NodeId},
22-
reference::{Reference, ReferenceFlags, ReferenceId},
23-
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
27+
node::AstNodes,
28+
reference::Reference,
29+
scope::{Bindings, ScopeTree},
2430
stats::Stats,
25-
symbol::{SymbolFlags, SymbolId, SymbolTable},
31+
symbol::SymbolTable,
2632
unresolved_stack::UnresolvedReferencesStack,
2733
JSDocFinder, Semantic,
2834
};

crates/oxc_semantic/src/checker/javascript.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use oxc_span::{GetSpan, ModuleKind, Span};
55
use oxc_syntax::{
66
number::NumberBase,
77
operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator},
8+
scope::ScopeFlags,
89
};
910
use phf::{phf_set, Set};
1011
use rustc_hash::FxHashMap;
1112

12-
use crate::{builder::SemanticBuilder, diagnostics::redeclaration, scope::ScopeFlags, AstNode};
13+
use crate::{builder::SemanticBuilder, diagnostics::redeclaration, AstNode};
1314

1415
pub fn check_duplicate_class_elements(ctx: &SemanticBuilder<'_>) {
1516
let classes = &ctx.class_table_builder.classes;

crates/oxc_semantic/src/class/table.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use oxc_index::IndexVec;
22
use oxc_span::{CompactStr, Span};
3-
use oxc_syntax::class::{ClassId, ElementId, ElementKind};
3+
use oxc_syntax::{
4+
class::{ClassId, ElementId, ElementKind},
5+
node::NodeId,
6+
};
47
use rustc_hash::FxHashMap;
58

6-
use crate::node::NodeId;
7-
89
#[derive(Debug)]
910
pub struct Element {
1011
pub name: CompactStr,

crates/oxc_semantic/src/label.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::NodeId;
1+
use oxc_syntax::node::NodeId;
22

33
#[derive(Debug)]
44
pub struct LabeledScope<'a> {

crates/oxc_semantic/src/node.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use oxc_ast::AstKind;
22
use oxc_cfg::BlockNodeId;
33
use oxc_index::IndexVec;
44
use oxc_span::GetSpan;
5-
pub use oxc_syntax::node::{NodeFlags, NodeId};
6-
7-
use crate::scope::ScopeId;
5+
use oxc_syntax::{
6+
node::{NodeFlags, NodeId},
7+
scope::ScopeId,
8+
};
89

910
/// Semantic node contains all the semantic information about an ast node.
1011
#[derive(Debug, Clone, Copy)]

crates/oxc_semantic/src/reference.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
pub use oxc_syntax::reference::{ReferenceFlags, ReferenceId};
1+
use oxc_syntax::{node::NodeId, reference::ReferenceFlags, symbol::SymbolId};
22
#[cfg(feature = "serialize")]
33
use serde::Serialize;
44
#[cfg(feature = "serialize")]
55
use tsify::Tsify;
66

7-
use crate::{symbol::SymbolId, NodeId};
8-
97
/// Describes where and how a Symbol is used in the AST.
108
///
119
/// References indicate how they are being used using [`ReferenceFlags`]. Refer

crates/oxc_semantic/src/scope.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use std::mem;
33
use indexmap::IndexMap;
44
use oxc_index::IndexVec;
55
use oxc_span::CompactStr;
6-
use oxc_syntax::reference::ReferenceId;
7-
pub use oxc_syntax::scope::{ScopeFlags, ScopeId};
6+
use oxc_syntax::{
7+
node::NodeId,
8+
reference::ReferenceId,
9+
scope::{ScopeFlags, ScopeId},
10+
symbol::SymbolId,
11+
};
812
use rustc_hash::{FxBuildHasher, FxHashMap};
913

10-
use crate::{symbol::SymbolId, NodeId};
11-
1214
type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
1315

1416
pub(crate) type Bindings = FxIndexMap<CompactStr, SymbolId>;

crates/oxc_semantic/src/symbol.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::mem;
33
use oxc_ast::ast::{Expression, IdentifierReference};
44
use oxc_index::IndexVec;
55
use oxc_span::{CompactStr, Span};
6-
pub use oxc_syntax::{
6+
use oxc_syntax::{
7+
node::NodeId,
8+
reference::ReferenceId,
79
scope::ScopeId,
810
symbol::{RedeclarationId, SymbolFlags, SymbolId},
911
};
@@ -12,10 +14,7 @@ use serde::Serialize;
1214
#[cfg(feature = "serialize")]
1315
use tsify::Tsify;
1416

15-
use crate::{
16-
node::NodeId,
17-
reference::{Reference, ReferenceId},
18-
};
17+
use crate::reference::Reference;
1918

2019
#[cfg(feature = "serialize")]
2120
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]

0 commit comments

Comments
 (0)