Skip to content

Commit 62b285e

Browse files
marco-ippolitoaduh95
authored andcommitted
test: module syntax should throw
PR-URL: #57121 Reviewed-By: Pietro Marchini <[email protected]>
1 parent 5f0f0db commit 62b285e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,25 @@ test('check syntax error is thrown when passing invalid syntax with --input-type
263263
match(result.stderr, /ERR_INVALID_TYPESCRIPT_SYNTAX/);
264264
strictEqual(result.code, 1);
265265
});
266+
267+
test('should not allow module keyword', async () => {
268+
const result = await spawnPromisified(process.execPath, [
269+
'--experimental-strip-types',
270+
'--input-type=module-typescript',
271+
'--eval',
272+
'module F { export type x = number }']);
273+
strictEqual(result.stdout, '');
274+
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
275+
strictEqual(result.code, 1);
276+
});
277+
278+
test('should not allow declare module keyword', async () => {
279+
const result = await spawnPromisified(process.execPath, [
280+
'--experimental-strip-types',
281+
'--input-type=module-typescript',
282+
'--eval',
283+
'declare module F { export type x = number }']);
284+
strictEqual(result.stdout, '');
285+
match(result.stderr, /ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX/);
286+
strictEqual(result.code, 1);
287+
});

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

Lines changed: 4 additions & 3 deletions
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)