Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/generated/ast_changes_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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;
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)]
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 0 additions & 30 deletions crates/oxc_span/src/source_type/error.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tasks/ast_tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];
Expand Down
Loading