test: module syntax should throw

PR-URL: https://github.com/nodejs/node/pull/57121
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
This commit is contained in:
Marco Ippolito 2025-02-28 09:37:45 -05:00 committed by Node.js GitHub Bot
parent 5b7ebbc7b3
commit 1347d424e2
2 changed files with 24 additions and 3 deletions

View file

@ -242,3 +242,23 @@ test('check syntax error is thrown when passing invalid syntax with --input-type
match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/);
strictEqual(result.code, 1);
});
test('should not allow module keyword', async () => {
const result = await spawnPromisified(process.execPath, [
'--input-type=module-typescript',
'--eval',
'module F { export type x = number }']);
strictEqual(result.stdout, '');
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
strictEqual(result.code, 1);
});
test('should not allow declare module keyword', async () => {
const result = await spawnPromisified(process.execPath, [
'--input-type=module-typescript',
'--eval',
'declare module F { export type x = number }']);
strictEqual(result.stdout, '');
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
strictEqual(result.code, 1);
});

View file

@ -85,9 +85,10 @@ test('execute a TypeScript file with legacy-module', async () => {
fixtures.path('typescript/ts/transformation/test-legacy-module.ts'),
]);
strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
match(result.stderr, /`module` keyword is not supported\. Use `namespace` instead/);
strictEqual(result.stdout, '');
strictEqual(result.code, 1);
});
test('execute a TypeScript file with modern typescript syntax', async () => {