diff --git a/index.js b/index.js index a428c0e..c003144 100644 --- a/index.js +++ b/index.js @@ -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': [ { @@ -246,6 +251,16 @@ var extensions = { }); }, }, + { + module: '@swc/register', + register: function(hook) { + hook({ + extensions: '.ts', + only: [endsInTs], + ignore: [isNodeModules], + }); + }, + }, ], '.tsx': [ 'ts-node/register', @@ -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', diff --git a/test/fixtures/ts/7/.swcrc b/test/fixtures/ts/7/.swcrc new file mode 100644 index 0000000..a9c9497 --- /dev/null +++ b/test/fixtures/ts/7/.swcrc @@ -0,0 +1,10 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + } + }, + "module": { + "type": "commonjs" + } +} diff --git a/test/fixtures/ts/7/package.json b/test/fixtures/ts/7/package.json new file mode 100644 index 0000000..e345156 --- /dev/null +++ b/test/fixtures/ts/7/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@swc/core": "^1.2.110", + "@swc/register": "^0.1.7" + } +} diff --git a/test/fixtures/ts/7/test.ts b/test/fixtures/ts/7/test.ts new file mode 100644 index 0000000..9a955db --- /dev/null +++ b/test/fixtures/ts/7/test.ts @@ -0,0 +1,15 @@ +var test = { + data: { + trueKey: true, + falseKey: false, + subKey: { + subProp: 1 + } + } +}; + +var main = { + default: test +}; + +export = main; diff --git a/test/fixtures/tsx/5/.swcrc b/test/fixtures/tsx/5/.swcrc new file mode 100644 index 0000000..98f536d --- /dev/null +++ b/test/fixtures/tsx/5/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true + } + }, + "module": { + "type": "commonjs" + } +} diff --git a/test/fixtures/tsx/5/package.json b/test/fixtures/tsx/5/package.json new file mode 100644 index 0000000..e345156 --- /dev/null +++ b/test/fixtures/tsx/5/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@swc/core": "^1.2.110", + "@swc/register": "^0.1.7" + } +} diff --git a/test/fixtures/tsx/5/test.tsx b/test/fixtures/tsx/5/test.tsx new file mode 100644 index 0000000..c52e28d --- /dev/null +++ b/test/fixtures/tsx/5/test.tsx @@ -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