Fix comments on right side of "assignment like" (#19456)
This commit is contained in:
1 parent
ebc995158b
commit
aa10aa4b1e
3 files changed
+24
-34
No files matched your search
@@ -26,6 +26,7 @@ import {
|
||||
isConditionalType,
|
||||
isIntersectionType,
|
||||
isMemberExpression,
|
||||
isTypeAlias,
|
||||
isUnionType,
|
||||
} from "../utilities/node-types.js";
|
||||
import { stripComments } from "../utilities/strip-comments.js";
|
||||
@@ -776,16 +777,19 @@ const isComplexExprNode = createTypeCheckFunction([
|
||||
/** @param {CommentContext} context */
|
||||
function handleAssignmentLikeComments(context) {
|
||||
const { comment, enclosingNode, followingNode, options, placement } = context;
|
||||
if (isAssignmentLikeNode(enclosingNode) && followingNode) {
|
||||
if (
|
||||
placement === "endOfLine" &&
|
||||
(isComplexExprNode(followingNode) || isBlockComment(comment))
|
||||
) {
|
||||
return addLeadingCommentToPossibleUnionType(followingNode, context);
|
||||
}
|
||||
if (
|
||||
isAssignmentLikeNode(enclosingNode) &&
|
||||
followingNode &&
|
||||
placement === "endOfLine" &&
|
||||
(isComplexExprNode(followingNode) || isBlockComment(comment))
|
||||
) {
|
||||
return addLeadingCommentToPossibleUnionType(followingNode, context);
|
||||
}
|
||||
|
||||
// @ts-expect-error -- Safe
|
||||
const leftSide = enclosingNode.id ?? enclosingNode.left;
|
||||
// Ideally, we should only check cases that the right side is a single-element union or intersection type
|
||||
// We already strip the wrapper, there is no way to know it, so we only check "type alias"
|
||||
if (isTypeAlias(enclosingNode) && followingNode) {
|
||||
const leftSide = enclosingNode.id;
|
||||
const equalsTokenIndex = stripComments(options).indexOf(
|
||||
"=",
|
||||
locEnd(leftSide),
|
||||
|
||||
@@ -19,8 +19,7 @@ if (true)
|
||||
if (true)
|
||||
if (true)
|
||||
if (true)
|
||||
longVariableName1 =
|
||||
// @ts-ignore
|
||||
longVariableName1 = // @ts-ignore
|
||||
(variable01 + veryLongVariableNameNumber2).method();
|
||||
|
||||
================================================================================
|
||||
@@ -35,8 +34,7 @@ const kochabCooieGameOnOboleUnweave = // ???
|
||||
rhubarbRhubarb(annularCooeedSplicesWalksWayWay);
|
||||
|
||||
=====================================output=====================================
|
||||
const kochabCooieGameOnOboleUnweave =
|
||||
// ???
|
||||
const kochabCooieGameOnOboleUnweave = // ???
|
||||
rhubarbRhubarb(annularCooeedSplicesWalksWayWay);
|
||||
|
||||
================================================================================
|
||||
@@ -123,8 +121,7 @@ f3 = (
|
||||
a = b, //comment
|
||||
) => {};
|
||||
|
||||
f4 =
|
||||
// Comment
|
||||
f4 = // Comment
|
||||
() => {};
|
||||
|
||||
f5 =
|
||||
@@ -152,8 +149,7 @@ let f3 = (
|
||||
a = b, //comment
|
||||
) => {};
|
||||
|
||||
let f4 =
|
||||
// Comment
|
||||
let f4 = // Comment
|
||||
() => {};
|
||||
|
||||
let f5 =
|
||||
@@ -185,12 +181,10 @@ const bifornCringerMoshedPerplexSawder = // !!!
|
||||
anodyneCondosMalateOverateRetinol;
|
||||
|
||||
=====================================output=====================================
|
||||
const kochabCooieGameOnOboleUnweave =
|
||||
// ???
|
||||
const kochabCooieGameOnOboleUnweave = // ???
|
||||
annularCooeedSplicesWalksWayWay;
|
||||
|
||||
const bifornCringerMoshedPerplexSawder =
|
||||
// !!!
|
||||
const bifornCringerMoshedPerplexSawder = // !!!
|
||||
glimseGlyphsHazardNoopsTieTie +
|
||||
averredBathersBoxroomBuggyNurl -
|
||||
anodyneCondosMalateOverateRetinol;
|
||||
@@ -434,14 +428,11 @@ fnString =
|
||||
"long" +
|
||||
"string";
|
||||
|
||||
fnString =
|
||||
// Comment0
|
||||
fnString = // Comment0
|
||||
// Comment1
|
||||
"some" + "long" + "string";
|
||||
|
||||
fnString =
|
||||
// Comment
|
||||
"some" + "long" + "string";
|
||||
fnString = "some" + "long" + "string"; // Comment
|
||||
|
||||
fnString =
|
||||
// Comment
|
||||
@@ -481,14 +472,11 @@ var fnString =
|
||||
"long" +
|
||||
"string";
|
||||
|
||||
var fnString =
|
||||
// Comment0
|
||||
var fnString = // Comment0
|
||||
// Comment1
|
||||
"some" + "long" + "string";
|
||||
|
||||
var fnString =
|
||||
// Comment
|
||||
"some" + "long" + "string";
|
||||
var fnString = "some" + "long" + "string"; // Comment
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -50,9 +50,7 @@ let a32 =
|
||||
/*
|
||||
commment */
|
||||
1;
|
||||
let a4 =
|
||||
// comment
|
||||
1;
|
||||
let a4 = 1; // comment
|
||||
let a42 =
|
||||
// comment
|
||||
1;
|
||||
|
||||
Reference in new issue
Block a user