1use swc_core::common::{Span, Spanned};
2
3#[derive(Debug)]
4pub struct ParseError {
5 pub kind: ParseErrorKind,
6 pub span: Span,
7}
8
9#[derive(Debug)]
10pub enum ParseErrorKind {
11 DirectiveSyntax,
13 DuplicateScriptOptions,
15 DuplicateScriptSetup,
17 DuplicateTemplate,
19 DuplicateAttribute,
21 DynamicArgument,
23 EcmaSyntaxError(Box<swc_ecma_parser::error::SyntaxError>),
25 InvalidHtml(Box<swc_html_parser::error::ErrorKind>),
27 MissingTemplateOrScript,
29 UnexpectedNonRawTextContent,
31 UnsupportedLang,
33}
34
35impl From<swc_ecma_parser::error::Error> for ParseError {
36 fn from(value: swc_ecma_parser::error::Error) -> ParseError {
37 let span = value.span();
38
39 ParseError {
40 kind: ParseErrorKind::EcmaSyntaxError(Box::new(value.into_kind())),
41 span,
42 }
43 }
44}
45
46impl std::fmt::Display for ParseErrorKind {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 write!(f, "{:?}", self)
49 }
50}
51
52impl std::fmt::Display for ParseError {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 write!(f, "{:?}", self)
55 }
56}
57
58impl Spanned for ParseError {
59 fn span(&self) -> Span {
60 self.span
61 }
62}