@@ -158,112 +158,6 @@ export function formatOutput(code: string): string {
158158 return lines . join ( "\n" ) ;
159159 } ) ( ) ;
160160
161- // Remove blank line between props destructure and the next statement.
162- // recast inserts a blank line after `const { ... } = props;` inside function bodies.
163- // We use a line-based approach to avoid matching inside string/template literals.
164- out = removeBlankLineAfterPropsDestructure ( out ) ;
165-
166161 // Normalize EOF: trim all trailing whitespace, then ensure a single trailing newline.
167162 return out . trimEnd ( ) + "\n" ;
168163}
169-
170- /**
171- * Remove blank lines after `} = props;` destructuring statements in function bodies.
172- * Uses line-by-line analysis to avoid modifying matching patterns inside
173- * string/template literals or comments.
174- */
175- function removeBlankLineAfterPropsDestructure ( code : string ) : string {
176- const lines = code . split ( "\n" ) ;
177- const result : string [ ] = [ ] ;
178- let inString = false ;
179- let stringChar = "" ;
180- let inBlockComment = false ;
181- let inTemplateLiteral = false ;
182-
183- for ( let i = 0 ; i < lines . length ; i ++ ) {
184- const line = lines [ i ] ?? "" ;
185-
186- // Track whether we're inside a multi-line string/comment context.
187- // If so, just pass the line through unchanged.
188- if ( inBlockComment ) {
189- result . push ( line ) ;
190- if ( line . includes ( "*/" ) ) {
191- inBlockComment = false ;
192- }
193- continue ;
194- }
195- if ( inTemplateLiteral ) {
196- result . push ( line ) ;
197- // Count unescaped backticks to detect end of template literal
198- for ( let c = 0 ; c < line . length ; c ++ ) {
199- if ( line [ c ] === "\\" ) {
200- c ++ ; // skip escaped char
201- } else if ( line [ c ] === "`" ) {
202- inTemplateLiteral = false ;
203- }
204- }
205- continue ;
206- }
207- if ( inString ) {
208- result . push ( line ) ;
209- // Multi-line strings (only template literals can truly span lines,
210- // but handle edge cases)
211- if ( line . includes ( stringChar ) ) {
212- inString = false ;
213- }
214- continue ;
215- }
216-
217- // Check if this line ends with ` } = props;` (the destructuring pattern)
218- // and the next line is blank — if so, skip the blank line.
219- const trimmed = line . trimEnd ( ) ;
220- if (
221- trimmed . endsWith ( "} = props;" ) &&
222- i + 1 < lines . length &&
223- ( lines [ i + 1 ] ?? "" ) . trim ( ) === ""
224- ) {
225- result . push ( line ) ;
226- i ++ ; // skip the blank line
227- continue ;
228- }
229-
230- result . push ( line ) ;
231-
232- // Update string/comment tracking for subsequent lines
233- // Simple heuristic: scan the line for unmatched quotes/comments
234- for ( let c = 0 ; c < line . length ; c ++ ) {
235- const ch = line [ c ] ;
236- if ( ch === "/" && line [ c + 1 ] === "/" ) {
237- break ; // rest of line is a comment
238- }
239- if ( ch === "/" && line [ c + 1 ] === "*" ) {
240- if ( ! line . includes ( "*/" , c + 2 ) ) {
241- inBlockComment = true ;
242- }
243- break ;
244- }
245- if ( ch === "\\" ) {
246- c ++ ; // skip escaped char
247- continue ;
248- }
249- if ( ch === "`" ) {
250- inTemplateLiteral = true ;
251- // Check if it closes on the same line
252- for ( let j = c + 1 ; j < line . length ; j ++ ) {
253- if ( line [ j ] === "\\" ) {
254- j ++ ;
255- } else if ( line [ j ] === "`" ) {
256- inTemplateLiteral = false ;
257- c = j ;
258- break ;
259- }
260- }
261- if ( inTemplateLiteral ) {
262- break ;
263- }
264- }
265- }
266- }
267-
268- return result . join ( "\n" ) ;
269- }
0 commit comments