refactor: remove all usages of Into<Error>

This commit is contained in:
Boshen 2024-05-12 12:00:26 +08:00
parent dbde5b3a04
commit d8173e1000
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
2 changed files with 8 additions and 8 deletions

View file

@ -4,7 +4,7 @@ use std::{cell::RefCell, path::PathBuf, rc::Rc, sync::Arc};
#[allow(clippy::wildcard_imports)] #[allow(clippy::wildcard_imports)]
use oxc_ast::{ast::*, AstKind, Trivias, Visit}; use oxc_ast::{ast::*, AstKind, Trivias, Visit};
use oxc_diagnostics::Error; use oxc_diagnostics::{Error, OxcDiagnostic};
use oxc_span::{CompactStr, SourceType, Span}; use oxc_span::{CompactStr, SourceType, Span};
use oxc_syntax::{ use oxc_syntax::{
identifier::is_identifier_name, identifier::is_identifier_name,
@ -186,7 +186,7 @@ impl<'a> SemanticBuilder<'a> {
} }
/// Push a Syntax Error /// Push a Syntax Error
pub fn error<T: Into<Error>>(&self, error: T) { pub fn error(&self, error: OxcDiagnostic) {
self.errors.borrow_mut().push(error.into()); self.errors.borrow_mut().push(error.into());
} }

View file

@ -7,7 +7,7 @@ use std::{
use oxc_allocator::Allocator; use oxc_allocator::Allocator;
use oxc_ast::{AstBuilder, Trivias}; use oxc_ast::{AstBuilder, Trivias};
use oxc_diagnostics::Error; use oxc_diagnostics::{Error, OxcDiagnostic};
use oxc_span::SourceType; use oxc_span::SourceType;
use crate::{helpers::module_imports::ModuleImports, TransformOptions}; use crate::{helpers::module_imports::ModuleImports, TransformOptions};
@ -15,7 +15,7 @@ use crate::{helpers::module_imports::ModuleImports, TransformOptions};
pub type Ctx<'a> = Rc<TransformCtx<'a>>; pub type Ctx<'a> = Rc<TransformCtx<'a>>;
pub struct TransformCtx<'a> { pub struct TransformCtx<'a> {
errors: RefCell<Vec<Error>>, errors: RefCell<Vec<OxcDiagnostic>>,
pub trivias: &'a Trivias, pub trivias: &'a Trivias,
@ -66,12 +66,12 @@ impl<'a> TransformCtx<'a> {
} }
pub fn take_errors(&self) -> Vec<Error> { pub fn take_errors(&self) -> Vec<Error> {
mem::take(&mut self.errors.borrow_mut()) let errors: Vec<OxcDiagnostic> = mem::take(&mut self.errors.borrow_mut());
errors.into_iter().map(Error::from).collect()
} }
/// Add an Error /// Add an Error
#[allow(unused)] pub fn error(&self, error: OxcDiagnostic) {
pub fn error<T: Into<Error>>(&self, error: T) { self.errors.borrow_mut().push(error);
self.errors.borrow_mut().push(error.into());
} }
} }