{"record":{"id":"a53022d4c4c9746a","repo":"sinelaw/fresh","slug":"isolated-declarations-parse-errors-in","errorCode":null,"errorMessage":"isolated-declarations parse errors in {}: {}","messagePattern":"isolated-declarations parse errors in (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-parser-js/src/lib.rs","lineNumber":110,"sourceCode":"/// are tolerated and the caller simply gets a partial emit.\npub fn emit_isolated_declarations(source: &str, filename: &str) -> Result<String> {\n    let allocator = Allocator::default();\n    let source_type = SourceType::from_path(filename)\n        .unwrap_or_default()\n        .with_module(true);\n\n    let module_marked;\n    let effective_source: &str = if has_es_module_syntax(source) {\n        source\n    } else {\n        module_marked = format!(\"{source}\\nexport {{}};\\n\");\n        &module_marked\n    };\n\n    let parser_ret = Parser::new(&allocator, effective_source, source_type).parse();\n    if !parser_ret.errors.is_empty() {\n        let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect();\n        return Err(anyhow!(\n            \"isolated-declarations parse errors in {}: {}\",\n            filename,\n            errors.join(\"; \")\n        ));\n    }\n\n    let emit = IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions::default())\n        .build(&parser_ret.program);\n\n    // Codegen the declaration AST back to source. We deliberately do\n    // NOT fail on `emit.errors` — isolated-declarations emits one per\n    // exported value that lacks an explicit type, and we want the\n    // partial emit anyway (the consumer can still use the surfaces\n    // the plugin annotated correctly).\n    let codegen_ret = Codegen::new().build(&emit.program);\n    Ok(codegen_ret.code)\n}\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-parser-js/src/lib.rs#L92-L128","documentation":"`emit_isolated_declarations` re-parses the (possibly module-wrapped) source with isolated-declarations mode enabled to generate a .d.ts; if parsing fails it reports the filename plus all parse errors. This enforces that declarations can be emitted only from syntactically valid, declaration-compatible source.","triggerScenarios":"Calling `emit_isolated_declarations(source, filename)` where the effective source (raw or module-marked) contains syntax errors, or a filename whose extension yields an incompatible SourceType.","commonSituations":"Generating .d.ts for a plugin/API file with a syntax error; passing a snippet that only parses inside a larger file; wrong file extension changing parse mode.","solutions":["Fix the syntax errors listed for the named file before re-running.","Ensure the full file contents (not a fragment) are passed, since module wrapping re-parses the whole source.","Verify the filename extension matches the language (e.g. .ts)."],"exampleFix":"// before\nlet src = \"export function f(: number) {}\";\nemit_isolated_declarations(src, \"api.ts\")?; // parse error\n// after\nlet src = \"export function f(x: number) {}\";\nemit_isolated_declarations(src, \"api.ts\")?;","handlingStrategy":"validation","validationCode":"// Ensure source is complete and extension is .ts before emitting declarations\nif !filename.ends_with(\".ts\") { bail!(\"pass a .ts filename\"); }\n// Optionally run transpile_typescript first as a parse pre-check\ntranspile_typescript(source, filename)?;","typeGuard":null,"tryCatchPattern":"match emit_isolated_declarations(src, \"api.ts\") {\n    Err(e) if e.to_string().contains(\"isolated-declarations parse errors\") => report_diagnostics(&e.to_string()),\n    other => other?,\n}","preventionTips":["Feed whole files, not snippets, to the declaration emitter.","Run a plain parse (transpile_typescript) as a pre-check.","Validate declaration-compatibility with tsc --isolatedDeclarations in CI."],"tags":["typescript","declarations","parser","syntax-error"],"backgroundTag":"schema-validation-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}