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: add more namespace fixtures #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions tests/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ it("errors on instantiated namespaces due to having runtime emit", () => {
);
});

it("importing instantiated namespace", () => {
const onError = mock.fn();
const out = tsBlankSpace(
`
namespace A { export let x = 1; }
namespace B { import x = A.x; }
namespace C { export import x = A.x; }
`,
onError,
);
assert.equal(onError.mock.callCount(), 2);
const errorNodeNames = errorCallbackToModuleDeclarationNames(onError);
assert.deepEqual(errorNodeNames, ["A", "C"]);
// Only 'B' is erased:
assert.equal(
out,
[
``,
` namespace A { export let x = 1; }`,
` ; `,
` namespace C { export import x = A.x; }`,
` `,
].join("\n"),
);
});

it("errors on CJS export assignment syntax", () => {
const onError = mock.fn();
const out = tsBlankSpace(
Expand Down
7 changes: 7 additions & 0 deletions tests/fixture/cases/namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ declare namespace Declared {
export function foo(): void
}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `declare namespace`

export namespace ValueImport {
import foo = Declared.foo;
export type T = typeof foo;
}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // _value_ import namespace

Declared.foo(); // May throw at runtime if declaration was false

export const x: With.Imports.Foo = 1;
Expand Down
7 changes: 7 additions & 0 deletions tests/fixture/output/namespaces.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.