Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ exports[`transform in strip-only mode should throw an error when it encounters a
}
`;

exports[`transform in strip-only mode should throw an error when it encounters a module 2`] = `
{
"code": "UnsupportedSyntax",
"message": " x \`module\` keyword is not supported. Use \`namespace\` instead.
,----
1 | declare module foo { }
: ^^^^^^
\`----
",
}
`;

exports[`transform in strip-only mode should throw an error when it encounters a namespace 1`] = `
{
"code": "UnsupportedSyntax",
Expand All @@ -153,6 +165,15 @@ exports[`transform in strip-only mode should throw an error when it encounters a
}
`;

exports[`transform in transform mode should throw an error when it encounters a declared module 1`] = `
" x \`module\` keyword is not supported. Use \`namespace\` instead.
Copy link
Contributor

@marco-ippolito marco-ippolito Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magic-akari @kdy1 its missing the error code "Unsupported Syntax" in transform mode
nodejs/amaro#177

,----
1 | declare module foo { }
: ^^^^^^
\`----
"
`;

exports[`transform in transform mode should throw an error when it encounters a module 1`] = `
" x \`module\` keyword is not supported. Use \`namespace\` instead.
,----
Expand Down
18 changes: 18 additions & 0 deletions bindings/binding_typescript_wasm/__tests__/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ describe("transform", () => {
).rejects.toMatchSnapshot();
});

it("should throw an error when it encounters a module", async () => {
await expect(
swc.transform("declare module foo { }", {
mode: "strip-only",
deprecatedTsModuleAsError: true,
}),
).rejects.toMatchSnapshot();
});

it("should not emit 'Caused by: failed to parse'", async () => {
await expect(
swc.transform("function foo() { await Promise.resolve(1); }", {
Expand Down Expand Up @@ -171,5 +180,14 @@ describe("transform", () => {
}),
).rejects.toMatchSnapshot();
});

it("should throw an error when it encounters a declared module", async () => {
await expect(
swc.transform("declare module foo { }", {
mode: "transform",
deprecatedTsModuleAsError: true,
}),
).rejects.toMatchSnapshot();
});
});
});
13 changes: 13 additions & 0 deletions crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
: ^^^^^^
4 | export const foo = 1;
`----
x `module` keyword is not supported. Use `namespace` instead.
,-[7:1]
6 |
7 | module Foo { }
: ^^^^^^
8 | declare module Bar { }
`----
x `module` keyword is not supported. Use `namespace` instead.
,-[8:1]
7 | module Foo { }
8 | declare module Bar { }
: ^^^^^^
`----
x TypeScript namespace declaration is not supported in strip-only mode
,-[3:1]
2 |
Expand Down
5 changes: 4 additions & 1 deletion crates/swc_fast_ts_strip/tests/errors/ts-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

module Foo {
export const foo = 1;
}
}

module Foo { }
declare module Bar { }
Loading