Fix embedded GraphQL in JS with backticks (#4265)
parent
f35d1c21d7
commit
2e73164b81
|
@ -77,7 +77,7 @@ function embed(path, print, textToDoc /*, options */) {
|
|||
const templateElement = node.quasis[i];
|
||||
const isFirst = i === 0;
|
||||
const isLast = i === numQuasis - 1;
|
||||
const text = templateElement.value.raw;
|
||||
const text = templateElement.value.cooked;
|
||||
const lines = text.split("\n");
|
||||
const numLines = lines.length;
|
||||
const expressionDoc = expressionDocs[i];
|
||||
|
@ -107,13 +107,17 @@ function embed(path, print, textToDoc /*, options */) {
|
|||
doc = docUtils.stripTrailingHardline(
|
||||
textToDoc(text, { parser: "graphql" })
|
||||
);
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
if (process.env.PRETTIER_DEBUG) {
|
||||
throw error;
|
||||
}
|
||||
// Bail if any part fails to parse.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (doc) {
|
||||
doc = escapeBackticks(doc);
|
||||
if (!isFirst && startsWithBlankLine) {
|
||||
parts.push("");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`backticks.js 1`] = `
|
||||
gql\`
|
||||
"\\\`foo\\\` mutation payload."
|
||||
type FooPayload {
|
||||
bar: String
|
||||
}
|
||||
\`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
gql\`
|
||||
"\\\`foo\\\` mutation payload."
|
||||
type FooPayload {
|
||||
bar: String
|
||||
}
|
||||
\`;
|
||||
|
||||
`;
|
||||
|
||||
exports[`expressions.js 1`] = `
|
||||
graphql(schema, \`
|
||||
query allPartsByManufacturerName($name: String!) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
gql`
|
||||
"\`foo\` mutation payload."
|
||||
type FooPayload {
|
||||
bar: String
|
||||
}
|
||||
`
|
Loading…
Reference in New Issue