diff --git a/crates/swc_css_parser/src/error.rs b/crates/swc_css_parser/src/error.rs index 9cbbfc77a0b..a585d4d9b8d 100644 --- a/crates/swc_css_parser/src/error.rs +++ b/crates/swc_css_parser/src/error.rs @@ -30,7 +30,7 @@ impl Error { } } - pub fn message(&self) -> Cow { + pub fn message(&self) -> Cow<'static, str> { match &self.inner.1 { ErrorKind::Eof => "Unexpected end of file".into(), ErrorKind::Ignore => "Not an error".into(), diff --git a/crates/swc_html_parser/src/error.rs b/crates/swc_html_parser/src/error.rs index f6893a614d6..96c09f7ebed 100644 --- a/crates/swc_html_parser/src/error.rs +++ b/crates/swc_html_parser/src/error.rs @@ -26,8 +26,8 @@ impl Error { } } - pub fn to_diagnostics<'a>(&self, handler: &'a Handler) -> DiagnosticBuilder<'a> { - let msg: Cow<_> = match &self.inner.1 { + pub fn message(&self) -> Cow<'static, str> { + match &self.inner.1 { ErrorKind::Eof => "Unexpected end of file".into(), ErrorKind::ControlCharacterInInputStream => "Control character in input stream".into(), ErrorKind::NoncharacterInInputStream => "Noncharacter in input stream".into(), @@ -138,8 +138,11 @@ impl Error { "Eof in element that can contain only text".into() } ErrorKind::UnexpectedToken => "Unexpected token".into(), - }; - handler.struct_span_err(self.inner.0, &msg) + } + } + + pub fn to_diagnostics<'a>(&self, handler: &'a Handler) -> DiagnosticBuilder<'a> { + handler.struct_span_err(self.inner.0, &self.message()) } }