swc-project/swc · error

test_inlined_transform does not support paths outside of the

Error message

test_inlined_transform does not support paths outside of the crate root

What it means

`test_inlined_transform` locates snapshots by joining the caller's file path (from `panic::Location::caller()`) onto `CARGO_WORKSPACE_ROOT`, then requires it to sit under the current crate's manifest dir via `strip_prefix(&manifest_dir)`. The expect fires when the file that invoked `test_inlined_transform` does not live inside the crate being compiled — the harness has no place to put the `__swc_snapshots__` output.

Source

Thrown at crates/swc_ecma_transforms_testing/src/lib.rs:414

    test_name: &str,
    syntax: Syntax,
    module: Option<bool>,
    tr: F,
    input: &str,
) where
    F: FnOnce(&mut Tester) -> P,
    P: Pass,
{
    let loc = panic::Location::caller();

    let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));

    let test_file_path = CARGO_WORKSPACE_ROOT.join(loc.file());

    let snapshot_dir = manifest_dir.join("tests").join("__swc_snapshots__").join(
        test_file_path
            .strip_prefix(&manifest_dir)
            .expect("test_inlined_transform does not support paths outside of the crate root"),
    );

    test_fixture_inner(
        syntax,
        Box::new(move |tester| Box::new(tr(tester))),
        input,
        &snapshot_dir.join(format!("{test_name}.js")),
        FixtureTestConfig {
            module,
            ..Default::default()
        },
    )
}

/// NOT A PUBLIC API. DO NOT USE.
#[doc(hidden)]
#[macro_export]
macro_rules! test_location {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Invoke `test_inlined_transform` directly from a test file inside the crate whose snapshots you want (each crate owns tests/__swc_snapshots__).
  2. If a shared helper must drive inlined tests, make the helper take explicit paths and use `test_fixture`/`test_transform` style APIs that accept a snapshot path, instead of this caller-location-based helper.
  3. Check for path oddities (symlinks, `#[path]` includes from outside the crate root) in the failing test's file.
Defensive patterns

Strategy: validation

Prevention

When it happens

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

Common situations: Test helpers that live in a shared crate but call `test_inlined_transform` on behalf of another crate; vendored or symlinked source layouts where the compile-time file path and the manifest dir disagree; moving tests between workspace members without moving the snapshot helper call.

Related errors


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