Repository: swc-project/swc
File: crates/swc_cli_impl/tests/issues.rs (Rust)

Code before:
    // target: es2022 keeps arrow functions (unlike default es5)
    fs::write(
        tmp.path().join(".swcrc"),
        r#"{
            "jsc": {
                "parser": { "syntax": "ecmascript" },
                "target": "es2022"
            }
        }"#,
    )?;

    fs::write(subdir.join("input.js"), "const arrow = () => 'hello';")?;

    let mut cmd = cli()?;
    cmd.current_dir(&subdir)
        .arg("compile")
        .arg("--root-mode")
        .arg("upward")
        .arg("--out-dir")
        .arg(".")
        .arg("input.js");

    cmd.assert().success();

    // Verify the config was found: es2022 keeps arrow functions
    let output = fs::read_to_string(subdir.join("input.js"))?;
    assert!(
        output.contains("=>"),
        "Arrow should be kept with es2022 target from parent .swcrc. Got: {output}"
    );

    Ok(())
}

/// Tests that `--root-mode upward` fails when no `.swcrc` is found.
#[test]
fn root_mode_upward_fails_without_config() -> Result<()> {
    let tmp = TempDir::new()?;

    // No .swcrc anywhere
    fs::write(tmp.path().join("input.js"), "const arrow = () => 'hello';")?;

    let mut cmd = cli()?;
    cmd.current_dir(&tmp)
        .arg("compile")
        .arg("--root-mode")
        .arg("upward")
        .arg("--out-dir")
        .arg(".")
        .arg("input.js");


Review comment (bug):
The test reads from `input.js` but should read from the compiled output file. The `--out-dir` is set to `.` (current directory), so the output should be read from the same location, but the original input file would be overwritten. This test is checking the wrong file - it should verify the compiled output, not re-read the input.
```suggestion
        .arg("out")
        .arg("input.js");

    cmd.assert().success();

    // Verify the config was found: es2022 keeps arrow functions
    let output = fs::read_to_string(subdir.join("out").join("input.js"))?;
```

Code after:
    // target: es2022 keeps arrow functions (unlike default es5)
    fs::write(
        tmp.path().join(".swcrc"),
        r#"{
            "jsc": {
                "parser": { "syntax": "ecmascript" },
                "target": "es2022"
            }
        }"#,
    )?;

    fs::write(subdir.join("input.js"), "const arrow = () => 'hello';")?;

    let mut cmd = cli()?;
    cmd.current_dir(&subdir)
        .arg("compile")
        .arg("--root-mode")
        .arg("upward")
        .arg("--out-file")
        .arg("output.js")
        .arg("input.js");

    cmd.assert().success();

    // Verify the config was found: es2022 keeps arrow functions
    let output = fs::read_to_string(subdir.join("output.js"))?;
    assert!(
        output.contains("=>"),
        "Arrow should be kept with es2022 target from parent .swcrc. Got: {output}"
    );

    Ok(())
}

/// Tests that `--root-mode root` does NOT search parent directories for
/// `.swcrc`.
#[test]
fn root_mode_root_ignores_parent_config() -> Result<()> {
    let tmp = TempDir::new()?;

    let subdir = tmp.path().join("subdir");
    create_dir_all(&subdir)?;

    // Parent has .swcrc with es2022 (keeps arrows)
    fs::write(
        tmp.path().join(".swcrc"),
        r#"{
            "jsc": {
                "parser": { "syntax": "ecmascript" },
                "target": "es2022"
            }