Add test for comments in hookTypeAnnotation (#18631)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-01-15 03:35:07 +08:00
1 parent 4cfb8bc9b8
commit b0ffc1208d
3 files changed
+90

No files matched your search

+3
View File
@@ -108,6 +108,9 @@ const hermesDisabledTests = new Set([
// Not supported
"flow/comments",
"flow-repo/union_new",
// Different result
"flow/hook/comments-before-arrow.js",
].map((file) => path.join(__dirname, "../format", file)),
]);
const flowDisabledTests = new Set(
@@ -1,5 +1,67 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`comments-before-arrow.js format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
| printWidth
=====================================input======================================
/*
The following should format like \`ArrowFunctionExpression\`,
but currently the AST shape are different, and it allows line break before \`=>\`
This is valid
\`\`\`
type A1 = hook () /*
1 *\\/ => void
\`\`\`
while this is invalid
\`\`\`
a = () /*
1 *\\/ => void
\`\`\`
*/
type A1 = hook /* 11 */ () => void
type A2 = hook () /* 12 */ => void
type A3 = hook () => /* 13 */ void
a = /* 21 */ () => {}
a = () /* 22 */ => {}
a = () => /* 23 */ {}
=====================================output=====================================
/*
The following should format like \`ArrowFunctionExpression\`,
but currently the AST shape are different, and it allows line break before \`=>\`
This is valid
\`\`\`
type A1 = hook () /*
1 *\\/ => void
\`\`\`
while this is invalid
\`\`\`
a = () /*
1 *\\/ => void
\`\`\`
*/
type A1 = hook () => /* 11 */ void;
type A2 = hook () => /* 12 */ void;
type A3 = hook () => /* 13 */ void;
a = /* 21 */ () => {};
a = () /* 22 */ => {};
a = () => /* 23 */ {};
================================================================================
`;
exports[`dangling-comments.js format 1`] = `
====================================options=====================================
parsers: ["flow"]
@@ -0,0 +1,25 @@
/*
The following should format like `ArrowFunctionExpression`,
but currently the AST shape are different, and it allows line break before `=>`
This is valid
```
type A1 = hook () /*
1 *\/ => void
```
while this is invalid
```
a = () /*
1 *\/ => void
```
*/
type A1 = hook /* 11 */ () => void
type A2 = hook () /* 12 */ => void
type A3 = hook () => /* 13 */ void
a = /* 21 */ () => {}
a = () /* 22 */ => {}
a = () => /* 23 */ {}