1- export const compact_c_style = (
2- content : string ,
3- should_strip_bodies : boolean
4- ) : string => {
1+ export const compact_c_style = ( content : string ) : string => {
52 // Split by newline to process line by line, handling both LF and CRLF
63 const lines = content . split ( / \r ? \n / )
74 const result : string [ ] = [ ]
@@ -76,7 +73,7 @@ export const compact_c_style = (
7673 }
7774
7875 // Handle Function Body Stripping
79- if ( should_strip_bodies && char == '{' ) {
76+ if ( char == '{' ) {
8077 if ( skip_body_depth > 0 ) {
8178 // Already skipping, just deepen the level
8279 skip_body_depth ++
@@ -86,8 +83,9 @@ export const compact_c_style = (
8683 } else {
8784 // Check if we should preserve this block (class, interface, etc.)
8885 // We look at last_code_buffer for keywords
86+ // We also want to preserve control flow (if, for, while, etc.)
8987 const is_keeper =
90- / ( ^ | \s ) ( c l a s s | i n t e r f a c e | e n u m | n a m e s p a c e | t y p e ) ( \s | $ ) / . test (
88+ / ( ^ | \s ) ( c l a s s | i n t e r f a c e | e n u m | n a m e s p a c e | t y p e | i f | e l s e | f o r | w h i l e | d o | s w i t c h | t r y | c a t c h | f i n a l l y ) ( \s | $ ) / . test (
9189 last_code_buffer
9290 )
9391 // Also preserve object literals (preceded by = or :)
@@ -96,8 +94,7 @@ export const compact_c_style = (
9694 if ( ! is_keeper && ! is_object_literal ) {
9795 // Start skipping
9896 skip_body_depth = 1
99- const indent = processed_line . match ( / ^ \s * / ) ?. [ 0 ] || ''
100- processed_line += `{\n${ indent } // ...\n${ indent } }`
97+ processed_line += `{\n// ...\n}`
10198 last_code_buffer += '{}'
10299 i ++
103100 continue
@@ -106,7 +103,7 @@ export const compact_c_style = (
106103 last_code_buffer = ''
107104 }
108105 }
109- } else if ( should_strip_bodies && char == '}' ) {
106+ } else if ( char == '}' ) {
110107 if ( skip_body_depth > 0 ) {
111108 skip_body_depth --
112109 last_code_buffer += char
0 commit comments