11import * as ts from 'typescript' ;
22
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 ;
1316}
1417
1518function isSpecExpressionStatement ( node : ts . Node ) {
@@ -18,13 +21,5 @@ function isSpecExpressionStatement(node: ts.Node) {
1821 && node . expression . expression . escapedText === 'it' ) ;
1922}
2023
21- if ( typeof it !== 'function' ) {
22- // @ts -ignore
23- var it : any = ( ) => { } ;
24- }
25- it ( 'smoke' , ( ) => {
26- expect ( typescriptTransformUnspec ) . toBeTruthy ( ) ;
27- } ) ;
28-
2924module . exports = typescriptTransformUnspec ;
3025module . exports . default = typescriptTransformUnspec ;
0 commit comments