Return original input when specified range is unformattable (#2250)

* Add failing test for range-formatting whitespace

See https://github.com/prettier/prettier/issues/2247#issue-238322065

* Return original input when specified range is unformattable

Fixes https://github.com/prettier/prettier/issues/2247
master
Joseph Frazier 2017-06-24 12:41:10 -04:00 committed by Christopher Chedeau
parent b0413fc1fe
commit 4b955a14c4
3 changed files with 16 additions and 0 deletions

View File

@ -219,6 +219,14 @@ function calculateRange(text, opts, ast) {
endNonWhitespace,
isSourceElement
);
if (!startNodeAndParents || !endNodeAndParents) {
return {
rangeStart: 0,
rangeEnd: 0
};
}
const siblingAncestors = findSiblingAncestors(
startNodeAndParents,
endNodeAndParents

View File

@ -223,4 +223,11 @@ catch (err) {}
try {
} catch (err) {}
`;
exports[`whitespace.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`;

View File

@ -0,0 +1 @@
<<<PRETTIER_RANGE_START>>> <<<PRETTIER_RANGE_END>>>