Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
315 changes: 233 additions & 82 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion scripts/plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import { codeImport } from 'remark-code-import';

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/swc.js/0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
"@swc-node/register": "^1.9.0"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/swc.js/1/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"
}
}
14 changes: 14 additions & 0 deletions test/fixtures/swc.js/1/test.swc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Foo {
#x = 1;
#y = 2;
}

export default {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};
2 changes: 1 addition & 1 deletion test/fixtures/swc.jsx/0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
"@swc-node/register": "^1.9.0"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/swc.jsx/1/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"
}
}
Loading