@@ -20,17 +20,25 @@ export function stripTypes(content: string): { content: string; sourceMap: Sourc
2020 walk ( ast as unknown as TSESTree . Node , null , {
2121 _ : ( node , context ) => {
2222 console . log ( node . type ) ;
23- if ( node . type . startsWith ( 'TS' ) && node . type !== 'TSAsExpression' ) {
23+ if (
24+ node . type . startsWith ( 'TS' ) &&
25+ ! [ 'TSAsExpression' , 'TSSatisfiesExpression' , 'TSNonNullExpression' ] . includes ( node . type )
26+ ) {
2427 const { start, end } = node as unknown as { start : number ; end : number } ;
2528 s . overwrite ( start , end , ' ' . repeat ( end - start ) ) ;
2629 } else {
2730 context . next ( ) ;
2831 }
2932 } ,
3033 TSAsExpression : ( node ) => {
31- const { end : start } = node . expression as unknown as { end : number ; start : number } ;
32- const { end } = node . typeAnnotation as unknown as { start : number ; end : number } ;
33- s . overwrite ( start , end , ' ' . repeat ( end - start ) ) ;
34+ handleTypeExpression ( node , s ) ;
35+ } ,
36+ TSSatisfiesExpression : ( node ) => {
37+ handleTypeExpression ( node , s ) ;
38+ } ,
39+ TSNonNullExpression : ( node ) => {
40+ const { end } = node as unknown as { start : number ; end : number } ;
41+ s . overwrite ( end - 1 , end , ' ' ) ;
3442 } ,
3543 ImportDeclaration : ( node , context ) => {
3644 if (
@@ -64,3 +72,15 @@ export function stripTypes(content: string): { content: string; sourceMap: Sourc
6472 } )
6573 } ;
6674}
75+
76+ function handleTypeExpression (
77+ node : {
78+ expression : unknown ;
79+ typeAnnotation : unknown ;
80+ } ,
81+ s : { overwrite : ( start : number , end : number , content : string ) => void }
82+ ) {
83+ const { end : start } = node . expression as unknown as { end : number ; start : number } ;
84+ const { end } = node . typeAnnotation as unknown as { start : number ; end : number } ;
85+ s . overwrite ( start , end , ' ' . repeat ( end - start ) ) ;
86+ }
0 commit comments