diff --git a/Cargo.lock b/Cargo.lock index c38610a..f010324 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -803,6 +803,7 @@ dependencies = [ "fervid_core", "fervid_css", "fxhash", + "itertools 0.10.5", "lazy_static", "phf", "smallvec", diff --git a/crates/fervid/src/errors.rs b/crates/fervid/src/errors.rs index 6b97eff..0275e36 100644 --- a/crates/fervid/src/errors.rs +++ b/crates/fervid/src/errors.rs @@ -43,7 +43,7 @@ impl Spanned for CompileError { fn span(&self) -> swc_core::common::Span { match self { CompileError::SfcParse(e) => e.span, - CompileError::TransformError(e) => e.span + CompileError::TransformError(e) => e.span() } } } diff --git a/crates/fervid_transform/Cargo.toml b/crates/fervid_transform/Cargo.toml index 7454a6d..2e3bde8 100644 --- a/crates/fervid_transform/Cargo.toml +++ b/crates/fervid_transform/Cargo.toml @@ -17,6 +17,7 @@ lazy_static = { workspace = true } phf = { workspace = true } swc_core = { workspace = true, features = ["common", "ecma_ast", "ecma_visit"] } smallvec = { workspace = true } +itertools = "*" [dev-dependencies] swc_ecma_codegen = { workspace = true } diff --git a/crates/fervid_transform/src/error.rs b/crates/fervid_transform/src/error.rs index 0169cb4..724e39a 100644 --- a/crates/fervid_transform/src/error.rs +++ b/crates/fervid_transform/src/error.rs @@ -2,39 +2,71 @@ use fervid_css::CssError; use swc_core::common::{Span, Spanned}; #[derive(Debug)] -pub struct TransformError { - pub span: Span, - pub kind: TransformErrorKind +pub enum TransformError { + CssError(CssError), + ScriptError(ScriptError) } #[derive(Debug)] -pub enum TransformErrorKind { - CssError(CssError), - ScriptError(ScriptError) +pub struct ScriptError { + pub span: Span, + pub kind: ScriptErrorKind } #[derive(Debug)] -pub enum ScriptError { +pub enum ScriptErrorKind { /// A compiler macro was imported, but it didn't need to CompilerMacroImport, + /// `defineEmits` called with 0 type arguments (e.g. `defineEmits<>()`) + DefineEmitsMalformed, + /// `defineEmits` was called with both runtime and type arguments + DefineEmitsTypeAndNonTypeArguments, + /// "defineEmits() type cannot mixed call signature and property syntax" + DefineEmitsMixedCallAndPropertySyntax, + /// Duplicate `defineEmits` call + DuplicateDefineEmits, /// Different imports using the same local symbol, /// e.g `import foo from './foo'` and `import { foo } from './bar'`. DuplicateImport, + /// Could not resolve array element type + ResolveTypeElementType, + /// A type param was not provided, + /// e.g. `ExtractPropTypes<>` + ResolveTypeMissingTypeParam, + /// Type parameters were not provided, + /// e.g. `ExtractPropTypes` + ResolveTypeMissingTypeParams, + /// A type both not supported and not planned to be supported during type resolution + ResolveTypeUnresolvable, + /// "Failed to resolve index type into finite keys" + ResolveTypeUnresolvableIndexType, + /// An unsupported construction during type resolution + ResolveTypeUnsupported, + /// "Unsupported type when resolving index type" + ResolveTypeUnsupportedIndexType, + /// Unsupported computed key in type referenced by a macro + ResolveTypeUnsupportedComputedKey, /// Disallow non-type exports inside `