1
1
import * as ts from 'typescript' ;
2
2
3
- function typescriptTransformUnspec < T extends ts . Node > ( program : ts . Program ) : ts . TransformerFactory < T > {
4
- return ( context : ts . TransformationContext ) => {
5
- const visit : ts . Visitor = ( node ) => {
6
- if ( isSpecExpressionStatement ( node ) ) {
7
- return undefined ;
8
- }
9
- return ts . visitEachChild ( node , ( child ) => visit ( child ) , context ) ;
10
- } ;
11
- return ( node ) => ts . visitNode ( node , visit ) ;
12
- } ;
3
+ function typescriptTransformUnspec ( program : ts . Program ) : ts . TransformerFactory < ts . SourceFile > {
4
+ return ( context ) => ( file ) => visitNodeAndChildren ( file , program , context ) ;
5
+ }
6
+
7
+ function visitNodeAndChildren ( node : ts . Node , program : ts . Program , context : ts . TransformationContext ) : ts . SourceFile {
8
+ return ts . visitEachChild ( visitNode ( node ) , ( childNode ) => visitNodeAndChildren ( childNode , program , context ) , context ) as ts . SourceFile ;
9
+ }
10
+
11
+ function visitNode ( node : ts . Node ) : ts . Node | undefined {
12
+ if ( isSpecExpressionStatement ( node ) ) {
13
+ return undefined ;
14
+ }
15
+ return node ;
13
16
}
14
17
15
18
function isSpecExpressionStatement ( node : ts . Node ) {
@@ -18,13 +21,5 @@ function isSpecExpressionStatement(node: ts.Node) {
18
21
&& node . expression . expression . escapedText === 'it' ) ;
19
22
}
20
23
21
- if ( typeof it !== 'function' ) {
22
- // @ts -ignore
23
- var it : any = ( ) => { } ;
24
- }
25
- it ( 'smoke' , ( ) => {
26
- expect ( typescriptTransformUnspec ) . toBeTruthy ( ) ;
27
- } ) ;
28
-
29
24
module . exports = typescriptTransformUnspec ;
30
25
module . exports . default = typescriptTransformUnspec ;
0 commit comments