Fix embedded GraphQL in JS with backticks (#4265)

master
Lucas Duailibe 2018-04-05 17:52:09 -03:00 committed by GitHub
parent f35d1c21d7
commit 2e73164b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -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("");
}

View File

@ -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!) {

View File

@ -0,0 +1,6 @@
gql`
"\`foo\` mutation payload."
type FooPayload {
bar: String
}
`