sinelaw/fresh · error

isolated-declarations parse errors in

Error message

isolated-declarations parse errors in {}: {}

What it means

`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.

Solutions

  1. Fix the syntax errors listed for the named file before re-running.
  2. Ensure the full file contents (not a fragment) are passed, since module wrapping re-parses the whole source.
  3. Verify the filename extension matches the language (e.g. .ts).

Example fix

// before
let src = "export function f(: number) {}";
emit_isolated_declarations(src, "api.ts")?; // parse error
// after
let src = "export function f(x: number) {}";
emit_isolated_declarations(src, "api.ts")?;
Defensive patterns

Strategy: validation

Validate before calling

// Ensure source is complete and extension is .ts before emitting declarations
if !filename.ends_with(".ts") { bail!("pass a .ts filename"); }
// Optionally run transpile_typescript first as a parse pre-check
transpile_typescript(source, filename)?;

Try / catch

match emit_isolated_declarations(src, "api.ts") {
    Err(e) if e.to_string().contains("isolated-declarations parse errors") => report_diagnostics(&e.to_string()),
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/a53022d4c4c9746a. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-parser-js/src/lib.rs:110

/// are tolerated and the caller simply gets a partial emit.
pub fn emit_isolated_declarations(source: &str, filename: &str) -> Result<String> {
    let allocator = Allocator::default();
    let source_type = SourceType::from_path(filename)
        .unwrap_or_default()
        .with_module(true);

    let module_marked;
    let effective_source: &str = if has_es_module_syntax(source) {
        source
    } else {
        module_marked = format!("{source}\nexport {{}};\n");
        &module_marked
    };

    let parser_ret = Parser::new(&allocator, effective_source, source_type).parse();
    if !parser_ret.errors.is_empty() {
        let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect();
        return Err(anyhow!(
            "isolated-declarations parse errors in {}: {}",
            filename,
            errors.join("; ")
        ));
    }

    let emit = IsolatedDeclarations::new(&allocator, IsolatedDeclarationsOptions::default())
        .build(&parser_ret.program);

    // Codegen the declaration AST back to source. We deliberately do
    // NOT fail on `emit.errors` — isolated-declarations emits one per
    // exported value that lacks an explicit type, and we want the
    // partial emit anyway (the consumer can still use the surfaces
    // the plugin annotated correctly).
    let codegen_ret = Codegen::new().build(&emit.program);
    Ok(codegen_ret.code)
}

View on GitHub (pinned to 67894ca546)