Skip to content

Commit 37672e0

Browse files
authored
test(ts/fast-strip): Add tests for declare module error cases (#10040)
**Related issue:** - nodejs/amaro#174
1 parent 80ee121 commit 37672e0

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

Diff for: bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap

+21
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ exports[`transform in strip-only mode should throw an error when it encounters a
129129
}
130130
`;
131131
132+
exports[`transform in strip-only mode should throw an error when it encounters a module 2`] = `
133+
{
134+
"code": "UnsupportedSyntax",
135+
"message": " x \`module\` keyword is not supported. Use \`namespace\` instead.
136+
,----
137+
1 | declare module foo { }
138+
: ^^^^^^
139+
\`----
140+
",
141+
}
142+
`;
143+
132144
exports[`transform in strip-only mode should throw an error when it encounters a namespace 1`] = `
133145
{
134146
"code": "UnsupportedSyntax",
@@ -153,6 +165,15 @@ exports[`transform in strip-only mode should throw an error when it encounters a
153165
}
154166
`;
155167
168+
exports[`transform in transform mode should throw an error when it encounters a declared module 1`] = `
169+
" x \`module\` keyword is not supported. Use \`namespace\` instead.
170+
,----
171+
1 | declare module foo { }
172+
: ^^^^^^
173+
\`----
174+
"
175+
`;
176+
156177
exports[`transform in transform mode should throw an error when it encounters a module 1`] = `
157178
" x \`module\` keyword is not supported. Use \`namespace\` instead.
158179
,----

Diff for: bindings/binding_typescript_wasm/__tests__/transform.js

+18
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ describe("transform", () => {
132132
).rejects.toMatchSnapshot();
133133
});
134134

135+
it("should throw an error when it encounters a module", async () => {
136+
await expect(
137+
swc.transform("declare module foo { }", {
138+
mode: "strip-only",
139+
deprecatedTsModuleAsError: true,
140+
}),
141+
).rejects.toMatchSnapshot();
142+
});
143+
135144
it("should not emit 'Caused by: failed to parse'", async () => {
136145
await expect(
137146
swc.transform("function foo() { await Promise.resolve(1); }", {
@@ -171,5 +180,14 @@ describe("transform", () => {
171180
}),
172181
).rejects.toMatchSnapshot();
173182
});
183+
184+
it("should throw an error when it encounters a declared module", async () => {
185+
await expect(
186+
swc.transform("declare module foo { }", {
187+
mode: "transform",
188+
deprecatedTsModuleAsError: true,
189+
}),
190+
).rejects.toMatchSnapshot();
191+
});
174192
});
175193
});

Diff for: crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
: ^^^^^^
66
4 | export const foo = 1;
77
`----
8+
x `module` keyword is not supported. Use `namespace` instead.
9+
,-[7:1]
10+
6 |
11+
7 | module Foo { }
12+
: ^^^^^^
13+
8 | declare module Bar { }
14+
`----
15+
x `module` keyword is not supported. Use `namespace` instead.
16+
,-[8:1]
17+
7 | module Foo { }
18+
8 | declare module Bar { }
19+
: ^^^^^^
20+
`----
821
x TypeScript namespace declaration is not supported in strip-only mode
922
,-[3:1]
1023
2 |

Diff for: crates/swc_fast_ts_strip/tests/errors/ts-module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
module Foo {
44
export const foo = 1;
5-
}
5+
}
6+
7+
module Foo { }
8+
declare module Bar { }

0 commit comments

Comments
 (0)