Skip to content

Commit b43936e

Browse files
committed
feat: add jiti support
1 parent c09bf70 commit b43936e

File tree

10 files changed

+114
-1
lines changed

10 files changed

+114
-1
lines changed

index.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ var extensions = {
215215
hook(Object.assign({}, config, { extensions: '.jsx' }));
216216
},
217217
},
218+
{
219+
module: 'jiti/lib/jiti-register.mjs',
220+
register: function () {
221+
process.env.JITI_JSX = true
222+
},
223+
},
218224
'sucrase/register/jsx',
219225
],
220226
'.litcoffee': 'coffeescript/register',
@@ -366,6 +372,7 @@ var extensions = {
366372
'.ts': [
367373
'ts-node/register',
368374
'sucrase/register/ts',
375+
'jiti/lib/jiti-register.mjs',
369376
{
370377
module: '@babel/register',
371378
register: function (hook, config) {
@@ -425,10 +432,16 @@ var extensions = {
425432
},
426433
},
427434
],
428-
'.cts': ['ts-node/register'],
435+
'.cts': ['ts-node/register', 'jiti/lib/jiti-register.mjs'],
429436
'.tsx': [
430437
'ts-node/register',
431438
'sucrase/register/tsx',
439+
{
440+
module: 'jiti/lib/jiti-register.mjs',
441+
register: function () {
442+
process.env.JITI_JSX = true
443+
},
444+
},
432445
{
433446
module: '@babel/register',
434447
register: function (hook, config) {

test/fixtures/cts/1/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"jiti": "^2.4.2"
4+
}
5+
}

test/fixtures/cts/1/test.cts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var test: {
2+
data: {
3+
trueKey: boolean;
4+
falseKey: boolean;
5+
subKey: {
6+
subProp: number;
7+
};
8+
};
9+
} = {
10+
data: {
11+
trueKey: true,
12+
falseKey: false,
13+
subKey: {
14+
subProp: 1,
15+
},
16+
},
17+
};
18+
19+
export default test;

test/fixtures/cts/1/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"declaration": false,
6+
"noImplicitAny": false,
7+
"removeComments": true,
8+
"sourceMap": true,
9+
"outDir": ".tmp"
10+
}
11+
}

test/fixtures/jsx/2/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"jiti": "^2.4.2"
4+
}
5+
}

test/fixtures/jsx/2/test.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const React = {
2+
createElement: function (Component) {
3+
return Component();
4+
},
5+
};
6+
7+
// Test harmony arrow functions
8+
const Component = () => {
9+
var trueKey = true;
10+
var falseKey = false;
11+
var subKey = { subProp: 1 };
12+
// Test harmony object short notation
13+
return { data: { trueKey, falseKey, subKey } };
14+
};
15+
16+
// Test JSX syntax
17+
module.exports = <Component />;

test/fixtures/ts/5/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"jiti": "^2.4.2"
4+
}
5+
}

test/fixtures/ts/5/test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var test = {
2+
data: {
3+
trueKey: true,
4+
falseKey: false,
5+
subKey: {
6+
subProp: 1,
7+
},
8+
},
9+
};
10+
11+
var main = {
12+
default: test,
13+
};
14+
15+
export = main;

test/fixtures/tsx/5/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"jiti": "^2.4.2"
4+
}
5+
}

test/fixtures/tsx/5/test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const React = {
2+
createElement(Component: () => any) {
3+
return Component();
4+
},
5+
};
6+
7+
// Test harmony arrow functions.
8+
const Component = () => {
9+
var trueKey: boolean = true;
10+
var falseKey: boolean = false;
11+
var subKey = { subProp: 1 };
12+
13+
// Test harmony object short notation.
14+
return { data: { trueKey, falseKey, subKey } };
15+
};
16+
17+
// Test TSX syntax.
18+
export default <Component />;

0 commit comments

Comments
 (0)