Repository: swc-project/swc (rust)

Issue:
Paths bug
### Describe the bug

Error compiling path aliases. The paths must either remain unchanged or point to the file.

### Input code

```typescript
// src/utils.ts
export const str = "";

// src/app/src/index.ts
import { str } from "$utils";
console.log(str);
```


### Config

```json
{
    "$schema": "https://json.schemastore.org/swcrc",
    "jsc": {
        "baseUrl": "./",
        "paths": {
            "$utils": [
                "./src/utils.ts"
            ]
        }
    }
}
```


### Playground link (or link to the minimal reproduction)

https://github.com/AlexRMU/swc-bug

### SWC Info output

```
    Operating System:
        Platform: win32
        Arch: x64
        Machine Type: x86_64
        Version: Windows 10 Pro
        CPU: (12 cores)
            Models: 11th Gen Intel(R) Core(TM) i5-11400F @ 2.60GHz

    Binaries:
        Node: 20.8.1
        npm: N/A
        Yarn: N/A
        pnpm: N/A

    Relevant Packages:
        @swc/core: 1.4.2
        @swc/helpers: N/A
        @swc/types: N/A
        typescript: 5.3.3

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A
```

### Expected behavior

```ts
import { str } from "$utils";
console.log(str);
```
or
```ts
import { str } from "../../utils.ts";
console.log(str);
```

### Actual behavior

```ts
import { str } from "../../$utils";
console.log(str);
```

### Version

"@swc/cli": "^0.3.9", "@swc/core": "^1.4.2"

### Additional context

_No response_

Pull request description:
fix(es/modules): Fix resolution of `jsc.paths` with exact match
**Description:**


**Related issue:**

 - Closes #8668

Patch:
diff --git a/crates/swc_ecma_loader/src/resolvers/tsc.rs b/crates/swc_ecma_loader/src/resolvers/tsc.rs
index b7794652bd..357ea3961a 100644
--- a/crates/swc_ecma_loader/src/resolvers/tsc.rs
+++ b/crates/swc_ecma_loader/src/resolvers/tsc.rs
@@ -299,7 +299,16 @@ where
 
                     if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
                     {
-                        return Ok(res);
+                        return Ok(Resolution {
+                            slug: match &res.filename {
+                                FileName::Real(p) => p
+                                    .file_stem()
+                                    .filter(|&s| s != "index")
+                                    .map(|v| v.to_string_lossy().into()),
+                                _ => None,
+                            },
+                            ..res
+                        });
                     }
 
                     return Ok(Resolution {


Test patch:
diff --git a/crates/swc/tests/fixture/issues-8xxx/8668/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8668/input/.swcrc
new file mode 100644
index 0000000000..d7e49e17d2
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8668/input/.swcrc
@@ -0,0 +1,11 @@
+{
+    "$schema": "https://json.schemastore.org/swcrc",
+    "jsc": {
+        "baseUrl": "./",
+        "paths": {
+            "$utils": [
+                "./src/utils.ts"
+            ]
+        }
+    }
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8668/input/src/app/src/index.ts b/crates/swc/tests/fixture/issues-8xxx/8668/input/src/app/src/index.ts
new file mode 100644
index 0000000000..5ee45b7e85
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8668/input/src/app/src/index.ts
@@ -0,0 +1,2 @@
+import { str } from "$utils";
+console.log(str);
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8668/input/src/utils.ts b/crates/swc/tests/fixture/issues-8xxx/8668/input/src/utils.ts
new file mode 100644
index 0000000000..d9b1ed7a88
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8668/input/src/utils.ts
@@ -0,0 +1,1 @@
+export const str = "";
diff --git a/crates/swc/tests/fixture/issues-8xxx/8668/output/src/app/src/index.ts b/crates/swc/tests/fixture/issues-8xxx/8668/output/src/app/src/index.ts
new file mode 100644
index 0000000000..ca434401ae
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8668/output/src/app/src/index.ts
@@ -0,0 +1,2 @@
+import { str } from "../../utils";
+console.log(str);
diff --git a/crates/swc/tests/fixture/issues-8xxx/8668/output/src/utils.ts b/crates/swc/tests/fixture/issues-8xxx/8668/output/src/utils.ts
new file mode 100644
index 0000000000..5a589ce769
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8668/output/src/utils.ts
@@ -0,0 +1,1 @@
+export var str = "";