Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
style: cargo fmt + clippy fix
  • Loading branch information
DonIsaac committed Jun 23, 2024
commit 3161e12c8cf1cb7fb31499dc52e62e77c682c07e
15 changes: 8 additions & 7 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,19 @@ impl<'a> SemanticBuilder<'a> {
let symbol_flags = self.symbols.get_flag(symbol_id);
for reference_id in &reference_ids {
let reference = &mut self.symbols.references[*reference_id];
let meaning = if reference.is_type() {
SymbolFlags::Type
} else {
SymbolFlags::Value
};
let meaning =
if reference.is_type() { SymbolFlags::Type } else { SymbolFlags::Value };
if symbol_flags.intersects(meaning) {
reference.set_symbol_id(symbol_id);
self.symbols.resolved_references[symbol_id].push(*reference_id)
self.symbols.resolved_references[symbol_id].push(*reference_id);
} else {
// FIXME: this may cause a lot of cloning. @Boshen can you
// think of a workaround?
self.scope.add_unresolved_reference(parent_scope_id, name.clone(), *reference_id)
self.scope.add_unresolved_reference(
parent_scope_id,
name.clone(),
*reference_id,
);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a> SymbolTester<'a> {
parent,
semantic: Rc::new(semantic),
target_symbol_name: symbol_name,
test_result: Ok(symbol_id)
test_result: Ok(symbol_id),
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_span/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ impl Span {
}

/// Checks if this [`Span`] contains an offset.
///
///
/// The end index is considered included.
///
///
/// # Example
/// ```
/// use oxc_span::Span;
///
///
/// let span = Span::new(1, 5);
/// assert!(span.contains_inclusive(1));
/// assert!(span.contains_inclusive(5));
///
///
/// assert!(!span.contains_inclusive(0));
/// assert!(!span.contains_inclusive(6));
/// ```
Expand Down
15 changes: 10 additions & 5 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,29 +251,34 @@ impl TraverseScoping {

/// Attempt to resolve a symbol bound to a `name` by walking up the scope
/// tree, starting at the current scope id.
///
///
/// See [`TraverseScoping::resolve_binding_from_scope`] for more details.
pub fn resolve_binding(&self, name: &str, meaning: Option<SymbolFlags>) -> Option<SymbolId> {
self.resolve_binding_from_scope(self.current_scope_id, name, meaning)
}

/// Attempt to resolve a symbol bound to a `name` by walking up the scope
/// tree, starting at the desired `scope_id`.
///
///
/// Meaning refers to the kind of symbol desired. It will almost always be
/// [`SymbolFlags::Value`] or [`SymbolFlags::Type`]. This prevents us from
/// binding variable declarations to type references, e.g. in
/// ```ts
/// const x = 1;
/// function foo(a: x) {}
/// ```
///
///
/// If you do not care about what kind of symbol is found, you can pass
/// [`None`]; this is equivalent to [`SymbolFlags::all()`].
///
///
/// This method returns [`None`] when no symbol is found with the desired
/// `name`, or if a symbol is found but it does not have the correct meaning.
pub fn resolve_binding_from_scope(&self, scope_id: ScopeId, name: &str, meaning: Option<SymbolFlags>) -> Option<SymbolId> {
pub fn resolve_binding_from_scope(
&self,
scope_id: ScopeId,
name: &str,
meaning: Option<SymbolFlags>,
) -> Option<SymbolId> {
let meaning = meaning.unwrap_or(SymbolFlags::all());
for scope_id in self.scopes.ancestors(scope_id) {
if let Some(symbol_id) = self.scopes.get_binding(scope_id, name) {
Expand Down