GraphQL: Fix dangling comments in empty "listValue" (#19422)
This commit is contained in:
1 parent
9c0e48cd25
commit
7c39d9ba1e
5 files changed
+54
-6
No files matched your search
@@ -1,4 +1,4 @@
|
||||
#### Fix comment print (#18581 by @fisker)
|
||||
#### Fix crash with comment only object value (#18581 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```gql
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#### Fix crash with comment only list value (#19422 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```gql
|
||||
# Input
|
||||
query {
|
||||
a(x: [
|
||||
# only comment
|
||||
])
|
||||
}
|
||||
|
||||
# Prettier stable
|
||||
Error: Comment "only comment" was not printed. Please report this error!
|
||||
|
||||
# Prettier main
|
||||
query {
|
||||
a(
|
||||
x: [
|
||||
# only comment
|
||||
]
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -133,16 +133,21 @@ function genericPrint(path, options, print) {
|
||||
case "Variable":
|
||||
return ["$", print("name")];
|
||||
|
||||
case "ListValue":
|
||||
case "ListValue": {
|
||||
const isEmpty = !isNonEmptyArray(node.values);
|
||||
return group([
|
||||
"[",
|
||||
indent([
|
||||
softline,
|
||||
join([ifBreak("", ", "), softline], path.map(print, "values")),
|
||||
]),
|
||||
printDanglingComments(path, options, { indent: true }),
|
||||
isEmpty
|
||||
? ""
|
||||
: indent([
|
||||
softline,
|
||||
join([ifBreak("", ", "), softline], path.map(print, "values")),
|
||||
]),
|
||||
softline,
|
||||
"]",
|
||||
]);
|
||||
}
|
||||
|
||||
case "ObjectValue": {
|
||||
const isEmpty = !isNonEmptyArray(node.fields);
|
||||
|
||||
@@ -37,6 +37,12 @@ query {
|
||||
}
|
||||
}
|
||||
|
||||
query {
|
||||
a(x: [
|
||||
# only comment
|
||||
])
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
query {
|
||||
search(
|
||||
@@ -48,6 +54,14 @@ query {
|
||||
}
|
||||
}
|
||||
|
||||
query {
|
||||
a(
|
||||
x: [
|
||||
# only comment
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
|
||||
@@ -5,3 +5,9 @@ query {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
query {
|
||||
a(x: [
|
||||
# only comment
|
||||
])
|
||||
}
|
||||
Reference in new issue
Block a user