Description
Some modern libraries rely on the tagged template literal (styled components, graphql libraries), and it is often necessary to use the tagged template literal to have good interop with these libraries.
My specific use-case at the moment is Gatsby. It's a static site generator, and it uses babel plugins to extract graphql queries and pre-render them. I think I am pretty far with getting this to work with the [%bs.raw] extension and a PPX, but it's a hack and not sure if my attempt will be successful.
Many libraries require the tagged template literal do do fancy compiler stuff. There are some Apollo utilities that extract all the queries in the source code into a manifest which can be used for several things. All of that is not possible when using Bucklescript 😢.
It would be great to have an escape hatch for this to allow the interop.
Option A:
Compile the current interpolation to the ES6 string literal:
{j|你好,$world|j} => `你好,${world}`
And then add something to the syntax to support the tagged string literal (or probably a better syntax variant to this):
{graphql|你好,$world|graphql} => graphql`你好,${world}`
The nice thing is that the functionality of the default interpolation will be the same, and the old transformation can be used for es5, but adds the tagged template literal functionality when on es6.
Option B:
An extension:
[%tagged_template_literal]
external graphql: (string) => parsedGraphql = "graphql"
The downside is that this removes the tagged
(interpolation) part of the template literal, so it would not be great for things like styled components.
I guess with ES6 now pretty well supported in most browsers it would be good timing to encourage users of Bucklescript to use the ES6 target as the default.