Skip to content

feat: add jiti support #102

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
feat: add jiti support
  • Loading branch information
folliehiyuki committed Mar 15, 2025
commit b43936ea87d7996c14f93dc0de8c8182c72d80b0
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ var extensions = {
hook(Object.assign({}, config, { extensions: '.jsx' }));
},
},
{
module: 'jiti/lib/jiti-register.mjs',
register: function () {
process.env.JITI_JSX = true
},
},
'sucrase/register/jsx',
],
'.litcoffee': 'coffeescript/register',
Expand Down Expand Up @@ -366,6 +372,7 @@ var extensions = {
'.ts': [
'ts-node/register',
'sucrase/register/ts',
'jiti/lib/jiti-register.mjs',
{
module: '@babel/register',
register: function (hook, config) {
Expand Down Expand Up @@ -425,10 +432,16 @@ var extensions = {
},
},
],
'.cts': ['ts-node/register'],
'.cts': ['ts-node/register', 'jiti/lib/jiti-register.mjs'],
'.tsx': [
'ts-node/register',
'sucrase/register/tsx',
{
module: 'jiti/lib/jiti-register.mjs',
register: function () {
process.env.JITI_JSX = true
},
},
{
module: '@babel/register',
register: function (hook, config) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/cts/1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jiti": "^2.4.2"
}
}
19 changes: 19 additions & 0 deletions test/fixtures/cts/1/test.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var test: {
data: {
trueKey: boolean;
falseKey: boolean;
subKey: {
subProp: number;
};
};
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};

export default test;
11 changes: 11 additions & 0 deletions test/fixtures/cts/1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"outDir": ".tmp"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/jsx/2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jiti": "^2.4.2"
}
}
17 changes: 17 additions & 0 deletions test/fixtures/jsx/2/test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const React = {
createElement: function (Component) {
return Component();
},
};

// Test harmony arrow functions
const Component = () => {
var trueKey = true;
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
return { data: { trueKey, falseKey, subKey } };
};

// Test JSX syntax
module.exports = <Component />;
5 changes: 5 additions & 0 deletions test/fixtures/ts/5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jiti": "^2.4.2"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/ts/5/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;
5 changes: 5 additions & 0 deletions test/fixtures/tsx/5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jiti": "^2.4.2"
}
}
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 />;