swc-project/swc · error

assertion failed\n{}

Error message

assertion failed\n{}

What it means

The terminal panic of the assert_eq_ignore_span! macro (crates/testing/src/lib.rs:292). After spans are stripped from both values, if the despanned structures still differ, the macro prints the module path and panics with this generic 'assertion failed' header plus the rendered left/right dump from print_left_right. It means two ASTs that are expected to be identical except for spans genuinely differ in content; the differing left/right values are the faulty input.

Source

Thrown at crates/testing/src/lib.rs:292

            )
        });

        buf
    };

    write_to_file(&target_dir.join("left"), &left);
    write_to_file(&target_dir.join("right"), &right);

    format!("----- {test_name}\n    left:\n{left}\n    right:\n{right}")
}

#[macro_export]
macro_rules! assert_eq_ignore_span {
    ($l:expr, $r:expr) => {{
        println!("{}", module_path!());
        let (l, r) = ($crate::drop_span($l), $crate::drop_span($r));
        if l != r {
            panic!("assertion failed\n{}", $crate::print_left_right(&l, &r));
        }
    }};
}

pub fn diff(l: &str, r: &str) -> String {
    let cs = Changeset::new(l, r, "\n");

    format!("{cs}")
}

/// Used for assertions.
///
/// Prints string without escaping special characters on failure.
#[derive(PartialEq, Eq)]
pub struct DebugUsingDisplay<'a>(pub &'a str);

impl Debug for DebugUsingDisplay<'_> {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Inspect the left/right files written under target/swc-test-results to see exactly which node differs
  2. Regenerate expected fixtures with UPDATE=1 only after confirming the difference is an intended behavior change
  3. Fix the transform that produced the unexpected output instead of updating the fixture
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/testing/src/lib.rs:292 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/011191adf3103e3a. Report an issue: GitHub.