Skip to content

Commit 8d0f1a7

Browse files
marco-ippolitoaduh95
authored andcommitted
test: module syntax should throw
PR-URL: #57121 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
1 parent ce1cfff commit 8d0f1a7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

test/es-module/test-typescript-eval.mjs

+20
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,23 @@ test('check syntax error is thrown when passing invalid syntax with --input-type
242242
match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/);
243243
strictEqual(result.code, 1);
244244
});
245+
246+
test('should not allow module keyword', async () => {
247+
const result = await spawnPromisified(process.execPath, [
248+
'--input-type=module-typescript',
249+
'--eval',
250+
'module F { export type x = number }']);
251+
strictEqual(result.stdout, '');
252+
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
253+
strictEqual(result.code, 1);
254+
});
255+
256+
test('should not allow declare module keyword', async () => {
257+
const result = await spawnPromisified(process.execPath, [
258+
'--input-type=module-typescript',
259+
'--eval',
260+
'declare module F { export type x = number }']);
261+
strictEqual(result.stdout, '');
262+
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
263+
strictEqual(result.code, 1);
264+
});

test/es-module/test-typescript-transform.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ test('execute a TypeScript file with legacy-module', async () => {
8585
fixtures.path('typescript/ts/transformation/test-legacy-module.ts'),
8686
]);
8787

88-
strictEqual(result.stderr, '');
89-
match(result.stdout, /Hello, TypeScript!/);
90-
strictEqual(result.code, 0);
88+
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
89+
match(result.stderr, /`module` keyword is not supported\. Use `namespace` instead/);
90+
strictEqual(result.stdout, '');
91+
strictEqual(result.code, 1);
9192
});
9293

9394
test('execute a TypeScript file with modern typescript syntax', async () => {

0 commit comments

Comments
 (0)