Skip to content

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

Open
PaulHMason opened this issue Dec 14, 2018 · 5 comments
Open

Tagged Template Literals #56720

PaulHMason opened this issue Dec 14, 2018 · 5 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop

Comments

@PaulHMason
Copy link

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

@nandoflorestan
Copy link

nandoflorestan commented Sep 11, 2024

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:

@lrhn
Copy link
Member

lrhn commented Sep 12, 2024

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 js-interop.

@lrhn lrhn transferred this issue from dart-lang/language Sep 12, 2024
@lrhn lrhn added web-js-interop Issues that impact all js interop type-enhancement A request for a change that isn't a bug area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. labels Sep 12, 2024
@nandoflorestan
Copy link

nandoflorestan commented Sep 12, 2024

@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.

@lrhn
Copy link
Member

lrhn commented Sep 12, 2024

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.

@PaulHMason
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-enhancement A request for a change that isn't a bug web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

3 participants