Fix comments for method signature (#18287)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-11-19 13:04:32 +08:00
1 parent 5b30f909ce
commit 9f2fad7aa4
10 files changed
+85

No files matched your search

@@ -931,6 +931,7 @@ function handleVariableDeclaratorComments({
function handleTSFunctionTrailingComments({
comment,
enclosingNode,
precedingNode,
followingNode,
text,
}) {
@@ -939,6 +940,7 @@ function handleTSFunctionTrailingComments({
(enclosingNode?.type === "TSMethodSignature" ||
enclosingNode?.type === "TSDeclareFunction" ||
enclosingNode?.type === "TSAbstractMethodDefinition") &&
(!precedingNode || precedingNode !== enclosingNode.returnType) &&
getNextNonSpaceNonCommentCharacter(text, locEnd(comment)) === ";"
) {
addTrailingComment(enclosingNode, comment);
@@ -0,0 +1,23 @@
interface a {
bar():any /* bat */;
}
type b = {
bar():any /* bat */;
}
declare class c {
bar():any /* bat */;
}
// https://github.com/babel/babel/blob/c92c4919771105140015167f25f7bacac77c90d9/scripts/babel-plugin-bit-decorator/types.d.ts#L28-L37
export type BitDecorator<T> = BitDecoratorCall<T> & {
(assertMask: number): BitDecoratorCall<T>;
storage(
value: unknown,
context: ClassFieldDecoratorContext<T, number>
): void /*{
context.metadata.bitsStorage = context.access;
}*/;
};
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`18278.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
interface a {
bar():any /* bat */;
}
type b = {
bar():any /* bat */;
}
declare class c {
bar():any /* bat */;
}
// https://github.com/babel/babel/blob/c92c4919771105140015167f25f7bacac77c90d9/scripts/babel-plugin-bit-decorator/types.d.ts#L28-L37
export type BitDecorator<T> = BitDecoratorCall<T> & {
(assertMask: number): BitDecoratorCall<T>;
storage(
value: unknown,
context: ClassFieldDecoratorContext<T, number>
): void /*{
context.metadata.bitsStorage = context.access;
}*/;
};
=====================================output=====================================
interface a {
bar(): any /* bat */;
}
type b = {
bar(): any /* bat */;
};
declare class c {
bar(): any /* bat */;
}
// https://github.com/babel/babel/blob/c92c4919771105140015167f25f7bacac77c90d9/scripts/babel-plugin-bit-decorator/types.d.ts#L28-L37
export type BitDecorator<T> = BitDecoratorCall<T> & {
(assertMask: number): BitDecoratorCall<T>;
storage(
value: unknown,
context: ClassFieldDecoratorContext<T, number>,
): void /*{
context.metadata.bitsStorage = context.access;
}*/;
};
================================================================================
`;
@@ -0,0 +1 @@
runFormatTest(import.meta, ["typescript"]);