Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check erasable namespaces are supported #162

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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