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/2247master
parent
b0413fc1fe
commit
4b955a14c4
8
index.js
8
index.js
|
@ -219,6 +219,14 @@ function calculateRange(text, opts, ast) {
|
|||
endNonWhitespace,
|
||||
isSourceElement
|
||||
);
|
||||
|
||||
if (!startNodeAndParents || !endNodeAndParents) {
|
||||
return {
|
||||
rangeStart: 0,
|
||||
rangeEnd: 0
|
||||
};
|
||||
}
|
||||
|
||||
const siblingAncestors = findSiblingAncestors(
|
||||
startNodeAndParents,
|
||||
endNodeAndParents
|
||||
|
|
|
@ -223,4 +223,11 @@ catch (err) {}
|
|||
try {
|
||||
} catch (err) {}
|
||||
|
||||
`;
|
||||
|
||||
exports[`whitespace.js 1`] = `
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<<<PRETTIER_RANGE_START>>> <<<PRETTIER_RANGE_END>>>
|
Loading…
Reference in New Issue