Skip to content

Commit

Permalink
Return original input when specified range is unformattable (prettier…
Browse files Browse the repository at this point in the history
…#2250)

* Add failing test for range-formatting whitespace

See prettier#2247 (comment)

* Return original input when specified range is unformattable

Fixes prettier#2247
  • Loading branch information
josephfrazier authored and vjeux committed Jun 24, 2017
1 parent b0413fc commit 4b955a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ function calculateRange(text, opts, ast) {
endNonWhitespace,
isSourceElement
);

if (!startNodeAndParents || !endNodeAndParents) {
return {
rangeStart: 0,
rangeEnd: 0
};
}

const siblingAncestors = findSiblingAncestors(
startNodeAndParents,
endNodeAndParents
Expand Down
7 changes: 7 additions & 0 deletions tests/range/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,11 @@ catch (err) {}
try {
} catch (err) {}
`;
exports[`whitespace.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`;
1 change: 1 addition & 0 deletions tests/range/whitespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<<PRETTIER_RANGE_START>>> <<<PRETTIER_RANGE_END>>>

0 comments on commit 4b955a1

Please sign in to comment.