Skip to content

Commit

Permalink
test: check erasable namespaces are supported
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Feb 4, 2025
1 parent 4e6441c commit 3d84c70
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,49 @@ test("should not throw on yield new line when stripped", (t) => {
test("should throw invalid syntax error", (t) => {
assert.throws(() => transformSync("const foo;"));
});

test("erasable namespaces and modules should be supported", (t) => {
const tests = [
"namespace Empty {}",
`namespace TypeOnly {
type A = string;
export type B = A | number;
export interface I {}
export namespace Inner {
export type C = B;
}
}`,
`namespace My.Internal.Types {
export type Foo = number;
}`,
"declare namespace C { export let x = 1 }",
"declare module D { export let x = 1 }",
"module F { export type x = number }",
];
for (const input of tests) {
const { code } = transformSync(input);
t.assert.snapshot(code);
}
});

test("should throw on non erasable namespace/module", (t) => {
const tests = [
"namespace A { export let x = 1 }",
`namespace With.Imports {
import Types = My.Internal.Types;
export type Foo = Types.Foo;
}`,
"namespace B { ; } ",
"module E { export let x = 1 }",
`namespace A { export let x = 1; }
namespace B { import x = A.x; }
namespace C { export import x = A.x; }`,
];

for (const input of tests) {
assert.throws(() => transformSync(input), { code: "UnsupportedSyntax" });
}
});
24 changes: 24 additions & 0 deletions test/snapshots/index.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
exports[`erasable namespaces and modules should be supported 1`] = `
" "
`;

exports[`erasable namespaces and modules should be supported 2`] = `
" \\n \\t\\t \\n\\n \\t\\t \\n\\n \\t\\t\\t \\n\\n\\t\\t\\t \\n\\t\\t\\t\\t \\n\\t\\t\\t \\n\\t\\t "
`;

exports[`erasable namespaces and modules should be supported 3`] = `
" \\n \\t\\t \\n\\t\\t "
`;

exports[`erasable namespaces and modules should be supported 4`] = `
" "
`;

exports[`erasable namespaces and modules should be supported 5`] = `
" "
`;

exports[`erasable namespaces and modules should be supported 6`] = `
" "
`;

exports[`should handle User type and isAdult function 1`] = `
"\\n \\n \\n \\n \\n\\n function isAdult(user ) {\\n return user.age >= 18;\\n }\\n "
`;
Expand Down

0 comments on commit 3d84c70

Please sign in to comment.