Skip to content

Commit 4bc72b0

Browse files
committed
[patch] fix a case where [] type accessors crashed the plugin
1 parent b2684ad commit 4bc72b0

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/printer/child-docs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function walkDoc(
1010
startDoc: Doc,
1111
/** Return something falsy to prevent walking of child docs */
1212
debug: boolean,
13+
/** If this returns something falsy, none of the current node's children will be walked. */
1314
callback: (
1415
currentDoc: Doc,
1516
parents: Parents[],

src/printer/insert-new-lines.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ function insertLinesIntoArray(
5050
console.info(stringify(parentDoc));
5151
}
5252
if (childIndex !== 0) {
53-
throw new Error(`${found} not at index 0 in its parent`);
53+
/**
54+
* This happens in some situations which we don't want to format in this plugin,
55+
* like in type accessors:
56+
*
57+
* ```typescript
58+
* type mockType = exampleObject['property'];
59+
* ```
60+
*/
61+
return true;
5462
}
5563

5664
const maybeBreak = parentDoc[childIndex + 2];

src/test/typescript-tests.mock.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ export const typescriptTests: MultilineArrayTest[] = [
3434
multilineArraysWrapThreshold: 0,
3535
},
3636
},
37+
{
38+
it: 'works with type accessors',
39+
code: `
40+
export function doThing(
41+
[
42+
data,
43+
]: Parameters<stuff['param']>,
44+
thing: string,
45+
) {}
46+
`,
47+
},
3748
{
3849
it: 'works even if filepath is undefined GitHub Issue #18 (thank you farmerpaul)',
3950
code: `

0 commit comments

Comments
 (0)