@@ -35,7 +35,6 @@ import {Cursor, isScope, isTree, Tree} from "../../tree";
3535import { mapAsync } from "../../util" ;
3636import { produceAsync } from "../../visitor" ;
3737import { TabsAndIndentsStyle } from "../style" ;
38- import { findMarker } from "../../markers" ;
3938
4039type IndentKind = 'block' | 'continuation' | 'align' ;
4140type IndentContext = [ number , IndentKind ] ; // [indent, kind]
@@ -215,10 +214,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
215214
216215 private prefixContainsNewline ( tree : J ) : boolean {
217216 // Check if the element starts on a new line (only the last whitespace matters)
218- if ( tree . prefix && lastWhitespace ( tree . prefix ) . includes ( "\n" ) ) {
219- return true ;
220- }
221- return false ;
217+ return ! ! ( tree . prefix && lastWhitespace ( tree . prefix ) . includes ( "\n" ) ) ;
222218 }
223219
224220 private isJsxChildElement ( tree : J ) : boolean {
@@ -556,10 +552,6 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
556552 // Restore cursor
557553 this . cursor = this . cursor . parent ! ;
558554
559- // For tree types, ret IS the element (intersection type); check if undefined directly
560- if ( ret === undefined ) {
561- return undefined ;
562- }
563555 return ret ;
564556 }
565557
@@ -627,8 +619,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
627619 // PropertyAssignment wrapping a spread (for object spread like `...obj`)
628620 if ( element . kind === JS . Kind . PropertyAssignment ) {
629621 const propAssign = element as JS . PropertyAssignment ;
630- // For tree types, name IS the expression with padding mixed in
631- const nameElement = propAssign . name as unknown as J | undefined ;
622+ const nameElement = propAssign . name ;
632623 if ( nameElement ?. kind === JS . Kind . Spread ) {
633624 return true ;
634625 }
@@ -654,8 +645,6 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
654645 let anchorCursor : Cursor | undefined ;
655646 let anchorIndent = 0 ;
656647
657- const DEBUG = false ; // Set to true to enable debug logging
658-
659648 for ( let c = this . cursor . parent ; c ; c = c . parent ) {
660649 path . push ( c ) ;
661650 const v = c . value ;
@@ -665,7 +654,6 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
665654 if ( isJavaWithPrefix && ! anchorCursor ) {
666655 const ws = lastWhitespace ( v . prefix ) ;
667656 const idx = ws . lastIndexOf ( '\n' ) ;
668- if ( DEBUG ) console . log ( ` CHECK ${ v . kind } : prefix=${ JSON . stringify ( ws . substring ( 0 , 50 ) ) } hasNewline=${ idx !== - 1 } ` ) ;
669657 if ( idx !== - 1 ) {
670658 anchorCursor = c ;
671659 anchorIndent = ws . length - idx - 1 ;
@@ -684,18 +672,6 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
684672 if ( path . length === 0 ) return ;
685673 path . reverse ( ) ;
686674
687- if ( DEBUG ) {
688- console . log ( `PATH (raw): ${ path . map ( p => {
689- const v = p . value as any ;
690- const isRP = this . isRightPaddedWrapper ( v ) ;
691- const isLP = this . isLeftPaddedWrapper ( v ) ;
692- const isCont = v ?. kind === J . Kind . Container ;
693- const wrapper = isRP ? '[RP]' : isLP ? '[LP]' : isCont ? '[C]' : '' ;
694- return `${ v ?. kind || 'unknown' } ${ wrapper } ` ;
695- } ) . join ( ' -> ' ) } `) ;
696- console . log ( `ANCHOR: ${ anchorCursor ? ( anchorCursor . value as any ) ?. kind : 'none' } at indent ${ anchorIndent } ` ) ;
697- }
698-
699675 // Process ancestors from root to leaf
700676 for ( let i = 0 ; i < path . length ; i ++ ) {
701677 const c = path [ i ] ;
@@ -708,22 +684,21 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
708684 if ( c === anchorCursor && ! c . messages . has ( "indentContext" ) ) {
709685 const ctx : IndentContext = [ anchorIndent , 'align' ] ;
710686 c . messages . set ( "indentContext" , ctx ) ;
711- if ( DEBUG ) console . log ( `SET (anchor): ${ v . kind } -> [${ ctx [ 0 ] } , ${ ctx [ 1 ] } ]` ) ;
712687 continue ;
713688 }
714689
715690 // Handle wrapper types (RightPadded, LeftPadded, Container)
716691 // These need their context set up for proper indent propagation
717692 // Note: RightPadded<J> intersection types have the element's kind, not J.Kind.RightPadded
718693 // So we detect them by checking for padding.after property
719- if ( this . isRightPaddedWrapper ( v ) ) {
694+ if ( isRightPadded ( v ) ) {
720695 const savedCursor = this . cursor ;
721696 this . cursor = c ;
722697 this . preVisitRightPadded ( v ) ;
723698 this . cursor = savedCursor ;
724699 continue ;
725700 }
726- if ( this . isLeftPaddedWrapper ( v ) ) {
701+ if ( isLeftPadded ( v ) ) {
727702 const savedCursor = this . cursor ;
728703 this . cursor = c ;
729704 this . preVisitLeftPadded ( v ) ;
@@ -745,11 +720,6 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
745720 // Only set up context if not already set (e.g., by If->Block handling above)
746721 if ( ! c . messages . has ( "indentContext" ) ) {
747722 this . setupCursorMessagesForTree ( c , v ) ;
748- const ctx = c . messages . get ( "indentContext" ) as IndentContext ;
749- if ( DEBUG ) console . log ( `SET (computed): ${ v . kind } -> [${ ctx ?. [ 0 ] } , ${ ctx ?. [ 1 ] } ]` ) ;
750- } else {
751- const ctx = c . messages . get ( "indentContext" ) as IndentContext ;
752- if ( DEBUG ) console . log ( `SKIP (already set): ${ v . kind } -> [${ ctx ?. [ 0 ] } , ${ ctx ?. [ 1 ] } ]` ) ;
753723 }
754724 this . cursor = savedCursor ;
755725
@@ -763,7 +733,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
763733 if ( nextCursor !== anchorCursor ) {
764734 const nextValue = nextCursor . value ;
765735 // Check if next is a statement (J node, not a wrapper type)
766- if ( this . isActualJNode ( nextValue ) && ! this . isRightPaddedWrapper ( nextValue ) ) {
736+ if ( this . isActualJNode ( nextValue ) && ! isRightPadded ( nextValue ) ) {
767737 // This is a Block child without explicit RightPadded wrapper in cursor chain
768738 // Apply RightPadded-like context: add indent if statement has newline
769739 const blockContext = c . messages . get ( "indentContext" ) as IndentContext | undefined ;
@@ -776,10 +746,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
776746 // Create a synthetic cursor for the implied RightPadded context
777747 // and set the context for the statement directly
778748 nextCursor . messages . set ( "indentContext" , [ stmtIndent , 'align' ] as IndentContext ) ;
779- if ( DEBUG ) console . log ( `BLOCK->STMT: ${ ( nextValue as any ) . kind } hasNewline=${ hasNewline } -> [${ stmtIndent } , align]` ) ;
780749 }
781- } else {
782- if ( DEBUG ) console . log ( `BLOCK->ANCHOR: skipping (next is anchor)` ) ;
783750 }
784751 }
785752
@@ -790,16 +757,13 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
790757 if ( nextCursor !== anchorCursor ) {
791758 const nextValue = nextCursor . value ;
792759 // If thenPart is a Block and not wrapped in RightPadded in cursor chain
793- if ( this . isActualJNode ( nextValue ) && nextValue . kind === J . Kind . Block && ! this . isRightPaddedWrapper ( nextValue ) ) {
760+ if ( this . isActualJNode ( nextValue ) && nextValue . kind === J . Kind . Block && ! isRightPadded ( nextValue ) ) {
794761 const ifContext = c . messages . get ( "indentContext" ) as IndentContext | undefined ;
795762 const [ ifIndent ] = ifContext ?? [ 0 , 'continuation' ] ;
796763 // thenPart Block doesn't have newline in prefix (it's { after condition)
797764 // Keep same indent, use 'block' so children get proper indentation
798765 nextCursor . messages . set ( "indentContext" , [ ifIndent , 'block' ] as IndentContext ) ;
799- if ( DEBUG ) console . log ( `IF->BLOCK: ifIndent=${ ifIndent } -> [${ ifIndent } , block]` ) ;
800766 }
801- } else {
802- if ( DEBUG ) console . log ( `IF->ANCHOR: skipping (next is anchor)` ) ;
803767 }
804768 }
805769 }
@@ -808,15 +772,8 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
808772 private isActualJNode ( v : any ) : v is J {
809773 return isJava ( v ) &&
810774 v . kind !== J . Kind . Container &&
811- ! this . isRightPaddedWrapper ( v ) &&
812- ! this . isLeftPaddedWrapper ( v ) ;
775+ ! isRightPadded ( v ) &&
776+ ! isLeftPadded ( v ) ;
813777 }
814778
815- private isRightPaddedWrapper ( v : any ) : v is J . RightPadded < J > {
816- return isRightPadded ( v ) ;
817- }
818-
819- private isLeftPaddedWrapper ( v : any ) : v is J . LeftPadded < J > {
820- return isLeftPadded ( v ) ;
821- }
822779}
0 commit comments