2018-01-27 09:14:53 +03:00
|
|
|
use fold::FoldWith;
|
2018-03-03 13:00:57 +03:00
|
|
|
pub use swc_macros::Spanned;
|
2018-06-02 12:01:00 +03:00
|
|
|
pub use syntax_pos::{
|
2018-09-16 14:25:41 +03:00
|
|
|
hygiene, BytePos, ExpnFormat, ExpnInfo, FileName, MultiSpan, SourceFile, Span, SpanData,
|
|
|
|
SyntaxContext, DUMMY_SP, NO_EXPANSION,
|
2018-06-02 12:01:00 +03:00
|
|
|
};
|
2018-01-21 11:47:37 +03:00
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
///
|
|
|
|
/// # Derive
|
|
|
|
/// This trait can be derived with `#[derive(Spanned)]`.
|
|
|
|
pub trait Spanned {
|
|
|
|
/// Get span of `self`.
|
|
|
|
fn span(&self) -> Span;
|
2018-01-27 09:14:53 +03:00
|
|
|
}
|
|
|
|
|
2018-03-04 08:41:59 +03:00
|
|
|
impl Spanned for Span {
|
|
|
|
#[inline(always)]
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Spanned for BytePos {
|
|
|
|
/// Creates a new single-byte span.
|
|
|
|
#[inline(always)]
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
Span::new(*self, *self, Default::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
impl<S> Spanned for Box<S>
|
2018-01-27 09:14:53 +03:00
|
|
|
where
|
2018-03-03 13:00:57 +03:00
|
|
|
S: ?Sized + Spanned,
|
2018-01-27 09:14:53 +03:00
|
|
|
{
|
2018-03-03 13:00:57 +03:00
|
|
|
fn span(&self) -> Span {
|
|
|
|
<S as Spanned>::span(&*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 08:12:17 +03:00
|
|
|
impl<'a, S> Spanned for &'a S
|
2018-03-03 13:00:57 +03:00
|
|
|
where
|
|
|
|
S: ?Sized + Spanned,
|
|
|
|
{
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
<S as Spanned>::span(&*self)
|
2018-01-27 09:14:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<F> FoldWith<F> for Span {
|
|
|
|
/// No op as span does not have any child.
|
|
|
|
fn fold_children(self, _: &mut F) -> Span {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|