Skip to content

Commit ba6b0e6

Browse files
HRKingsphated
authored andcommitted
Add @swc/register as a module for TypeScript
1 parent 8a8df59 commit ba6b0e6

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

Diff for: index.js

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function ignoreNonBabelAndNodeModules(file) {
1919
path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
2020
}
2121

22+
// Not part of the above check because it seems broken
23+
function isNodeModules(file) {
24+
return path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
25+
}
26+
2227
var extensions = {
2328
'.babel.js': [
2429
{
@@ -246,6 +251,16 @@ var extensions = {
246251
});
247252
},
248253
},
254+
{
255+
module: '@swc/register',
256+
register: function(hook) {
257+
hook({
258+
extensions: '.ts',
259+
only: [endsInTs],
260+
ignore: [isNodeModules],
261+
});
262+
},
263+
},
249264
],
250265
'.tsx': [
251266
'ts-node/register',
@@ -273,6 +288,16 @@ var extensions = {
273288
});
274289
},
275290
},
291+
{
292+
module: '@swc/register',
293+
register: function(hook) {
294+
hook({
295+
extensions: '.tsx',
296+
only: [endsInTsx],
297+
ignore: [isNodeModules],
298+
});
299+
},
300+
},
276301
],
277302
'.wisp': 'wisp/engine/node',
278303
'.xml': 'require-xml',

Diff for: test/fixtures/ts/7/.swcrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript"
5+
}
6+
},
7+
"module": {
8+
"type": "commonjs"
9+
}
10+
}

Diff for: test/fixtures/ts/7/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@swc/core": "^1.2.110",
4+
"@swc/register": "^0.1.7"
5+
}
6+
}

Diff for: test/fixtures/ts/7/test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var test = {
2+
data: {
3+
trueKey: true,
4+
falseKey: false,
5+
subKey: {
6+
subProp: 1
7+
}
8+
}
9+
};
10+
11+
var main = {
12+
default: test
13+
};
14+
15+
export = main;

Diff for: test/fixtures/tsx/5/.swcrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": true
6+
}
7+
},
8+
"module": {
9+
"type": "commonjs"
10+
}
11+
}

Diff for: test/fixtures/tsx/5/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@swc/core": "^1.2.110",
4+
"@swc/register": "^0.1.7"
5+
}
6+
}

Diff for: test/fixtures/tsx/5/test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const React = {
2+
createElement(Component: () => any) {
3+
return Component()
4+
}
5+
}
6+
7+
// Test harmony arrow functions.
8+
const Component = () => {
9+
var trueKey: boolean = true
10+
var falseKey: boolean = false
11+
var subKey = { subProp: 1 }
12+
13+
// Test harmony object short notation.
14+
return { data: { trueKey, falseKey, subKey } }
15+
};
16+
17+
// Test TSX syntax.
18+
export default <Component />

0 commit comments

Comments
 (0)