@@ -37,6 +37,93 @@ describe('renderNode', () => {
3737 } )
3838} )
3939
40+ /**
41+ * Indentation format tests to prevent regression.
42+ *
43+ * Expected indentation pattern:
44+ * - Function body: 2 spaces
45+ * - Inside return (): 4 spaces (baseDepth + 1 = 2, so 2 * 2 = 4)
46+ * - Nested children: +2 spaces per level (6, 8, 10, ...)
47+ * - Props on multiple lines: +2 spaces from component tag
48+ */
49+ describe ( 'renderComponent indentation' , ( ) => {
50+ test ( 'single line JSX stays on same line as return' , ( ) => {
51+ const result = renderComponent ( 'Button' , '<Button />' , { } )
52+ expect ( result ) . toBe ( `export function Button() {
53+ return <Button />
54+ }` )
55+ } )
56+
57+ test ( 'multiline JSX has 4 spaces inside return ()' , ( ) => {
58+ const code = `<Box>
59+ <Text />
60+ </Box>`
61+ const result = renderComponent ( 'Card' , code , { } )
62+
63+ // Verify indentation pattern
64+ const lines = result . split ( '\n' )
65+ expect ( lines [ 2 ] ) . toBe ( ' <Box>' ) // 4 spaces
66+ expect ( lines [ 3 ] ) . toBe ( ' <Text />' ) // 6 spaces
67+ expect ( lines [ 4 ] ) . toBe ( ' </Box>' ) // 4 spaces
68+ } )
69+
70+ test ( 'deeply nested children increment by 2 spaces each level' , ( ) => {
71+ const code = `<VStack>
72+ <Flex>
73+ <Box>
74+ <Text />
75+ </Box>
76+ </Flex>
77+ </VStack>`
78+ const result = renderComponent ( 'DeepNested' , code , { } )
79+
80+ const lines = result . split ( '\n' )
81+ expect ( lines [ 2 ] ) . toBe ( ' <VStack>' ) // 4 spaces (level 1)
82+ expect ( lines [ 3 ] ) . toBe ( ' <Flex>' ) // 6 spaces (level 2)
83+ expect ( lines [ 4 ] ) . toBe ( ' <Box>' ) // 8 spaces (level 3)
84+ expect ( lines [ 5 ] ) . toBe ( ' <Text />' ) // 10 spaces (level 4)
85+ expect ( lines [ 6 ] ) . toBe ( ' </Box>' ) // 8 spaces
86+ expect ( lines [ 7 ] ) . toBe ( ' </Flex>' ) // 6 spaces
87+ expect ( lines [ 8 ] ) . toBe ( ' </VStack>' ) // 4 spaces
88+ } )
89+
90+ test ( 'multiline props are indented correctly' , ( ) => {
91+ // When renderNode produces multiline props (5+ props or complex values)
92+ const code = `<Center
93+ bg="red"
94+ color="white"
95+ p="10px"
96+ m="5px"
97+ w="100%"
98+ >
99+ <Text />
100+ </Center>`
101+ const result = renderComponent ( 'MultiProps' , code , { } )
102+
103+ const lines = result . split ( '\n' )
104+ expect ( lines [ 2 ] ) . toBe ( ' <Center' ) // 4 spaces
105+ expect ( lines [ 3 ] ) . toBe ( ' bg="red"' ) // 6 spaces (props)
106+ expect ( lines [ 9 ] ) . toBe ( ' <Text />' ) // 6 spaces (child)
107+ expect ( lines [ 10 ] ) . toBe ( ' </Center>' ) // 4 spaces
108+ } )
109+
110+ test ( 'component with variants maintains correct indentation' , ( ) => {
111+ const code = `<Button>
112+ <Text />
113+ </Button>`
114+ const result = renderComponent ( 'MyButton' , code , {
115+ variant : '"primary" | "secondary"' ,
116+ } )
117+
118+ expect ( result ) . toContain ( 'export interface MyButtonProps' )
119+ const lines = result . split ( '\n' )
120+ // Line 0-2: interface, Line 3: empty, Line 4-5: function + return, Line 6+: JSX
121+ expect ( lines [ 6 ] ) . toBe ( ' <Button>' ) // 4 spaces
122+ expect ( lines [ 7 ] ) . toBe ( ' <Text />' ) // 6 spaces
123+ expect ( lines [ 8 ] ) . toBe ( ' </Button>' ) // 4 spaces
124+ } )
125+ } )
126+
40127describe ( 'renderComponent' , ( ) => {
41128 test . each ( [
42129 {
0 commit comments