Skip to content

Unnecessary escaping of tagged template literal output #7196

Closed
@cknitt

Description

@cknitt

I was recently starting to modernize an old Gatsby project and moving more stuff to ReScript there. Gatsby uses graphql queries to fetch the content to render.

The following ReScript code

type graphqlQuery

@module("gatsby") @taggedTemplate
external graphql: (array<string>, array<string>) => graphqlQuery = "graphql"

let query = graphql`
  query LayoutQuery {
    tags: allMarkdownRemark {
      edges {
        node {
          frontmatter {
            tags
          }
        }
      }
    }
    recentPosts: allMarkdownRemark(
      filter: {frontmatter: {layout: {eq: "post"}}}
      sort: {frontmatter: {date: DESC}}
      limit: 4
    ) {
      edges {
        node {
          id
          fields {
            slug
          }
          frontmatter {
            title
            date(formatString: "YYYY-MM-DD")
            tags
          }
        }
      }
    }
  }
`

produced this output:

import * as Gatsby from "gatsby";

var query = Gatsby.graphql`\n  query LayoutQuery {\n    tags: allMarkdownRemark {\n      edges {\n        node {\n          frontmatter {\n            tags\n          }\n        }\n      }\n    }\n    recentPosts: allMarkdownRemark(\n      filter: {frontmatter: {layout: {eq: \"post\"}}}\n      sort: {frontmatter: {date: DESC}}\n      limit: 4\n    ) {\n      edges {\n        node {\n          id\n          fields {\n            slug\n          }\n          frontmatter {\n            title\n            date(formatString: \"YYYY-MM-DD\")\n            tags\n          }\n        }\n      }\n    }\n  }\n`;

which Gatsby didn't like at all:

Syntax Error: Unexpected character: "\".

I think we should emit the string for the template literal exactly as defined in the ReScript code, i.e., without escaping.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions