Skip to content

Commit

Permalink
fix(repl): error on import statement (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jul 2, 2022
1 parent 6fe2524 commit 30c56db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const preEval: REPLEval = async function (code, context, filename, callback) {
const transformed = await transform(
code,
filename,
{ loader: 'ts' },
{
loader: 'ts',
tsconfigRaw: {
compilerOptions: {
preserveValueImports: true,
},
},
},
).catch(
(error) => {
console.log(error.message);
Expand Down
22 changes: 22 additions & 0 deletions tests/specs/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,27 @@ export default testSuite(async ({ describe }) => {

tsxProcess.kill();
}, 5000);

test('errors on import statement', async () => {
const tsxProcess = tsx({
args: [],
});

await new Promise<void>((resolve) => {
tsxProcess.stdout!.on('data', (data: Buffer) => {
const chunkString = data.toString();

if (chunkString.includes('SyntaxError: Cannot use import statement inside the Node.js REPL')) {
return resolve();
}

if (chunkString.includes('> ')) {
tsxProcess.stdin?.write('import fs from "fs"\n');
}
});
});

tsxProcess.kill();
}, 2000);
});
});

0 comments on commit 30c56db

Please sign in to comment.