Skip to content

Commit

Permalink
Fix potential mismatch with the Relay compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed May 14, 2024
1 parent e14978c commit 9006daf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-tables-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-relay-lite": patch
---

Fix potential mismatch with the Relay compiler on multiple fragments
4 changes: 1 addition & 3 deletions src/graphql-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function print(ast: ASTNode): string {
return visit<string>(ast, {
Name: { leave: node => node.value },
Variable: { leave: node => '$' + node.name },
Document: { leave: node => join(node.definitions, '\n\n') + '\n' },
Document: { leave: node => join(node.definitions, '\n') + '\n' },
OperationDefinition: {
leave(node) {
const varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
Expand Down Expand Up @@ -212,14 +212,12 @@ function printString(str: string): string {
return `"${str.replace(escapedRegExp, escapedReplacer)}"`;
}

// eslint-disable-next-line no-control-regex
const escapedRegExp = /[\x00-\x1f\x22\x5c\x7f-\x9f]/g;

function escapedReplacer(str: string): string {
return escapeSequences[str.charCodeAt(0)];
}

// prettier-ignore
const escapeSequences = [
'\\u0000', '\\u0001', '\\u0002', '\\u0003', '\\u0004', '\\u0005', '\\u0006', '\\u0007',
'\\b', '\\t', '\\n', '\\u000B', '\\f', '\\r', '\\u000E', '\\u000F',
Expand Down

0 comments on commit 9006daf

Please sign in to comment.