Fix range of IfStatement (#18735)
This commit is contained in:
1 parent
4531e18f75
commit
2b6c9fe2e7
5 files changed
+20
-21
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
@import {Node} from "./types/estree.js";
|
||||
@import {Node, Comment} from "./types/estree.js";
|
||||
*/
|
||||
|
||||
const isIndex = (value) => Number.isInteger(value) && value >= 0;
|
||||
@@ -21,6 +21,10 @@ function locStart(node) {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
@param {Node | Comment} node
|
||||
@return {number}
|
||||
*/
|
||||
function locEnd(node) {
|
||||
if (node.type === "BreakStatement" || node.type === "ContinueStatement") {
|
||||
const start = locStart(node);
|
||||
@@ -35,6 +39,10 @@ function locEnd(node) {
|
||||
return locEnd(lastDeclaration);
|
||||
}
|
||||
|
||||
if (node.type === "IfStatement") {
|
||||
return locEnd(node.alternate ?? node.consequent);
|
||||
}
|
||||
|
||||
return locEndWithFullText(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,9 +168,8 @@ function isLineAfterElementEmpty({ node }, { originalText: text }) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentIdx = skipInlineComment(
|
||||
text,
|
||||
skipTrailingComment(text, currentIdx + 1),
|
||||
currentIdx = /** @type {number} */ (
|
||||
skipInlineComment(text, skipTrailingComment(text, currentIdx + 1))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import getTextWithoutComments from "./get-text-without-comments.js";
|
||||
|
||||
/**
|
||||
@param {CallOrNewExpression} callOrNewExpression
|
||||
@returns {number | void}
|
||||
@returns {number | undefined}
|
||||
*/
|
||||
function getCallOrNewExpressionClosingParenthesisIndex(
|
||||
callOrNewExpression,
|
||||
|
||||
@@ -24,10 +24,6 @@ const unstableTests = new Map(
|
||||
[
|
||||
["js/comments/dangling_array.js", (options) => options.semi === false],
|
||||
["js/comments/jsx.js", (options) => options.semi === false],
|
||||
[
|
||||
"js/comments/break-continue-statements-2.js",
|
||||
(options) => options.semi !== false,
|
||||
],
|
||||
["js/no-semi/comments.js", (options) => options.semi === false],
|
||||
["flow/no-semi/comments.js", (options) => options.semi === false],
|
||||
["js/ignore/semi/asi.js", (options) => options.semi === false],
|
||||
|
||||
@@ -1502,18 +1502,16 @@ for (;;) {
|
||||
=====================================output=====================================
|
||||
// https://github.com/prettier/prettier/issues/7126
|
||||
for (;;) {
|
||||
if (condition)
|
||||
continue
|
||||
if (condition) continue
|
||||
|
||||
// breaking comment
|
||||
// breaking comment
|
||||
;(possibleArray || []).sort()
|
||||
}
|
||||
|
||||
lbl: for (;;) {
|
||||
if (condition)
|
||||
continue lbl
|
||||
if (condition) continue lbl
|
||||
|
||||
// breaking comment
|
||||
// breaking comment
|
||||
;(possibleArray || []).sort()
|
||||
}
|
||||
|
||||
@@ -1600,18 +1598,16 @@ for (;;) {
|
||||
=====================================output=====================================
|
||||
// https://github.com/prettier/prettier/issues/7126
|
||||
for (;;) {
|
||||
if (condition)
|
||||
continue;
|
||||
if (condition) continue;
|
||||
|
||||
// breaking comment
|
||||
// breaking comment
|
||||
(possibleArray || []).sort();
|
||||
}
|
||||
|
||||
lbl: for (;;) {
|
||||
if (condition)
|
||||
continue lbl;
|
||||
if (condition) continue lbl;
|
||||
|
||||
// breaking comment
|
||||
// breaking comment
|
||||
(possibleArray || []).sort();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user