diff --git a/index.js b/index.js
index b951fd9..d9f3a1c 100644
--- a/index.js
+++ b/index.js
@@ -263,100 +263,203 @@ var extensions = {
hook.registerTSX(config);
},
},
- '.swc.js': {
- module: '@swc/register',
- register: function (hook, config) {
- config = config || {
- only: [endsInSwcJs],
- ignore: [isNodeModules],
- jsc: {
- parser: {
- syntax: 'ecmascript',
+ '.swc.js': [
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInSwcJs],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'ecmascript',
+ },
},
- },
- module: {
- type: 'commonjs',
- },
- };
+ module: {
+ type: 'commonjs',
+ },
+ };
- hook(
- Object.assign({}, config, {
- extensions: '.js',
- })
- );
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.js',
+ })
+ );
+ },
},
- },
- '.swc.jsx': {
- module: '@swc/register',
- register: function (hook, config) {
- config = config || {
- only: [endsInSwcJsx],
- ignore: [isNodeModules],
- jsc: {
- parser: {
- syntax: 'ecmascript',
- jsx: true,
+ {
+ module: '@swc/register',
+ register: function (hook, config) {
+ config = config || {
+ only: [endsInSwcJs],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'ecmascript',
+ },
},
- },
- module: {
- type: 'commonjs',
- },
- };
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+
+ hook(
+ Object.assign({}, config, {
+ extensions: '.js',
+ })
+ );
+ },
+ }
+ ],
+ '.swc.jsx': [
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInSwcJsx],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'ecmascript',
+ jsx: true,
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
- hook(
- Object.assign({}, config, {
- extensions: '.jsx',
- })
- );
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.jsx',
+ })
+ );
+ },
},
- },
- '.swc.ts': {
- module: '@swc/register',
- register: function (hook, config) {
- config = config || {
- only: [endsInSwcTs],
- ignore: [isNodeModules],
- jsc: {
- parser: {
- syntax: 'typescript',
+ {
+ module: '@swc/register',
+ register: function (hook, config) {
+ config = config || {
+ only: [endsInSwcJsx],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'ecmascript',
+ jsx: true,
+ },
},
- },
- module: {
- type: 'commonjs',
- },
- };
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+ hook(
+ Object.assign({}, config, {
+ extensions: '.jsx',
+ })
+ );
+ },
+ }
+ ],
+ '.swc.ts': [
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInSwcTs],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
- hook(
- Object.assign({}, config, {
- extensions: '.ts',
- })
- );
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.ts',
+ })
+ );
+ },
},
- },
- '.swc.tsx': {
- module: '@swc/register',
- register: function (hook, config) {
- config = config || {
- only: [endsInSwcTsx],
- ignore: [isNodeModules],
- jsc: {
- parser: {
- syntax: 'typescript',
- tsx: true,
+ {
+ module: '@swc/register',
+ register: function (hook, config) {
+ config = config || {
+ only: [endsInSwcTs],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ },
},
- },
- module: {
- type: 'commonjs',
- },
- };
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+ hook(
+ Object.assign({}, config, {
+ extensions: '.ts',
+ })
+ );
+ },
+ }
+ ],
+ '.swc.tsx': [
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInSwcTsx],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ tsx: true,
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
- hook(
- Object.assign({}, config, {
- extensions: '.tsx',
- })
- );
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.tsx',
+ })
+ );
+ },
},
- },
+ {
+ module: '@swc/register',
+ register: function (hook, config) {
+ config = config || {
+ only: [endsInSwcTsx],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ tsx: true,
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+ hook(
+ Object.assign({}, config, {
+ extensions: '.tsx',
+ })
+ );
+ },
+ }
+ ],
'.toml': {
module: 'toml-require',
register: function (hook, config) {
@@ -401,6 +504,29 @@ var extensions = {
);
},
},
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInTs],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.ts',
+ })
+ );
+ },
+ },
{
module: '@swc/register',
register: function (hook, config) {
@@ -474,6 +600,30 @@ var extensions = {
);
},
},
+ {
+ module: '@swc-node/register',
+ register: function (mod, config) {
+ config = config || {
+ only: [endsInTsx],
+ ignore: [isNodeModules],
+ jsc: {
+ parser: {
+ syntax: 'typescript',
+ tsx: true,
+ },
+ },
+ module: {
+ type: 'commonjs',
+ },
+ };
+
+ mod.register(
+ Object.assign({}, config, {
+ extensions: '.tsx',
+ })
+ );
+ },
+ },
{
module: '@swc/register',
register: function (hook, config) {
diff --git a/scripts/plugin.mjs b/scripts/plugin.mjs
index 3bfec4c..d8aa7da 100644
--- a/scripts/plugin.mjs
+++ b/scripts/plugin.mjs
@@ -1,5 +1,4 @@
import fs from 'fs';
-import path from 'path';
import yaml from 'js-yaml';
import { codeImport } from 'remark-code-import';
diff --git a/test/fixtures/swc.js/0/package.json b/test/fixtures/swc.js/0/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/swc.js/0/package.json
+++ b/test/fixtures/swc.js/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
diff --git a/test/fixtures/swc.js/1/package.json b/test/fixtures/swc.js/1/package.json
new file mode 100644
index 0000000..e345156
--- /dev/null
+++ b/test/fixtures/swc.js/1/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "@swc/core": "^1.2.110",
+ "@swc/register": "^0.1.7"
+ }
+}
diff --git a/test/fixtures/swc.js/1/test.swc.js b/test/fixtures/swc.js/1/test.swc.js
new file mode 100644
index 0000000..5dfbff3
--- /dev/null
+++ b/test/fixtures/swc.js/1/test.swc.js
@@ -0,0 +1,14 @@
+class Foo {
+ #x = 1;
+ #y = 2;
+}
+
+export default {
+ data: {
+ trueKey: true,
+ falseKey: false,
+ subKey: {
+ subProp: 1,
+ },
+ },
+};
diff --git a/test/fixtures/swc.jsx/0/package.json b/test/fixtures/swc.jsx/0/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/swc.jsx/0/package.json
+++ b/test/fixtures/swc.jsx/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
diff --git a/test/fixtures/swc.jsx/1/package.json b/test/fixtures/swc.jsx/1/package.json
new file mode 100644
index 0000000..e345156
--- /dev/null
+++ b/test/fixtures/swc.jsx/1/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "@swc/core": "^1.2.110",
+ "@swc/register": "^0.1.7"
+ }
+}
diff --git a/test/fixtures/swc.jsx/1/test.swc.jsx b/test/fixtures/swc.jsx/1/test.swc.jsx
new file mode 100644
index 0000000..448a430
--- /dev/null
+++ b/test/fixtures/swc.jsx/1/test.swc.jsx
@@ -0,0 +1,28 @@
+const React = {
+ createElement(Component) {
+ return Component();
+ },
+};
+
+class Foo {
+ #x = 1;
+ #y = 2;
+}
+
+function Bar() {
+ const foo = new Foo();
+
+ return foo;
+}
+
+const a = ;
+
+export default {
+ data: {
+ trueKey: true,
+ falseKey: false,
+ subKey: {
+ subProp: 1,
+ },
+ },
+};
diff --git a/test/fixtures/swc.ts/0/package.json b/test/fixtures/swc.ts/0/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/swc.ts/0/package.json
+++ b/test/fixtures/swc.ts/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
diff --git a/test/fixtures/swc.ts/1/package.json b/test/fixtures/swc.ts/1/package.json
new file mode 100644
index 0000000..e345156
--- /dev/null
+++ b/test/fixtures/swc.ts/1/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "@swc/core": "^1.2.110",
+ "@swc/register": "^0.1.7"
+ }
+}
diff --git a/test/fixtures/swc.ts/1/test.swc.ts b/test/fixtures/swc.ts/1/test.swc.ts
new file mode 100644
index 0000000..9a0862f
--- /dev/null
+++ b/test/fixtures/swc.ts/1/test.swc.ts
@@ -0,0 +1,14 @@
+class Foo {
+ #x: number = 1;
+ #y: number = 2;
+}
+
+export default {
+ data: {
+ trueKey: true as boolean,
+ falseKey: false as boolean,
+ subKey: {
+ subProp: 1,
+ },
+ },
+} as const;
diff --git a/test/fixtures/swc.tsx/0/package.json b/test/fixtures/swc.tsx/0/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/swc.tsx/0/package.json
+++ b/test/fixtures/swc.tsx/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
diff --git a/test/fixtures/swc.tsx/1/package.json b/test/fixtures/swc.tsx/1/package.json
new file mode 100644
index 0000000..e345156
--- /dev/null
+++ b/test/fixtures/swc.tsx/1/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "@swc/core": "^1.2.110",
+ "@swc/register": "^0.1.7"
+ }
+}
diff --git a/test/fixtures/swc.tsx/1/test.swc.tsx b/test/fixtures/swc.tsx/1/test.swc.tsx
new file mode 100644
index 0000000..d26bcf1
--- /dev/null
+++ b/test/fixtures/swc.tsx/1/test.swc.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 ;
diff --git a/test/fixtures/ts/4/package.json b/test/fixtures/ts/4/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/ts/4/package.json
+++ b/test/fixtures/ts/4/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
diff --git a/test/fixtures/ts/5/package.json b/test/fixtures/ts/5/package.json
new file mode 100644
index 0000000..e345156
--- /dev/null
+++ b/test/fixtures/ts/5/package.json
@@ -0,0 +1,6 @@
+{
+ "dependencies": {
+ "@swc/core": "^1.2.110",
+ "@swc/register": "^0.1.7"
+ }
+}
diff --git a/test/fixtures/ts/5/test.ts b/test/fixtures/ts/5/test.ts
new file mode 100644
index 0000000..5044977
--- /dev/null
+++ b/test/fixtures/ts/5/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/4/package.json b/test/fixtures/tsx/4/package.json
index e345156..b7943f8 100644
--- a/test/fixtures/tsx/4/package.json
+++ b/test/fixtures/tsx/4/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
- "@swc/register": "^0.1.7"
+ "@swc-node/register": "^1.9.0"
}
}
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..d26bcf1
--- /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 ;
diff --git a/test/index.js b/test/index.js
index 1f9ca83..71bd1b7 100644
--- a/test/index.js
+++ b/test/index.js
@@ -131,7 +131,7 @@ describe('interpret.extensions', function () {
}
// Skip any swc test on linux due to https://github.com/swc-project/swc/issues/4107
- if (name === '@swc/register' && process.platform === 'linux') {
+ if ((name === '@swc/register' || '@swc-node/register') && process.platform === 'linux') {
this.skip();
}