File tree 5 files changed +42
-12
lines changed
bindings/binding_typescript_wasm/__tests__
5 files changed +42
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ swc_core : patch
3
+ swc_fast_ts_strip : patch
4
+ ---
5
+
6
+ fix(ts/fast-strip): Throw object consistently
Original file line number Diff line number Diff line change @@ -166,21 +166,27 @@ exports[`transform in strip-only mode should throw an error when it encounters a
166
166
` ;
167
167
168
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.
169
+ {
170
+ " code" : " UnsupportedSyntax" ,
171
+ " message" : " x \` module\` keyword is not supported. Use \` namespace\` instead.
170
172
,----
171
173
1 | declare module foo { }
172
174
: ^^^^^^
173
175
\` ----
174
- "
176
+ ",
177
+ }
175
178
` ;
176
179
177
180
exports [` transform in transform mode should throw an error when it encounters a module 1` ] = `
178
- " x \` module\` keyword is not supported. Use \` namespace\` instead.
181
+ {
182
+ " code" : " UnsupportedSyntax" ,
183
+ " message" : " x \` module\` keyword is not supported. Use \` namespace\` instead.
179
184
,----
180
185
1 | module foo { }
181
186
: ^^^^^^
182
187
\` ----
183
- "
188
+ ",
189
+ }
184
190
` ;
185
191
186
192
exports [` transform should strip types 1` ] = `
Original file line number Diff line number Diff line change @@ -189,5 +189,16 @@ describe("transform", () => {
189
189
} ) ,
190
190
) . rejects . toMatchSnapshot ( ) ;
191
191
} ) ;
192
+
193
+ it ( 'shoud throw an object even with deprecatedTsModuleAsError = true' , async ( ) => {
194
+ await expect (
195
+ swc . transform ( "module F { export type x = number }" , {
196
+ mode : "transform" ,
197
+ deprecatedTsModuleAsError : true ,
198
+ } ) ,
199
+ ) . rejects . toMatchObject ( {
200
+ code : "UnsupportedSyntax" ,
201
+ } ) ;
202
+ } )
192
203
} ) ;
193
204
} ) ;
Original file line number Diff line number Diff line change @@ -255,6 +255,12 @@ pub fn operate(
255
255
src : & fm. src ,
256
256
tokens : & tokens,
257
257
} ) ;
258
+ if handler. has_errors ( ) {
259
+ return Err ( TsError {
260
+ message : "Unsupported syntax" . to_string ( ) ,
261
+ code : ErrorCode :: UnsupportedSyntax ,
262
+ } ) ;
263
+ }
258
264
}
259
265
260
266
// Strip typescript types
@@ -365,6 +371,12 @@ pub fn operate(
365
371
src : & fm. src ,
366
372
tokens : & tokens,
367
373
} ) ;
374
+ if handler. has_errors ( ) {
375
+ return Err ( TsError {
376
+ message : "Unsupported syntax" . to_string ( ) ,
377
+ code : ErrorCode :: UnsupportedSyntax ,
378
+ } ) ;
379
+ }
368
380
}
369
381
370
382
program. mutate ( & mut typescript:: typescript (
@@ -378,7 +390,9 @@ pub fn operate(
378
390
program. mutate ( & mut hygiene ( ) ) ;
379
391
380
392
program. mutate ( & mut fixer ( Some ( & comments) ) ) ;
381
- } ) ;
393
+
394
+ Ok ( ( ) )
395
+ } ) ?;
382
396
383
397
let mut src = std:: vec:: Vec :: new ( ) ;
384
398
let mut src_map_buf = if options. source_map {
Original file line number Diff line number Diff line change 18
18
8 | declare module Bar { }
19
19
: ^^^^^^
20
20
`----
21
- x TypeScript namespace declaration is not supported in strip-only mode
22
- ,-[3:1]
23
- 2 |
24
- 3 | ,-> module Foo {
25
- 4 | | export const foo = 1;
26
- 5 | `-> }
27
- `----
You can’t perform that action at this time.
0 commit comments