-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Tagged Template Literals #56720
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
Comments
This is an extremely important feature missing from the JS interop in Dart, however no attention has ever been given to it in years. Basically, there is a class of JS functions that are currently impossible to call from Dart. It is impossible to consume from Dart a number of web frameworks and libraries that use tagged template literals. Does anyone know how to call the attention of someone at Google, such as Jacob Richman, to this issue? Jacob Richman is a Google dev who has talks about JS interop and in that talk he says to let him know about important missing features. The following issues are about adding a similar feature to the Dart language itself, which is a separate matter: |
Is the request here to give Dart a similar feature, or to have js-interop provide a way to invoke the JS functions intended as templates in a more convenient way? For the former, dart-lang/language#1497 and dart-lang/language#1988 already exists, so I'll assume the latter and move this to the SDK repo so it can be tagged as |
@lrhn Thank you. You did well, because reading the first message, it is clear this is about being able to call from Dart existing JS tagged template functions. This issue is about interop. There is no "more convenient way" involved. AFAIK there is currently no way to consume JS tagged template functions from Dart code. If there is, please enlighten us. |
Since template tags are just JS functions that get called with arguments derived from the following template string, you should be able to call those functions directly through interop. It's just not as convenient as doing it through a string template. Doing tag(["text 1", "text 2", "", "text 3"],
value1, value2, value3); doesn't have the same readability as tag"text 1${value1}text 2${value2}${value3}text 3"; but it means the same thing. |
It's been a while... My original request was also for Dart to support the same sort of "custom interpolation" that JavaScript tagged template literals allows. It opens up a bunch of useful scenarios around things like templating. |
More and more JavaScript libraries are using tagged template literals (lit-html and HyperHTML are becoming very popular). Interop with these libraries is a problem though because Dart doesn't support tagged template literals (just template literals).
For a description, see the tagged templates section in this article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates
The text was updated successfully, but these errors were encountered: