Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed May 10, 2024
1 parent 1f580c0 commit a607fb4
Show file tree
Hide file tree
Showing 27 changed files with 454 additions and 511 deletions.
57 changes: 4 additions & 53 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ mod graphical_theme;
mod reporter;
mod service;

use std::{
fmt::{self, Display},
path::PathBuf,
};
use std::path::PathBuf;

pub use miette;
pub use thiserror;
Expand All @@ -23,10 +20,12 @@ pub use crate::{
pub type Error = miette::Error;
pub type Severity = miette::Severity;
pub type Report = miette::Report;
pub type OxcDiagnostic = miette::MietteDiagnostic;

pub type Result<T> = std::result::Result<T, Error>;

use miette::{Diagnostic, LabeledSpan, SourceCode};
use miette::Diagnostic;
pub use miette::LabeledSpan;
use thiserror::Error;

#[derive(Debug, Error, Diagnostic)]
Expand All @@ -38,51 +37,3 @@ pub struct MinifiedFileError(pub PathBuf);
#[error("Failed to open file {0:?} with error \"{1}\"")]
#[diagnostic(help("Failed to open file {0:?} with error \"{1}\""))]
pub struct FailedToOpenFileError(pub PathBuf, pub std::io::Error);

#[derive(Debug, Default, Error)]
pub struct OxcDiagnostic {
pub message: &'static str,
pub help: Option<&'static str>,
pub severity: Option<Severity>,
pub labels: Vec<LabeledSpan>,
}

impl Display for OxcDiagnostic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}

impl Diagnostic for OxcDiagnostic {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
None
}

fn severity(&self) -> Option<Severity> {
Some(self.severity.unwrap_or(Severity::Warning))
}

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.help.map(|s| -> Box<dyn Display + 'a> { Box::new(s.to_string()) })
}

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
None
}

fn source_code(&self) -> Option<&dyn SourceCode> {
None
}

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
Some(Box::new(self.labels.iter().map(Clone::clone)))
}

fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
None
}

fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
None
}
}
4 changes: 2 additions & 2 deletions crates/oxc_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ and this project does not adhere to [Semantic Versioning](https://semver.org/spe
- Correct the span for irregular whitespaces (#2245)
- Correct MAX_LEN for 32-bit systems (#2204)
- AcessorProperty is missing decorators (#2176)
- Fix crash on TSTemplateLiteralType in function return position (#2089)
- Fix crash on TStemplate_literal()Type in function return position (#2089)
- Restore regex flag parsing (#2007)

### Performance
Expand Down Expand Up @@ -224,7 +224,7 @@ and this project does not adhere to [Semantic Versioning](https://semver.org/spe

- Unexpected ts type annotation in get/set (#1942)
- Fix incorrectly identified directives (#1885)
- Terminate parsing if an EmptyParenthesizedExpression error occurs (#1874)
- Terminate parsing if an empty_parenthesized_expression() error occurs (#1874)
- Error on source larger than 4 GiB (#1860)
- Await in jsx expression
- False postive for "Missing initializer in const declaration" in declare + namespace (#1724)
Expand Down
14 changes: 4 additions & 10 deletions crates/oxc_parser/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code related to navigating `Token`s from the lexer

use oxc_ast::ast::RegExpFlags;
use oxc_diagnostics::{OxcDiagnostic, Result};
use oxc_diagnostics::Result;
use oxc_span::Span;

use crate::{
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'a> ParserImpl<'a> {
fn test_escaped_keyword(&mut self, kind: Kind) {
if self.cur_token().escaped() && kind.is_all_keyword() {
let span = self.cur_token().span();
self.error(diagnostics::EscapedKeyword(span));
self.error(diagnostics::escaped_keyword(span));
}
}

Expand Down Expand Up @@ -158,13 +158,7 @@ impl<'a> ParserImpl<'a> {
pub(crate) fn asi(&mut self) -> Result<()> {
if !self.can_insert_semicolon() {
let span = Span::new(self.prev_token_end, self.cur_token().start);
let diagnostic = OxcDiagnostic {
message: "Expected a semicolon or an implicit semicolon after a statement, but found none",
help: None,
severity: None,
labels: vec![span.into()]
};
return Err(diagnostic.into());
return Err(diagnostics::auto_semicolon_insertion(span).into());
}
if self.at(Kind::Semicolon) {
self.advance(Kind::Semicolon);
Expand All @@ -185,7 +179,7 @@ impl<'a> ParserImpl<'a> {
if !self.at(kind) {
let range = self.cur_token().span();
return Err(
diagnostics::ExpectToken(kind.to_str(), self.cur_kind().to_str(), range).into()
diagnostics::expect_token(kind.to_str(), self.cur_kind().to_str(), range).into()
);
}
Ok(())
Expand Down

0 comments on commit a607fb4

Please sign in to comment.