Skip to content

Commit 00917ab

Browse files
authored
feat: allow to import TS files with js extension (#3899)
1 parent cea4364 commit 00917ab

File tree

12 files changed

+109
-2
lines changed

12 files changed

+109
-2
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { build } from '@e2e/helper';
2+
import { expect, test } from '@playwright/test';
3+
4+
test('should allow to import TS files with .js extension', async ({ page }) => {
5+
await build({
6+
cwd: __dirname,
7+
page,
8+
});
9+
expect(await page.evaluate(() => window.test)).toBe(1);
10+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const bar = () => {
2+
return <div>bar</div>;
3+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 1;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { bar } from './bar.js';
2+
import { foo } from './foo.js';
3+
4+
declare global {
5+
interface Window {
6+
test: number;
7+
}
8+
}
9+
10+
window.test = foo;
11+
12+
console.log(bar);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@rsbuild/config/tsconfig",
3+
"compilerOptions": {
4+
"jsx": "react-jsx",
5+
"baseUrl": "./",
6+
"outDir": "./dist",
7+
"paths": {
8+
"@/*": ["./src/*"]
9+
}
10+
},
11+
"include": ["src", "*.test.ts"]
12+
}

packages/compat/webpack/tests/__snapshots__/default.test.ts.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
333333
"alias": {
334334
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
335335
},
336+
"extensionAlias": {
337+
".js": [
338+
".ts",
339+
".tsx",
340+
".js",
341+
],
342+
},
336343
"extensions": [
337344
".ts",
338345
".tsx",
@@ -698,6 +705,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
698705
"alias": {
699706
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
700707
},
708+
"extensionAlias": {
709+
".js": [
710+
".ts",
711+
".tsx",
712+
".js",
713+
],
714+
},
701715
"extensions": [
702716
".ts",
703717
".tsx",
@@ -1012,6 +1026,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
10121026
"alias": {
10131027
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
10141028
},
1029+
"extensionAlias": {
1030+
".js": [
1031+
".ts",
1032+
".tsx",
1033+
".js",
1034+
],
1035+
},
10151036
"extensions": [
10161037
".ts",
10171038
".tsx",
@@ -1309,6 +1330,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
13091330
"alias": {
13101331
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
13111332
},
1333+
"extensionAlias": {
1334+
".js": [
1335+
".ts",
1336+
".tsx",
1337+
".js",
1338+
],
1339+
},
13121340
"extensions": [
13131341
".ts",
13141342
".tsx",

0 commit comments

Comments
 (0)