mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(napi): rename Error to OxcError to avoid name collision (#7780)
This commit is contained in:
parent
4f1ab49440
commit
18d0ce3c06
8 changed files with 35 additions and 35 deletions
|
|
@ -109,9 +109,9 @@ oxc_tasks_common = { path = "tasks/common" }
|
|||
oxc_tasks_transform_checker = { path = "tasks/transform_checker" }
|
||||
|
||||
# Relaxed version so the user can decide which version to use.
|
||||
napi = "3.0.0-alpha.11"
|
||||
napi = "3.0.0-alpha"
|
||||
napi-build = "2.1.3"
|
||||
napi-derive = "3.0.0-alpha.11"
|
||||
napi-derive = "3.0.0-alpha"
|
||||
|
||||
# Relaxed version so the user can decide which version to use.
|
||||
proc-macro2 = "1"
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@ use napi_derive::napi;
|
|||
use oxc_diagnostics::{LabeledSpan, OxcDiagnostic};
|
||||
|
||||
#[napi(object)]
|
||||
pub struct Error {
|
||||
pub struct OxcError {
|
||||
pub severity: Severity,
|
||||
pub message: String,
|
||||
pub labels: Vec<ErrorLabel>,
|
||||
pub help_message: Option<String>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
impl OxcError {
|
||||
pub fn new(message: String) -> Self {
|
||||
Self { severity: Severity::Error, message, labels: vec![], help_message: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OxcDiagnostic> for Error {
|
||||
impl From<OxcDiagnostic> for OxcError {
|
||||
fn from(diagnostic: OxcDiagnostic) -> Self {
|
||||
let labels = diagnostic
|
||||
.labels
|
||||
|
|
|
|||
16
napi/parser/index.d.ts
vendored
16
napi/parser/index.d.ts
vendored
|
|
@ -26,7 +26,7 @@ export declare class ParseResult {
|
|||
get program(): import("@oxc-project/types").Program
|
||||
get module(): EcmaScriptModule
|
||||
get comments(): Array<Comment>
|
||||
get errors(): Array<Error>
|
||||
get errors(): Array<OxcError>
|
||||
get magicString(): MagicString
|
||||
}
|
||||
|
||||
|
|
@ -54,13 +54,6 @@ export interface EcmaScriptModule {
|
|||
importMetas: Array<Span>
|
||||
}
|
||||
|
||||
export interface Error {
|
||||
severity: Severity
|
||||
message: string
|
||||
labels: Array<ErrorLabel>
|
||||
helpMessage?: string
|
||||
}
|
||||
|
||||
export interface ErrorLabel {
|
||||
message?: string
|
||||
start: number
|
||||
|
|
@ -145,6 +138,13 @@ export interface OverwriteOptions {
|
|||
contentOnly: boolean
|
||||
}
|
||||
|
||||
export interface OxcError {
|
||||
severity: Severity
|
||||
message: string
|
||||
labels: Array<ErrorLabel>
|
||||
helpMessage?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse asynchronously.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use oxc::{
|
|||
parser::{ParseOptions, Parser, ParserReturn},
|
||||
span::SourceType,
|
||||
};
|
||||
use oxc_napi::Error;
|
||||
use oxc_napi::OxcError;
|
||||
|
||||
pub use crate::{
|
||||
magic_string::MagicString,
|
||||
|
|
@ -74,7 +74,7 @@ fn parse_with_return(filename: &str, source_text: String, options: &ParserOption
|
|||
let ret = parse(&allocator, source_type, &source_text, options);
|
||||
let program = serde_json::to_string(&ret.program).unwrap();
|
||||
|
||||
let errors = ret.errors.into_iter().map(Error::from).collect::<Vec<_>>();
|
||||
let errors = ret.errors.into_iter().map(OxcError::from).collect::<Vec<_>>();
|
||||
|
||||
let comments = ret
|
||||
.program
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use napi_derive::napi;
|
||||
use std::mem;
|
||||
|
||||
use oxc_napi::Error;
|
||||
use oxc_napi::OxcError;
|
||||
|
||||
use crate::magic_string::MagicString;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ pub struct ParseResult {
|
|||
pub(crate) program: String,
|
||||
pub(crate) module: EcmaScriptModule,
|
||||
pub(crate) comments: Vec<Comment>,
|
||||
pub(crate) errors: Vec<Error>,
|
||||
pub(crate) errors: Vec<OxcError>,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
|
|
@ -52,7 +52,7 @@ impl ParseResult {
|
|||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn errors(&mut self) -> Vec<Error> {
|
||||
pub fn errors(&mut self) -> Vec<OxcError> {
|
||||
mem::take(&mut self.errors)
|
||||
}
|
||||
|
||||
|
|
|
|||
18
napi/transform/index.d.ts
vendored
18
napi/transform/index.d.ts
vendored
|
|
@ -20,13 +20,6 @@ export interface CompilerAssumptions {
|
|||
setPublicClassFields?: boolean
|
||||
}
|
||||
|
||||
export interface Error {
|
||||
severity: Severity
|
||||
message: string
|
||||
labels: Array<ErrorLabel>
|
||||
helpMessage?: string
|
||||
}
|
||||
|
||||
export interface ErrorLabel {
|
||||
message?: string
|
||||
start: number
|
||||
|
|
@ -85,7 +78,7 @@ export interface IsolatedDeclarationsOptions {
|
|||
export interface IsolatedDeclarationsResult {
|
||||
code: string
|
||||
map?: SourceMap
|
||||
errors: Array<Error>
|
||||
errors: Array<OxcError>
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,6 +176,13 @@ export interface JsxOptions {
|
|||
refresh?: boolean | ReactRefreshOptions
|
||||
}
|
||||
|
||||
export interface OxcError {
|
||||
severity: Severity
|
||||
message: string
|
||||
labels: Array<ErrorLabel>
|
||||
helpMessage?: string
|
||||
}
|
||||
|
||||
export interface ReactRefreshOptions {
|
||||
/**
|
||||
* Specify the identifier of the refresh registration variable.
|
||||
|
|
@ -332,7 +332,7 @@ export interface TransformResult {
|
|||
* transformed code may still be available even if there are errors in this
|
||||
* list.
|
||||
*/
|
||||
errors: Array<Error>
|
||||
errors: Array<OxcError>
|
||||
}
|
||||
|
||||
export interface TypeScriptOptions {
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ use oxc::{
|
|||
parser::Parser,
|
||||
span::SourceType,
|
||||
};
|
||||
use oxc_napi::Error;
|
||||
use oxc_napi::OxcError;
|
||||
use oxc_sourcemap::napi::SourceMap;
|
||||
|
||||
#[napi(object)]
|
||||
pub struct IsolatedDeclarationsResult {
|
||||
pub code: String,
|
||||
pub map: Option<SourceMap>,
|
||||
pub errors: Vec<Error>,
|
||||
pub errors: Vec<OxcError>,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
|
|
@ -70,7 +70,7 @@ pub fn isolated_declaration(
|
|||
.with_options(CodegenOptions { source_map_path, ..CodegenOptions::default() })
|
||||
.build(&transformed_ret.program);
|
||||
|
||||
let errors = ret.errors.into_iter().chain(transformed_ret.errors).map(Error::from).collect();
|
||||
let errors = ret.errors.into_iter().chain(transformed_ret.errors).map(OxcError::from).collect();
|
||||
|
||||
IsolatedDeclarationsResult {
|
||||
code: codegen_ret.code,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use oxc::{
|
|||
},
|
||||
CompilerInterface,
|
||||
};
|
||||
use oxc_napi::Error;
|
||||
use oxc_napi::OxcError;
|
||||
use oxc_sourcemap::napi::SourceMap;
|
||||
|
||||
use crate::IsolatedDeclarationsOptions;
|
||||
|
|
@ -70,7 +70,7 @@ pub struct TransformResult {
|
|||
/// Oxc's parser recovers from common syntax errors, meaning that
|
||||
/// transformed code may still be available even if there are errors in this
|
||||
/// list.
|
||||
pub errors: Vec<Error>,
|
||||
pub errors: Vec<OxcError>,
|
||||
}
|
||||
|
||||
/// Options for transforming a JavaScript or TypeScript file.
|
||||
|
|
@ -627,7 +627,7 @@ pub fn transform(
|
|||
Some("tsx") => SourceType::tsx(),
|
||||
Some(lang) => {
|
||||
return TransformResult {
|
||||
errors: vec![Error::new(format!("Incorrect lang '{lang}'"))],
|
||||
errors: vec![OxcError::new(format!("Incorrect lang '{lang}'"))],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -647,7 +647,7 @@ pub fn transform(
|
|||
Ok(compiler) => compiler,
|
||||
Err(errors) => {
|
||||
return TransformResult {
|
||||
errors: errors.into_iter().map(Error::from).collect(),
|
||||
errors: errors.into_iter().map(OxcError::from).collect(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -661,6 +661,6 @@ pub fn transform(
|
|||
declaration: compiler.declaration,
|
||||
declaration_map: compiler.declaration_map,
|
||||
helpers_used: compiler.helpers_used,
|
||||
errors: compiler.errors.into_iter().map(Error::from).collect(),
|
||||
errors: compiler.errors.into_iter().map(OxcError::from).collect(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue