Open littledan opened 5 years ago
Something like template identifier = return_type (/* arguments... */);
where arguments correspond to expressions?
A couple missing things there:
AFAIK tagged template functions are just functions, so we may just need a way to define general global (or module level) functions.
You can make global functions by defining operations in a global interface. For modules, see https://github.com/heycam/webidl/issues/592 .
Is there something preventing you from just using the normal operations syntax for template tags?
@domenic Well, you'd need to take it in as an object
and use a bunch of ECMAScript operations to get the template object, right?
Wouldn't just ReturnType someTag(sequence<DOMString> parts, TypesInteropolated interpolated...)
work? Then you'd get two Infra lists, parts and interopolated, each of which have the correct Web IDL type.
Yeah, that could work for some things. Some additional things that would be nice to do in a template tag:
Slightly off-topic for webidl, but since you tagged me: I think the most interesting future direction is for JS to allow host-defined tags that are not identifiers so that the host can switch parsers for the template literal contents before evaluating any JS.
We're running out of syntactic space, but imagine that:
let title = (text) => #html`<h1>${text}</h1>`;
invoked the host-defined parser for #html
at parse time, and at eval time invoked the associated host-defined tag function, but instead of a template object as the first argument, the first argument is an object produced by the host-defined parser.
Possible place to follow up on this idea: https://github.com/littledan/proposal-reserved-decorator-like-syntax
The ES6 feature of tagged template strings has recently been catching on in JavaScript. We may want to add Web APIs which define template tags in the near future, e.g., for Trusted Types, to test literal-ness (cc @koto) or for a built-in version of something like the parsing part of lit-html (cc @justinfagnani).
Would it make sense to add support to WebIDL to add template tags? What would that look like?