Skip to content

Commit 0018a8e

Browse files
authored
test(es/transform): Add tests for source map (#10375)
**Description:** I think the issue is in `@swc/cli` **Related issue:** - #6726
1 parent 1e2eb36 commit 0018a8e

File tree

8 files changed

+84
-0
lines changed

8 files changed

+84
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://swc.rs/schema.json",
3+
"jsc": {
4+
"minify": {
5+
"mangle": true
6+
},
7+
"parser": {
8+
"syntax": "typescript"
9+
},
10+
"target": "es2024",
11+
"loose": false,
12+
"externalHelpers": false,
13+
"keepClassNames": false
14+
},
15+
"minify": true,
16+
"sourceMaps": true
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface Props {
2+
foo: string;
3+
}
4+
5+
function Page(props: Props) {
6+
props.foo;
7+
}
8+
9+
// @ts-expect-error
10+
Page();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function App() {
2+
let [counter, setCounter] = React.useState(0);
3+
if (counter === 10) throw new Error("Too high!");
4+
return Other();
5+
}
6+
7+
function Other() {
8+
return "Change me";
9+
}
10+
11+
globalThis.Other = Other;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"mappings": "AAIA,SAASA,KAAKC,CAAY,EACtBA,EAAMC,GAAG,AACb,CAGAF",
3+
"names": [
4+
"Page",
5+
"props",
6+
"foo"
7+
],
8+
"sources": [
9+
"../../input/2.ts"
10+
],
11+
"sourcesContent": [
12+
"interface Props {\n foo: string;\n}\n\nfunction Page(props: Props) {\n props.foo;\n}\n\n// @ts-expect-error\nPage();"
13+
],
14+
"version": 3
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function Page(o){o.foo}Page();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function App(){let[t,r]=React.useState(0);if(t===10)throw new Error("Too high!");return e()}function e(){return"Change me"}globalThis.Other=e;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"mappings": "AAAA,OAAO,SAASA,MACZ,GAAI,CAACC,EAASC,EAAW,CAAGC,MAAMC,QAAQ,CAAC,GAC3C,GAAIH,IAAY,GAAI,MAAM,IAAII,MAAM,aACpC,OAAOC,GACX,CAEA,SAASA,IACL,MAAO,WACX,CAEAC,WAAWD,KAAK,CAAGA",
3+
"names": [
4+
"App",
5+
"counter",
6+
"setCounter",
7+
"React",
8+
"useState",
9+
"Error",
10+
"Other",
11+
"globalThis"
12+
],
13+
"sources": [
14+
"../../input/index.jsx"
15+
],
16+
"sourcesContent": [
17+
"export function App() {\n let [counter, setCounter] = React.useState(0);\n if (counter === 10) throw new Error(\"Too high!\");\n return Other();\n}\n\nfunction Other() {\n return \"Change me\";\n}\n\nglobalThis.Other = Other;"
18+
],
19+
"version": 3
20+
}

packages/core/__tests__/transform/sourcemap_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,13 @@ describe("sourceMaps: true in .swcrc", () => {
125125

126126
expect(out.map).toBeUndefined();
127127
});
128+
129+
it(`should have names `, async () => {
130+
const out = await swc.transformFile(
131+
path.join(__dirname, "..", "..", "tests", "issue-2120", "input.js")
132+
);
133+
134+
expect(out.map).toBeTruthy();
135+
expect(JSON.parse(out.map).names).toEqual(["Foo", "Array", "console", "log"]);
136+
});
128137
});

0 commit comments

Comments
 (0)