Skip to main content

oxc_span/
lib.rs

1//! Source positions and related helper functions.
2//!
3//! <https://doc.rust-lang.org/beta/nightly-rustc/rustc_span>
4
5mod cmp;
6mod edit_distance;
7mod source_type;
8mod span;
9
10pub use cmp::ContentEq;
11pub use edit_distance::{best_match, min_edit_distance};
12pub use oxc_str::ident;
13pub use oxc_str::{
14    ArenaIdentHashMap, Atom, CompactStr, Ident, IdentHashMap, IdentHashSet,
15    MAX_INLINE_LEN as ATOM_MAX_INLINE_LEN, format_atom, format_compact_str, format_ident,
16};
17pub use source_type::{
18    FileExtension, Language, LanguageVariant, ModuleKind, SourceType, UnknownExtension,
19    VALID_EXTENSIONS,
20};
21pub use span::{GetSpan, GetSpanMut, SPAN, Span};
22
23mod generated {
24    #[cfg(debug_assertions)]
25    mod assert_layouts;
26    mod derive_dummy;
27    #[cfg(feature = "serialize")]
28    mod derive_estree;
29}
30
31#[doc(hidden)]
32pub mod __internal {
33    // Used by `format_compact_str!` macro defined in `oxc_str`
34    pub use compact_str::format_compact;
35    // Used by `format_atom!` and `format_ident!` macros defined in `oxc_str`
36    pub use oxc_allocator::StringBuilder as ArenaStringBuilder;
37}
38
39// Additional trait implementations for types re-exported from oxc_str
40use std::ops::Index;
41
42impl ContentEq for Atom<'_> {
43    #[inline]
44    fn content_eq(&self, other: &Self) -> bool {
45        self == other
46    }
47}
48
49impl ContentEq for Ident<'_> {
50    #[inline]
51    fn content_eq(&self, other: &Self) -> bool {
52        self == other
53    }
54}
55
56impl Index<Span> for CompactStr {
57    type Output = str;
58
59    fn index(&self, index: Span) -> &Self::Output {
60        &self.as_str()[index.start as usize..index.end as usize]
61    }
62}