{"record":{"id":"0f6e058554e6ce8c","repo":"swc-project/swc","slug":"failed-to-parse-input-type","errorCode":null,"errorMessage":"failed to parse input type","messagePattern":"failed to parse input type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_quote_macros/src/lib.rs","lineNumber":33,"sourceCode":"mod ast;\nmod builder;\nmod ctxt;\nmod input;\nmod ret_type;\n\n/// Don't invoke this macro directly, use the `quote!` macro from\n/// `swc_ecma_quote` instead.\n#[proc_macro]\npub fn internal_quote(input: proc_macro::TokenStream) -> proc_macro::TokenStream {\n    let QuoteInput {\n        src,\n        as_token: _,\n        output_type,\n        vars,\n    } = syn::parse::<QuoteInput>(input).expect(\"failed to parse input to quote!()\");\n\n    let ret_type =\n        parse_input_type(&src.value(), &output_type).expect(\"failed to parse input type\");\n\n    let vars = vars.map(|v| v.1);\n\n    let (stmts, vars) = if let Some(vars) = vars {\n        prepare_vars(&ret_type, vars)\n    } else {\n        Default::default()\n    };\n\n    let cx = Ctx { vars };\n\n    let expr_for_ast_creation = ret_type.to_code(&cx);\n\n    syn::Expr::Block(ExprBlock {\n        attrs: Default::default(),\n        label: Default::default(),\n        block: Block {\n            brace_token: Default::default(),","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_quote_macros/src/lib.rs#L15-L51","documentation":"This panic comes from the `internal_quote` proc macro that powers the `quote!` macro in `swc_ecma_quote`. After parsing the macro input (output type, `as` keyword, source string, vars), it calls `parse_input_type` to parse the string literal as the requested AST type. The `expect(\"failed to parse input type\")` fires when that parse returns an Err: the quoted source is not valid syntax for the requested type, or the output type is one `parse_input_type` does not support (it bails with \"Unknown quote type\").","triggerScenarios":"Writing `quote!(T as \"src\")` where \"src\" fails to parse as T with swc_ecma_parser (e.g. `quote!(Expr as \"a +\")`, a dangling expression), writing multiple statements where only one expression is allowed, requesting an unsupported output type (only Expr, Pat, Stmt, AssignTarget, ModuleItem, plus Box<T>/Option<T> wrappers are handled), or a Box<T>/Option<T> whose inner T is unknown.","commonSituations":"Authors of swc transforms writing compile-time AST templates with `quote!`; a typo or unfinished snippet inside the quoted string panics at compile time of the consuming crate. Upgrading swc_ecma_parser versions can also make previously-accepted snippets fail to parse.","solutions":["Check the string literal inside `quote!(T as \"...\")`: run it through a JS parser (or `node --check`) and fix the syntax error the message context reports.","Confirm the output type is one of the supported ones (Expr, Pat, Stmt, AssignTarget, ModuleItem, or Box/Option wrapping them); for anything else, build the AST manually.","If the snippet is meant to be interpolated with vars, verify the `$(var)*` placeholders do not break the syntax of the surrounding snippet.","Isolate the failing `quote!` invocation by reading the compile error location, since the panic aborts the whole proc-macro expansion."],"exampleFix":"// before\nlet expr = quote!(Expr as \"a +\"); // dangling '+', fails to parse\n\n// after\nlet expr = quote!(Expr as \"a + b\");","handlingStrategy":"validation","validationCode":"// Validate the snippet parses as T before shipping the quote! invocation\nfn snippet_parses(src: &str) -> bool {\n    use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax};\n    let fm: swc_common::SourceFile =\n        swc_common::SourceFile::new(src.into()); // simplified\n    let lexer = Lexer::new(\n        Syntax::Es(Default::default()),\n        Default::default(),\n        StringInput::from(&fm),\n        None,\n    );\n    let mut parser = Parser::new_from(lexer);\n    parser.parse_expr().is_ok()\n}\n\n#[test]\nfn quoted_snippets_are_valid() {\n    assert!(snippet_parses(\"a + b\"));\n    assert!(!snippet_parses(\"a +\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep quoted snippets tiny (single expression/statement/pattern) so parse errors are obvious.","Add a unit test next to each quote! use so the proc-macro panic surfaces in CI at authoring time.","Restrict output types to the supported set: Expr, Pat, Stmt, AssignTarget, ModuleItem, Box<T>, Option<T>."],"tags":["proc-macro","quote-macro","compile-time","syntax-error","swc"],"backgroundTag":"proc-macro-parse-failure","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}