Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for swc #74

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function ignoreNonBabelAndNodeModules(file) {
path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
}

// Not part of the above check because it seems broken
function isNodeModules(file) {
return path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
}

var extensions = {
'.babel.js': [
{
Expand Down Expand Up @@ -246,6 +251,16 @@ var extensions = {
});
},
},
{
module: '@swc/register',
register: function(hook) {
hook({
extensions: '.ts',
only: [endsInTs],
ignore: [isNodeModules],
});
},
},
],
'.tsx': [
'ts-node/register',
Expand Down Expand Up @@ -273,6 +288,16 @@ var extensions = {
});
},
},
{
module: '@swc/register',
register: function(hook) {
hook({
extensions: '.tsx',
only: [endsInTsx],
ignore: [isNodeModules],
});
},
},
],
'.wisp': 'wisp/engine/node',
'.xml': 'require-xml',
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/ts/7/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/ts/7/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/ts/7/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var test = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};

var main = {
default: test
};

export = main;
11 changes: 11 additions & 0 deletions test/fixtures/tsx/5/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
}
},
"module": {
"type": "commonjs"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/tsx/5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
}
}
18 changes: 18 additions & 0 deletions test/fixtures/tsx/5/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const React = {
createElement(Component: () => any) {
return Component()
}
}

// Test harmony arrow functions.
const Component = () => {
var trueKey: boolean = true
var falseKey: boolean = false
var subKey = { subProp: 1 }

// Test harmony object short notation.
return { data: { trueKey, falseKey, subKey } }
};

// Test TSX syntax.
export default <Component />