Range Formatter: Remove Program/File from valid Ancestor (#2248)
* Remove Program/File from valid Ancestor Fix edge range formatting entire file. * Fix lint with `yarn lint -- --fix` See https://travis-ci.org/prettier/prettier/jobs/246569943#L242-L260master
parent
811885d635
commit
b0413fc1fe
12
index.js
12
index.js
|
@ -104,7 +104,11 @@ function findSiblingAncestors(startNodeAndParents, endNodeAndParents) {
|
|||
let resultEndNode = endNodeAndParents.node;
|
||||
|
||||
for (const endParent of endNodeAndParents.parentNodes) {
|
||||
if (util.locStart(endParent) >= util.locStart(startNodeAndParents.node)) {
|
||||
if (
|
||||
endParent.type !== "Program" &&
|
||||
endParent.type !== "File" &&
|
||||
util.locStart(endParent) >= util.locStart(startNodeAndParents.node)
|
||||
) {
|
||||
resultEndNode = endParent;
|
||||
} else {
|
||||
break;
|
||||
|
@ -112,7 +116,11 @@ function findSiblingAncestors(startNodeAndParents, endNodeAndParents) {
|
|||
}
|
||||
|
||||
for (const startParent of startNodeAndParents.parentNodes) {
|
||||
if (util.locEnd(startParent) <= util.locEnd(endNodeAndParents.node)) {
|
||||
if (
|
||||
startParent.type !== "Program" &&
|
||||
startParent.type !== "File" &&
|
||||
util.locEnd(startParent) <= util.locEnd(endNodeAndParents.node)
|
||||
) {
|
||||
resultStartNode = startParent;
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -176,6 +176,46 @@ function ugly ( {a=1, b = 2 } ) {
|
|||
|
||||
`;
|
||||
|
||||
exports[`range-end.js 1`] = `
|
||||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
|
||||
|
||||
call(
|
||||
1, 2,3
|
||||
);~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
|
||||
|
||||
call(1, 2, 3);
|
||||
`;
|
||||
|
||||
exports[`range-start.js 1`] = `
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
|
||||
|
||||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
call(1, 2, 3);
|
||||
|
||||
|
||||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
|
||||
`;
|
||||
|
||||
exports[`try-catch.js 1`] = `
|
||||
try {}
|
||||
catch (err) {}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
||||
|
||||
<<<PRETTIER_RANGE_START>>>
|
||||
call(
|
||||
1, 2,3
|
||||
);<<<PRETTIER_RANGE_END>>>
|
|
@ -0,0 +1,9 @@
|
|||
<<<PRETTIER_RANGE_START>>>call(
|
||||
1, 2,3
|
||||
);
|
||||
<<<PRETTIER_RANGE_END>>>
|
||||
|
||||
// Unchanged
|
||||
call(
|
||||
1, 2,3
|
||||
);
|
Loading…
Reference in New Issue