{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17956","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17956/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17956/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17956/events","html_url":"https://github.com/Microsoft/TypeScript/issues/17956","id":251797379,"number":17956,"title":"Tagged template literals compiled incorrectly, TemplateStringsArray not cached","user":{"login":"justinfagnani","id":522948,"avatar_url":"https://avatars0.githubusercontent.com/u/522948?v=4","gravatar_id":"","url":"https://api.github.com/users/justinfagnani","html_url":"https://github.com/justinfagnani","followers_url":"https://api.github.com/users/justinfagnani/followers","following_url":"https://api.github.com/users/justinfagnani/following{/other_user}","gists_url":"https://api.github.com/users/justinfagnani/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfagnani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfagnani/subscriptions","organizations_url":"https://api.github.com/users/justinfagnani/orgs","repos_url":"https://api.github.com/users/justinfagnani/repos","events_url":"https://api.github.com/users/justinfagnani/events{/privacy}","received_events_url":"https://api.github.com/users/justinfagnani/received_events","type":"User","site_admin":false},"labels":[{"id":113970366,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21","default":false},{"id":127212211,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/ES6","name":"ES6","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-21T23:29:08Z","updated_at":"2017-08-26T05:57:08Z","closed_at":null,"body":"\r\n**TypeScript Version:**  2.4.1\r\n\r\n**Code**\r\n\r\n```ts\r\nlet previousStrings;\r\n\r\nfunction test(strings, ...value) {\r\n  if (previousStrings !== undefined && previousStrings !== strings) {\r\n    window.alert('failure');\r\n  }\r\n  previousStrings = strings;\r\n}\r\n\r\nfunction go(n) {\r\n  return test`literal ${n}`;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nAccording to the ECMAScript spec, every time a template tag is evaluated, the _same_ strings object should be passed as the first argument:\r\n\r\n> Each TemplateLiteral in the program code of a realm is associated with a unique template object that is used in the evaluation of tagged Templates (12.2.9.6). The template objects are frozen and the same template object is used each time a specific tagged Template is evaluated.\r\n\r\nhttps://tc39.github.io/ecma262/#sec-gettemplateobject\r\n\r\n**Actual behavior:**\r\n\r\nThe above snippet compiles to:\r\n\r\n```ts\r\nvar previousStrings;\r\nfunction test(strings) {\r\n    var value = [];\r\n    for (var _i = 1; _i < arguments.length; _i++) {\r\n        value[_i - 1] = arguments[_i];\r\n    }\r\n    if (previousStrings !== undefined && previousStrings !== strings) {\r\n        window.alert('failure');\r\n    }\r\n    previousStrings = strings;\r\n}\r\nfunction go(n) {\r\n    return (_a = [\"literal \", \"\"], _a.raw = [\"literal \", \"\"], test(_a, n));\r\n    var _a;\r\n}\r\n```\r\n\r\nYou can see that `_a` is going to have a new identity for each call of go().\r\n\r\nFWIW, Babel compiles this correctly:\r\n\r\n```js\r\n'use strict';\r\n\r\nvar _templateObject = _taggedTemplateLiteral(['literal ', ''], ['literal ', '']);\r\n\r\nfunction _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }\r\n\r\nvar previousStrings = void 0;\r\n\r\nfunction test(strings) {\r\n  if (previousStrings !== undefined && previousStrings !== strings) {\r\n    window.alert('failure');\r\n  }\r\n  previousStrings = strings;\r\n}\r\n\r\nfunction go(n) {\r\n  return test(_templateObject, n);\r\n}\r\n```\r\n\r\nThis is breaking lit-html when used in TypeScript: https://github.com/PolymerLabs/lit-html/issues/58"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/325091004","html_url":"https://github.com/Microsoft/TypeScript/issues/17956#issuecomment-325091004","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17956","id":325091004,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars2.githubusercontent.com/u/972891?v=4","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2017-08-26T05:57:08Z","updated_at":"2017-08-26T05:57:08Z","body":"For now I'd rather wait on discussion on https://github.com/rwaldron/tc39-notes/blob/master/es8/2017-07/jul-27.md to get settled out first before we revisit the implementation."}}
{"actor":{"display_login":"DanielRosenwasser"}}