Normalize GraphQL multi-line strings (#3632)
* Normalize GraphQL multi-line strings See discussion in https://github.com/prettier/prettier/pull/3605#discussion_r159120321 * splitmaster
parent
a627ca7b5d
commit
5356db0e69
|
@ -126,9 +126,13 @@ function genericPrint(path, options, print) {
|
|||
}
|
||||
case "StringValue": {
|
||||
if (n.block) {
|
||||
// It is not possible to distinguish between """\nabc\n""" and """abc"""
|
||||
// https://github.com/graphql/graphql-js/issues/1188
|
||||
return options.originalText.slice(util.locStart(n), util.locEnd(n));
|
||||
return concat([
|
||||
'"""',
|
||||
hardline,
|
||||
join(hardline, n.value.replace(/"""/g, "\\$&").split("\n")),
|
||||
hardline,
|
||||
'"""'
|
||||
]);
|
||||
}
|
||||
return concat(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
|
||||
}
|
||||
|
@ -274,6 +278,8 @@ function genericPrint(path, options, print) {
|
|||
|
||||
case "FieldDefinition": {
|
||||
return concat([
|
||||
path.call(print, "description"),
|
||||
n.description ? hardline : "",
|
||||
path.call(print, "name"),
|
||||
n.arguments.length > 0
|
||||
? group(
|
||||
|
|
|
@ -110,9 +110,12 @@ fragment frag on Friend {
|
|||
foo(
|
||||
size: $size
|
||||
bar: $b
|
||||
obj: { key: "value", block: """
|
||||
obj: {
|
||||
key: "value"
|
||||
block: """
|
||||
block string uses \\"""
|
||||
""" }
|
||||
"""
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,29 @@ abc
|
|||
type T {
|
||||
a: Int
|
||||
}
|
||||
|
||||
"""
|
||||
a
|
||||
b
|
||||
c
|
||||
"""
|
||||
type T { a: Int }
|
||||
|
||||
type Foo {
|
||||
"""
|
||||
This is a description
|
||||
of the \`one\` field.
|
||||
"""
|
||||
one: Type
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
query X($a: Int) @relay(meta: "{\\"lowPri\\": true}") {
|
||||
a
|
||||
}
|
||||
|
||||
"""abc"""
|
||||
"""
|
||||
abc
|
||||
"""
|
||||
type T {
|
||||
a: Int
|
||||
}
|
||||
|
@ -31,4 +48,21 @@ type T {
|
|||
a: Int
|
||||
}
|
||||
|
||||
"""
|
||||
a
|
||||
b
|
||||
c
|
||||
"""
|
||||
type T {
|
||||
a: Int
|
||||
}
|
||||
|
||||
type Foo {
|
||||
"""
|
||||
This is a description
|
||||
of the \`one\` field.
|
||||
"""
|
||||
one: Type
|
||||
}
|
||||
|
||||
`;
|
||||
|
|
|
@ -11,3 +11,18 @@ abc
|
|||
type T {
|
||||
a: Int
|
||||
}
|
||||
|
||||
"""
|
||||
a
|
||||
b
|
||||
c
|
||||
"""
|
||||
type T { a: Int }
|
||||
|
||||
type Foo {
|
||||
"""
|
||||
This is a description
|
||||
of the `one` field.
|
||||
"""
|
||||
one: Type
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue