fix(multiparser): no additional trailing newline for graphql in js (#4616)

Fixes #4615

The root cause is the output doc from graphql printer does not match the desired input from `stripTrailingHardline`.

a9b21a01e2/src/doc/doc-utils.js (L167-L180)
master
Ika 2018-06-01 00:38:39 +08:00 committed by GitHub
parent e74e6565b4
commit b55997eb3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 6 deletions

View File

@ -28,15 +28,16 @@ function genericPrint(path, options, print) {
const parts = [];
path.map((pathChild, index) => {
parts.push(concat([pathChild.call(print)]));
parts.push(hardline);
if (
index !== n.definitions.length - 1 &&
isNextLineEmpty(options.originalText, pathChild.getValue(), options)
) {
if (index !== n.definitions.length - 1) {
parts.push(hardline);
if (
isNextLineEmpty(options.originalText, pathChild.getValue(), options)
) {
parts.push(hardline);
}
}
}, "definitions");
return concat(parts, hardline);
return concat([concat(parts), hardline]);
}
case "OperationDefinition": {
const hasOperation = options.originalText[options.locStart(n)] !== "{";

View File

@ -40,6 +40,29 @@ const query = /* GraphQL */ \`
`;
exports[`definitions.js 1`] = `
graphql\`
fragment x on y {
z
}
fragment a on b {
c
}
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
graphql\`
fragment x on y {
z
}
fragment a on b {
c
}
\`;
`;
exports[`expressions.js 1`] = `
graphql(schema, \`
query allPartsByManufacturerName($name: String!) {

View File

@ -0,0 +1,9 @@
graphql`
fragment x on y {
z
}
fragment a on b {
c
}
`;