-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 tagged template literal escape hatch #4070
Comments
Another great upside of this solution is that the types are preserved (of the tagged template literal function) |
Hmm pretty hard to do it now with |
the thing is es6 tagged literal is completely untyped which is an unsafe feature. Why is hard to do with |
@bobzhang: Because if the template literal tag for instance is |
it is not beautiful but doable:
bq is a function, then you can bind Gatsby.graphql and pass it to Note es6 tagged template literal can do arbitrary things in the runtime, it is an unsafe feature |
This works too |
@bobzhang: it needs to be static for most purposes I need it for, so it can't be the result of a function call. The feature you alluded to earlier that in the future there might be a raw that takes parameters and inlines the function call would be a solution though. |
Isn't that true for all externals? There might be a way if tagged template literals are exposed within bucklescript without |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
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:
And then add something to the syntax to support the tagged string literal (or probably a better syntax variant to this):
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:
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.
The text was updated successfully, but these errors were encountered: