From 5c551c761a2e96bcf145b4e33b4ad1d333643221 Mon Sep 17 00:00:00 2001 From: codermarcos Date: Wed, 27 Mar 2024 23:42:10 -0300 Subject: [PATCH] feat: Add new version of SWC to fix #98 From fork codermarcos/interpret On branch master Changes to be committed: modified: index.js --- index.js | 315 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 233 insertions(+), 82 deletions(-) diff --git a/index.js b/index.js index b951fd9..fbc2c4a 100644 --- a/index.js +++ b/index.js @@ -263,100 +263,204 @@ 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', + }, + }; + + console.log(hook) + + 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 +505,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 +601,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) {