Skip to content

Escape not just backticks but ${ as well in graphql tags#5137

Merged
lydell merged 2 commits intoprettier:masterfrom
lydell:fix-template-escaping
Sep 29, 2018
Merged

Escape not just backticks but ${ as well in graphql tags#5137
lydell merged 2 commits intoprettier:masterfrom
lydell:fix-template-escaping

Conversation

@lydell
Copy link
Copy Markdown
Member

@lydell lydell commented Sep 23, 2018

Fixes #4974.

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • I’ve read the contributing guidelines.

"Pattern: \\\`\\\${project}\\\`"
pattern: String
# Or escaping the first and second parentheses...
"Pattern: \\\`\\\${project}\\\`"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original escaping here is lost, but that’s another issue.

@lydell
Copy link
Copy Markdown
Member Author

lydell commented Sep 24, 2018

Still seems to fail somehow :(

Prettier pr-5137
Playground link

--parser babylon

Input:

gql`
query {
a(c: "a \\ b ") {
b
}
}
`

Output:

SyntaxError: Syntax Error: Invalid character escape sequence: \ . (3:10)
  1 | 
  2 | query {
> 3 | a(c: "a \ b ") {
    |          ^
  4 | b
  5 | }
  6 | }

EDIT: No, I'm just confused. The above is supposed to fail. Here's what I meant:

Prettier pr-5137
Playground link

--parser babylon

Input:

gql`
query {
a(c: "a \\\\ b ") {
b
}
}
`

Output:

gql`
  query {
    a(c: "a \\\\ b ") {
      b
    }
  }
`;

I'm starting to hate escaping.

@lydell lydell merged commit 87e109f into prettier:master Sep 29, 2018
@lydell lydell deleted the fix-template-escaping branch September 29, 2018 07:42
@ikatyang ikatyang added this to the 1.15 milestone Oct 25, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 23, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants