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

Implement Template Literals Revision proposal #4798

Closed
TimothyGu opened this Issue Oct 31, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@TimothyGu
Copy link
Contributor

TimothyGu commented Oct 31, 2016

The Template Literals Revision proposal reached Stage 3 in July, but is not yet implemented.

Input Code

Example derived from the proposal linked above.

function tag(strs) {
  assert(strs[0] === undefined);
  assert(strs.raw[0] === "\\unicode and \\u{55}");
}
tag`\unicode and \u{55}`;

Expected Behavior

The above code should execute without throwing any error.

Current Behavior

An error is currently thrown by Babylon:

repl: Bad character escape sequence (5:6)
  3 |   assert(strs.raw[0] === "\\unicode and \\u{55}");
  4 | }
> 5 | tag`\unicode and \u{55}`;
    |  

Possible Solution

First step would of course be adding support for it in Babylon.

Currently, the babel-plugin-transform-es2015-template-literals plugin transforms

tag`ab\\c`;

to

var _templateObject = _taggedTemplateLiteral(["ab\\c"], ["ab\\\\c"]);

function _taggedTemplateLiteral(strings, raw) {
  return Object.freeze(Object.defineProperties(strings, {
    raw: {
      value: Object.freeze(raw)
    }
  }));
}

tag(_templateObject);

To support this new syntax it could just convert

tag`\unicode and \u{55}`;

to

var _templateObject = _taggedTemplateLiteral([], ["\\unicode and \\u{55}"]);

function _taggedTemplateLiteral(strings, raw) {
  return Object.freeze(Object.defineProperties(strings, {
    raw: {
      value: Object.freeze(raw)
    }
  }));
}

tag(_templateObject);

@bakkot bakkot referenced this issue Jan 8, 2017

Open

Implementations #5

4 of 5 tasks complete
@bakkot

This comment has been minimized.

Copy link
Contributor

bakkot commented Jan 8, 2017

I'm interested in working on this. I expect I'll have a progress update or PR (at least to Babylon) within a week or so.

@hzoo

This comment has been minimized.

Copy link
Member

hzoo commented Jan 8, 2017

Alright cool @bakkot, can join our slack if you haven't already if you need help with contributing and the process, etc

@hzoo

This comment has been minimized.

Copy link
Member

hzoo commented Mar 22, 2017

Done in babel/babylon#274.

Updating Babel in #5522, need to add the transform tests/changes

@hzoo hzoo closed this Mar 22, 2017

@hzoo hzoo referenced this issue Mar 22, 2017

Merged

Update babylon #5522

@hzoo

This comment has been minimized.

Copy link
Member

hzoo commented Mar 22, 2017

Oops this is babel, not babylon, will close when we do the transform

@hzoo hzoo reopened this Mar 22, 2017

@hzoo hzoo added this to the Babel 7 milestone Mar 22, 2017

@hzoo hzoo referenced this issue Mar 22, 2017

Merged

Account for template literals revision #5523

2 of 2 tasks complete

@hzoo hzoo closed this in #5523 Mar 22, 2017

@lock lock bot added the outdated label May 4, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.