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;
7#[cfg(feature = "serialize")]
8mod serialize;
9mod source_type;
10mod span;
11
12pub use cmp::ContentEq;
13pub use edit_distance::{best_match, min_edit_distance};
14use oxc_str::{CompactStr, Ident, Str};
15pub use source_type::{
16    FileExtension, Language, LanguageVariant, ModuleKind, SourceType, UnknownExtension,
17    VALID_EXTENSIONS,
18};
19pub use span::{GetSpan, GetSpanMut, SPAN, Span};
20
21// Only here to make it available in `generated/assert_layouts` module
22#[cfg(debug_assertions)]
23use span::I32Dummy;
24
25mod generated {
26    #[cfg(debug_assertions)]
27    mod assert_layouts;
28    mod derive_dummy;
29    #[cfg(feature = "serialize")]
30    mod derive_estree;
31}
32
33#[doc(hidden)]
34pub mod __internal {
35    // Used by `format_compact_str!` macro defined in `oxc_str`
36    pub use compact_str::format_compact;
37    // Used by `format_str!` and `format_ident!` macros defined in `oxc_str`
38    pub use oxc_allocator::StringBuilder as ArenaStringBuilder;
39}
40
41// Additional trait implementations for types re-exported from oxc_str
42use std::ops::Index;
43
44impl ContentEq for Str<'_> {
45    #[inline]
46    fn content_eq(&self, other: &Self) -> bool {
47        self == other
48    }
49}
50
51impl ContentEq for Ident<'_> {
52    #[inline]
53    fn content_eq(&self, other: &Self) -> bool {
54        self == other
55    }
56}
57
58impl Index<Span> for CompactStr {
59    type Output = str;
60
61    fn index(&self, index: Span) -> &Self::Output {
62        &self.as_str()[index.start as usize..index.end as usize]
63    }
64}