-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(napi/transform): remove context
- Loading branch information
Showing
5 changed files
with
72 additions
and
186 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::sync::Arc; | ||
|
||
use oxc::{ | ||
diagnostics::{Error, NamedSource, OxcDiagnostic}, | ||
span::SourceType, | ||
}; | ||
|
||
pub fn wrap_diagnostics( | ||
filename: &str, | ||
source_type: SourceType, | ||
source_text: &str, | ||
errors: Vec<OxcDiagnostic>, | ||
) -> Vec<String> { | ||
if errors.is_empty() { | ||
return vec![]; | ||
} | ||
let source = { | ||
let lang = match (source_type.is_javascript(), source_type.is_jsx()) { | ||
(true, false) => "JavaScript", | ||
(true, true) => "JSX", | ||
(false, true) => "TypeScript React", | ||
(false, false) => { | ||
if source_type.is_typescript_definition() { | ||
"TypeScript Declaration" | ||
} else { | ||
"TypeScript" | ||
} | ||
} | ||
}; | ||
|
||
let ns = NamedSource::new(filename, source_text.to_string()).with_language(lang); | ||
Arc::new(ns) | ||
}; | ||
|
||
errors | ||
.into_iter() | ||
.map(move |diagnostic| Error::from(diagnostic).with_source_code(Arc::clone(&source))) | ||
.map(|error| format!("{error:?}")) | ||
.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod context; | ||
mod errors; | ||
|
||
pub use oxc::napi::{isolated_declarations, transform}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters