Fix hasFlowShorthandAnnotationComment check (#5497)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
2e596e33b7
commit
9f9677e6b7
2 files changed
+18
-1
No files matched your search
@@ -54,7 +54,7 @@ function hasFlowShorthandAnnotationComment(node) {
|
||||
return (
|
||||
node.extra &&
|
||||
node.extra.parenthesized &&
|
||||
node.trailingComments &&
|
||||
isNonEmptyArray(node.trailingComments) &&
|
||||
isBlockComment(node.trailingComments[0]) &&
|
||||
FLOW_SHORTHAND_ANNOTATION.test(node.trailingComments[0].value)
|
||||
);
|
||||
|
||||
@@ -29,6 +29,23 @@ test("allows usage of prettier's supported parsers", () => {
|
||||
expect(output).toEqual("bar();\n");
|
||||
});
|
||||
|
||||
test("allows add empty `trailingComments` array", () => {
|
||||
const output = prettier.format("(foo /* comment */)( )", {
|
||||
parser(text, parsers) {
|
||||
const ast = parsers.babel(text);
|
||||
|
||||
// This may happens in this use case https://github.com/prettier/prettier/pull/5497#issuecomment-439841965
|
||||
// Simply simulate it
|
||||
const callExpression = ast.program.body[0].expression;
|
||||
callExpression.extra = { parenthesized: true };
|
||||
callExpression.trailingComments = [];
|
||||
|
||||
return ast;
|
||||
},
|
||||
});
|
||||
expect(output).toEqual("foo(/* comment */);\n");
|
||||
});
|
||||
|
||||
describe("allows passing a string to resolve a parser", () => {
|
||||
runPrettier("./custom-parsers/", [
|
||||
"--end-of-line",
|
||||
|
||||
Reference in new issue
Block a user