refactor(span): remove source_type module (#11024)

It's unnecessary to have a separate `errors.rs` file for `SourceType`. Combine 2 files into 1.

Pure refactor. This PR doesn't alter any of the logic, just relocates it.
This commit is contained in:
overlookmotel committed 2025-05-14 09:11:22 +00:00
1 parent 4a72b58e77
commit 567368efe3
4 files changed
+36 -36

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ src:
- 'crates/oxc_span/src/generated/assert_layouts.rs'
- 'crates/oxc_span/src/generated/derive_dummy.rs'
- 'crates/oxc_span/src/generated/derive_estree.rs'
- 'crates/oxc_span/src/source_type/mod.rs'
- 'crates/oxc_span/src/source_type.rs'
- 'crates/oxc_span/src/span.rs'
- 'crates/oxc_syntax/src/generated/assert_layouts.rs'
- 'crates/oxc_syntax/src/generated/derive_clone_in.rs'
@@ -1,4 +1,10 @@
use std::{hash::Hash, path::Path};
use std::{
borrow::Cow,
error::Error,
fmt::{self, Display},
ops::Deref,
path::Path,
};
use oxc_allocator::{Allocator, CloneIn, Dummy};
use oxc_ast_macros::ast;
@@ -6,9 +12,6 @@ use oxc_estree::ESTree;
use crate::ContentEq;
mod error;
pub use error::UnknownExtension;
/// Source Type for JavaScript vs TypeScript / Script vs Module / JSX
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -551,6 +554,33 @@ impl SourceType {
}
}
/// Error returned by [`SourceType::from_path`] and [`SourceType::from_extension`] when
/// the file extension is not found or recognized.
#[derive(Debug)]
pub struct UnknownExtension(Cow<'static, str>);
impl UnknownExtension {
fn new<S: Into<Cow<'static, str>>>(ext: S) -> Self {
Self(ext.into())
}
}
impl Deref for UnknownExtension {
type Target = str;
fn deref(&self) -> &str {
&self.0
}
}
impl Display for UnknownExtension {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Unknown file extension: {}", self.0)
}
}
impl Error for UnknownExtension {}
#[cfg(test)]
mod tests {
use super::SourceType;
-30
View File
@@ -1,30 +0,0 @@
use std::{borrow::Cow, error::Error, fmt, ops::Deref};
/// Error returned by [`SourceType::from_path`] when the file extension is not
/// found or recognized.
///
/// [`SourceType::from_path`]: `crate::SourceType::from_path`
#[derive(Debug)]
pub struct UnknownExtension(/* msg */ pub(crate) Cow<'static, str>);
impl Deref for UnknownExtension {
type Target = str;
fn deref(&self) -> &str {
&self.0
}
}
impl UnknownExtension {
#[inline]
pub(crate) fn new<S: Into<Cow<'static, str>>>(ext: S) -> Self {
Self(ext.into())
}
}
impl fmt::Display for UnknownExtension {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Unknown file extension: {}", self.0)
}
}
impl Error for UnknownExtension {}
+1 -1
View File
@@ -227,7 +227,7 @@ static SOURCE_PATHS: &[&str] = &[
"crates/oxc_syntax/src/symbol.rs",
"crates/oxc_syntax/src/reference.rs",
"crates/oxc_span/src/span.rs",
"crates/oxc_span/src/source_type/mod.rs",
"crates/oxc_span/src/source_type.rs",
"crates/oxc_regular_expression/src/ast.rs",
"napi/parser/src/raw_transfer_types.rs",
];