@@ -17,7 +17,25 @@ const nestingSyntaxClose = ']})`';
1717
1818const found = 'Found "[" but:' ;
1919
20- function insertLinesIntoArray ( {
20+ function extractIndentDoc ( {
21+ maybeIndentDoc,
22+ } : Readonly < {
23+ maybeIndentDoc : Doc | undefined ;
24+ } > ) : ReturnType < typeof doc . builders . indent > | undefined {
25+ if ( isDocCommand ( maybeIndentDoc ) && maybeIndentDoc . type === 'indent' ) {
26+ return maybeIndentDoc ;
27+ } else if ( Array . isArray ( maybeIndentDoc ) ) {
28+ const firstDoc = maybeIndentDoc [ 0 ] ;
29+
30+ if ( isDocCommand ( firstDoc ) && firstDoc . type === 'indent' ) {
31+ return firstDoc ;
32+ }
33+ }
34+
35+ return undefined ;
36+ }
37+
38+ export function insertLinesIntoArray ( {
2139 inputDoc,
2240 manualWrap,
2341 lineCounts,
@@ -95,20 +113,25 @@ function insertLinesIntoArray({
95113 parentDoc [ childIndex + 2 ] = maybeBreak . breakContents ;
96114 }
97115 const indentIndex = childIndex + 1 ;
98- const bracketSibling =
116+ const maybeBracketSibling =
99117 parentDoc [ indentIndex ] === ''
100118 ? parentDoc [ indentIndex + 1 ]
101119 : parentDoc [ indentIndex ] ;
120+ const bracketSibling = extractIndentDoc ( {
121+ maybeIndentDoc : maybeBracketSibling ,
122+ } ) ;
102123 if ( debug ) {
103124 console . info ( {
104125 bracketSibling,
105126 } ) ;
106127 }
107- if ( bracketSibling === ']' ) {
128+ if ( maybeBracketSibling === ']' ) {
108129 return false ;
109- } else if ( ! isDocCommand ( bracketSibling ) || bracketSibling . type !== 'indent' ) {
130+ } else if ( ! bracketSibling ) {
110131 throw new Error (
111- `${ found } its sibling was not an indent Doc.: ${ stringify ( bracketSibling ) } ` ,
132+ `${ found } its sibling was not an indent Doc.: ${ stringify (
133+ maybeBracketSibling ,
134+ ) } `,
112135 ) ;
113136 }
114137 const indentContents = bracketSibling . contents ;
0 commit comments