3
3
// Should consolidate them here.
4
4
5
5
import { context } from './testlib' ;
6
- import {
7
- contextTsNodeUnderTest ,
8
- testsDirRequire ,
9
- } from './helpers' ;
6
+ import { contextTsNodeUnderTest , testsDirRequire } from './helpers' ;
10
7
import * as expect from 'expect' ;
11
8
12
9
const test = context ( contextTsNodeUnderTest ) ;
13
10
14
11
test . suite ( 'swc' , ( test ) => {
15
12
test ( 'verify that TS->SWC target mappings suppport all possible values from both TS and SWC' , async ( t ) => {
16
- const swcTranspiler = testsDirRequire ( 'ts-node/transpilers/swc-experimental' ) as typeof import ( '../transpilers/swc' ) ;
13
+ const swcTranspiler = testsDirRequire (
14
+ 'ts-node/transpilers/swc-experimental'
15
+ ) as typeof import ( '../transpilers/swc' ) ;
17
16
18
17
// Detect when mapping is missing any ts.ScriptTargets
19
18
const ts = testsDirRequire ( 'typescript' ) as typeof import ( 'typescript' ) ;
20
- for ( const key of Object . keys ( ts . ScriptTarget ) ) {
21
- if ( / ^ \d + $ / . test ( key ) ) continue ;
22
- if ( key === 'JSON' ) continue ;
23
- expect ( swcTranspiler . targetMapping . has ( ts . ScriptTarget [ key as any ] as any ) ) . toBe ( true ) ;
19
+ for ( const key of Object . keys ( ts . ScriptTarget ) ) {
20
+ if ( / ^ \d + $ / . test ( key ) ) continue ;
21
+ if ( key === 'JSON' ) continue ;
22
+ expect (
23
+ swcTranspiler . targetMapping . has ( ts . ScriptTarget [ key as any ] as any )
24
+ ) . toBe ( true ) ;
24
25
}
25
26
26
27
// Detect when mapping is missing any swc targets
27
28
// Assuming that tests/package.json declares @swc /core: latest
28
29
const swc = testsDirRequire ( '@swc/core' ) ;
29
30
let msg : string | undefined = undefined ;
30
31
try {
31
- swc . transformSync ( '' , { jsc : { target : 'invalid' } } ) ;
32
- } catch ( e ) {
32
+ swc . transformSync ( '' , { jsc : { target : 'invalid' } } ) ;
33
+ } catch ( e ) {
33
34
msg = ( e as Error ) . message ;
34
35
}
35
36
expect ( msg ) . toBeDefined ( ) ;
@@ -39,7 +40,7 @@ test.suite('swc', (test) => {
39
40
expect ( match ) . toBeDefined ( ) ;
40
41
const targets = match ! [ 1 ] . split ( ', ' ) . map ( ( v : string ) => v . slice ( 1 , - 1 ) ) ;
41
42
42
- for ( const target of targets ) {
43
+ for ( const target of targets ) {
43
44
expect ( [ ...swcTranspiler . targetMapping . values ( ) ] ) . toContain ( target ) ;
44
45
}
45
46
} ) ;
0 commit comments