Fix TSMappedType comments (#4418)
parent
1a6cf3d071
commit
5776c8405a
|
@ -135,6 +135,13 @@ function handleRemainingComment(comment, text, options, ast, isLastComment) {
|
||||||
comment,
|
comment,
|
||||||
options
|
options
|
||||||
) ||
|
) ||
|
||||||
|
handleTSMappedTypeComments(
|
||||||
|
text,
|
||||||
|
enclosingNode,
|
||||||
|
precedingNode,
|
||||||
|
followingNode,
|
||||||
|
comment
|
||||||
|
) ||
|
||||||
handleBreakAndContinueStatementComments(enclosingNode, comment)
|
handleBreakAndContinueStatementComments(enclosingNode, comment)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -700,6 +707,38 @@ function handleVariableDeclaratorComments(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleTSMappedTypeComments(
|
||||||
|
text,
|
||||||
|
enclosingNode,
|
||||||
|
precedingNode,
|
||||||
|
followingNode,
|
||||||
|
comment
|
||||||
|
) {
|
||||||
|
if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
followingNode &&
|
||||||
|
followingNode.type === "TSTypeParameter" &&
|
||||||
|
followingNode.name
|
||||||
|
) {
|
||||||
|
addLeadingComment(followingNode.name, comment);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
precedingNode &&
|
||||||
|
precedingNode.type === "TSTypeParameter" &&
|
||||||
|
precedingNode.constraint
|
||||||
|
) {
|
||||||
|
addTrailingComment(precedingNode.constraint, comment);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function isBlockComment(comment) {
|
function isBlockComment(comment) {
|
||||||
return comment.type === "Block" || comment.type === "CommentBlock";
|
return comment.type === "Block" || comment.type === "CommentBlock";
|
||||||
}
|
}
|
||||||
|
|
|
@ -2559,10 +2559,11 @@ function printPathNoParens(path, options, print, args) {
|
||||||
case "TypeParameter": {
|
case "TypeParameter": {
|
||||||
const parent = path.getParentNode();
|
const parent = path.getParentNode();
|
||||||
if (parent.type === "TSMappedType") {
|
if (parent.type === "TSMappedType") {
|
||||||
parts.push(path.call(print, "name"));
|
parts.push("[", path.call(print, "name"));
|
||||||
if (n.constraint) {
|
if (n.constraint) {
|
||||||
parts.push(" in ", path.call(print, "constraint"));
|
parts.push(" in ", path.call(print, "constraint"));
|
||||||
}
|
}
|
||||||
|
parts.push("]");
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2788,9 +2789,7 @@ function printPathNoParens(path, options, print, args) {
|
||||||
])
|
])
|
||||||
: "",
|
: "",
|
||||||
printTypeScriptModifiers(path, options, print),
|
printTypeScriptModifiers(path, options, print),
|
||||||
"[",
|
|
||||||
path.call(print, "typeParameter"),
|
path.call(print, "typeParameter"),
|
||||||
"]",
|
|
||||||
n.questionToken
|
n.questionToken
|
||||||
? getTypeScriptMappedTypeModifier(n.questionToken, "?")
|
? getTypeScriptMappedTypeModifier(n.questionToken, "?")
|
||||||
: "",
|
: "",
|
||||||
|
|
|
@ -116,6 +116,55 @@ export type WrappedFormUtils = {
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`mapped_types.ts 1`] = `
|
||||||
|
type A = {
|
||||||
|
// commentA
|
||||||
|
[a in A]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type B = {
|
||||||
|
/* commentB */ [b in B]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type C = {
|
||||||
|
[/* commentC */ c in C]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type D = {
|
||||||
|
[d /* commentD */ in D]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type E = {
|
||||||
|
[e in /* commentE */ E]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type F = {
|
||||||
|
[f in F /* commentF */]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type G = {
|
||||||
|
[g in G] /* commentG */: string
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
type A = {
|
||||||
|
// commentA
|
||||||
|
[a in A]: string
|
||||||
|
};
|
||||||
|
|
||||||
|
type B = { /* commentB */ [b in B]: string };
|
||||||
|
|
||||||
|
type C = { [/* commentC */ c in C]: string };
|
||||||
|
|
||||||
|
type D = { [d /* commentD */ in D]: string };
|
||||||
|
|
||||||
|
type E = { [e in /* commentE */ E]: string };
|
||||||
|
|
||||||
|
type F = { [f in F /* commentF */]: string };
|
||||||
|
|
||||||
|
type G = { [g in G /* commentG */]: string };
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`methods.ts 1`] = `
|
exports[`methods.ts 1`] = `
|
||||||
export class Point {
|
export class Point {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
type A = {
|
||||||
|
// commentA
|
||||||
|
[a in A]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type B = {
|
||||||
|
/* commentB */ [b in B]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type C = {
|
||||||
|
[/* commentC */ c in C]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type D = {
|
||||||
|
[d /* commentD */ in D]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type E = {
|
||||||
|
[e in /* commentE */ E]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type F = {
|
||||||
|
[f in F /* commentF */]: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type G = {
|
||||||
|
[g in G] /* commentG */: string
|
||||||
|
}
|
Loading…
Reference in New Issue