Skip to content

Tagged templates emit for ES3 & 5 #1590

Closed
@ivogabe

Description

@ivogabe

Currently tagged templates aren't supported when targeting ES3 or ES5. Tagged templates can be (partially) emitted like this:

foo(["A ", " B ", " C"], 1, 2);

The only difference with ES6 is (if I'm not mistaken) that the raw property on the first argument is missing. I think there are 3 solutions for this:

  1. Don't allow functions that take a TemplateStringsArray as first argument, only string[]
  2. Emit extra code (see below)
  3. If the function takes a string[] as first argument, emit as above, otherwise (also if first argument is any), emit as below.

Alternative javascript would be:

var __template;

foo((__template = ["A ", " B ", " C"], __template.raw = ["A ", " B ", " C"], __template), 1, 2);

I'd vote for 1, since the .raw property won't be used in most cases.

I've implemented basic functionality in #1589 (without a solution for the .raw property)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions