Skip to content

Support tagged templates in ES5 and ES3 #2253

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

Closed
Alxandr opened this issue Mar 7, 2015 · 5 comments
Closed

Support tagged templates in ES5 and ES3 #2253

Alxandr opened this issue Mar 7, 2015 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@Alxandr
Copy link

Alxandr commented Mar 7, 2015

Tagged templates are fairly easy to implement using ES5 and ES3, you simply turn the following:

fn`Hello ${you}! You're looking ${adjective} today!`

into the following:

fn(["Hello ", "! You're looking ", " today!"], you, adjective);

(sample taken from http://updates.html5rocks.com/2015/01/ES6-Template-Strings)

@ivogabe
Copy link
Contributor

ivogabe commented Mar 7, 2015

That has already been implemented in #1589. Note that the first argument of the downlevel call should have a raw property. We ended up with the following code:

(_a = ["Hello ", "! You're looking ", " today!"], _a.raw = ["Hello ", "! You're looking ", " today!"], fn(_a, you, adjective));
var _a;

@Alxandr
Copy link
Author

Alxandr commented Mar 7, 2015

Oh, damn, github search by default only searched open issues :-/.

Babel does more or less the same thing, except it uses a generated helper (and also does some Object.freeze if the browser supports it). I just tested this on the playground on the typescriptlang website, but I guess it hasn't been released yet.

@filipstachura
Copy link

Incoming in 1.5 :)

@Alxandr
Copy link
Author

Alxandr commented Mar 7, 2015

Great. Thanks. Sorry for duplicate issue :).

@Alxandr Alxandr closed this as completed Mar 7, 2015
@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Mar 7, 2015
@DanielRosenwasser
Copy link
Member

No worries - as a note, we thought about Object.freeze but I guess we were leaning towards the extremes of either doing it as correctly as possible (with making a cache of template strings arrays) or as cleanly as possible with ES3 compat (the way it is currently slated for 1.5). I think that the way @ivogabe did it is clean, canonical, and understandable.

Just for documentation, the duplicate issue is #1590.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants