Skip to content

Commit

Permalink
use ref
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Sep 5, 2024
1 parent 24bf97d commit 975fef6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/format_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use super::swc::parse_swc_ast;
/// // save result here...
/// }
/// ```
pub fn format_text(file_path: &Path, file_extension: Option<String>, file_text: String, config: &Configuration) -> Result<Option<String>> {
pub fn format_text(file_path: &Path, file_extension: Option<&str>, file_text: String, config: &Configuration) -> Result<Option<String>> {
if super::utils::file_text_has_ignore_comment(&file_text, &config.ignore_file_comment_text) {
Ok(None)
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/swc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use deno_ast::ParsedSource;
use std::path::Path;
use std::sync::Arc;

pub fn parse_swc_ast(file_path: &Path, file_extension: Option<String>, file_text: Arc<str>) -> Result<ParsedSource> {
match parse_inner(file_path, file_extension.as_deref(), file_text.clone()) {
pub fn parse_swc_ast(file_path: &Path, file_extension: Option<&str>, file_text: Arc<str>) -> Result<ParsedSource> {
match parse_inner(file_path, file_extension, file_text.clone()) {
Ok(result) => Ok(result),
Err(err) => {
let lowercase_ext = file_extension.or_else(|| get_lowercase_extension(file_path));
let lowercase_ext = file_extension.map(|ext| ext.to_string()).or_else(|| get_lowercase_extension(file_path));
let new_file_path = match lowercase_ext.as_deref() {
Some("ts") | Some("cts") | Some("mts") => file_path.with_extension("tsx"),
Some("js") | Some("cjs") | Some("mjs") => file_path.with_extension("jsx"),
Expand Down Expand Up @@ -294,7 +294,7 @@ mod tests {
#[test]
fn file_extension_overwrite() {
let file_path = PathBuf::from("./test.js");
assert!(parse_swc_ast(&file_path, Some("ts".to_string()), "const foo: string = 'bar';".into()).is_ok());
assert!(parse_swc_ast(&file_path, Some("ts"), "const foo: string = 'bar';".into()).is_ok());
}

#[test]
Expand Down

0 comments on commit 975fef6

Please sign in to comment.