Skip to content

Commit cd9955f

Browse files
authored
Fix range format for function bodies (#13173)
1 parent b65cb6c commit cd9955f

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#### Fix range format for function bodies (#13173 by @thorn0)
2+
3+
<!-- prettier-ignore -->
4+
```jsx
5+
// Input
6+
let fn = (() => {
7+
return; //
8+
//^^^^^^^^^^ - range
9+
});
10+
11+
// Prettier stable
12+
let fn = (() => {
13+
return; //
14+
};);
15+
16+
// Prettier main
17+
let fn = (() => {
18+
return; //
19+
});
20+
```

src/main/range-util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ function findSiblingAncestors(
6464
} else {
6565
break;
6666
}
67+
if (resultStartNode === resultEndNode) {
68+
break;
69+
}
6770
}
6871

6972
return {

tests/format/js/range/__snapshots__/jsfmt.spec.js.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ rangeStart: 0
182182
================================================================================
183183
`;
184184

185+
exports[`function-body.js format 1`] = `
186+
====================================options=====================================
187+
parsers: ["babel", "flow", "typescript"]
188+
printWidth: 80
189+
rangeEnd: 33
190+
rangeStart: 20
191+
| | printWidth
192+
=====================================input======================================
193+
1 | let fn =a((x ) => {
194+
> 2 | quux (); //
195+
| ^^^^^^^^^^^^^
196+
3 | });
197+
4 |
198+
=====================================output=====================================
199+
let fn =a((x ) => {
200+
quux(); //
201+
});
202+
203+
================================================================================
204+
`;
205+
185206
exports[`function-declaration.js format 1`] = `
186207
====================================options=====================================
187208
parsers: ["babel", "flow", "typescript"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let fn =a((x ) => {
2+
<<<PRETTIER_RANGE_START>>> quux (); //<<<PRETTIER_RANGE_END>>>
3+
});

0 commit comments

Comments
 (0)