{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/ecma262/issues/943","repository_url":"https://api.github.com/repos/tc39/ecma262","labels_url":"https://api.github.com/repos/tc39/ecma262/issues/943/labels{/name}","comments_url":"https://api.github.com/repos/tc39/ecma262/issues/943/comments","events_url":"https://api.github.com/repos/tc39/ecma262/issues/943/events","html_url":"https://github.com/tc39/ecma262/issues/943","id":238690465,"number":943,"title":"ASI hazard in tagged templates (need [NoLT here]?)","user":{"login":"bswierczynski","id":2477607,"avatar_url":"https://avatars1.githubusercontent.com/u/2477607?v=3","gravatar_id":"","url":"https://api.github.com/users/bswierczynski","html_url":"https://github.com/bswierczynski","followers_url":"https://api.github.com/users/bswierczynski/followers","following_url":"https://api.github.com/users/bswierczynski/following{/other_user}","gists_url":"https://api.github.com/users/bswierczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/bswierczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bswierczynski/subscriptions","organizations_url":"https://api.github.com/users/bswierczynski/orgs","repos_url":"https://api.github.com/users/bswierczynski/repos","events_url":"https://api.github.com/users/bswierczynski/events{/privacy}","received_events_url":"https://api.github.com/users/bswierczynski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-06-26T22:45:07Z","updated_at":"2017-06-26T23:11:25Z","closed_at":null,"body":"A New Line before a TemplateLiteral does not trigger ASI if the template literal is preceded by a MemberExpression. \r\n\r\nThis allows for constructs that caused [some](https://twitter.com/seanparsons/status/879416928191873024) [confusion](https://twitter.com/rauschma/status/879129403292254216) on the web: semicolons were not inserted where some people expected them to be.\r\n\r\n**Example 1 (gotcha)**\r\n\r\n```\r\nlet some_ident = 42\r\nlet foo = 43 + some_ident // expecting ASI to add a semicolon here\r\n\r\n`id\r\nclassName\r\nsomeOtherAttrs`.forEach(attr => { /*do something */ })\r\n\r\n// Uncaught TypeError: some_ident is not a function\r\n```\r\n\r\n`some_ident`  from the previous line is treated as the template handler function for the template on the next line.\r\n\r\n\r\n**Example 2 (gotcha)**\r\nOr even when concatenating files, if the preceding one is wrapped in an IIFE:\r\n\r\n```\r\n// Previous file:\r\n(function() {\r\n  // ...\r\n})() // expecting ASI to add a semicolon here\r\n\r\n// Next file:\r\n`id\r\nclassName\r\nsomeOtherAttrs`.forEach(attr => { /* ... */ })\r\n\r\n// Uncaught TypeError: (intermediate value)(...) is not a function\r\n```\r\nThe IIFE's result is treated as the template handler for the template literal on the next line.\r\n\r\n\r\n**A rare hazard**\r\nThis makes only the third such ASI-hazard in the language. The other two can be avoided by never starting a line with a `(` or `[`. With tagged templates, ` has been added to that list.\r\n\r\nThis hazard was recognized by standard JS:\r\nhttps://www.npmjs.com/package/standard\r\n\r\n**Potential fix**\r\nMake `MemberExpression: MemberExpression TemplateLiteral` a restricted rule:\r\n```\r\nMemberExpression: MemberExpression [no LineTerminator here] TemplateLiteral\r\n```\r\nThis would make sure that ASI inserts semicolons before lines that start with a template literal.\r\n\r\n**Example 3 (Fix breaks compatibility)**\r\nThe problem is, adding `[NoLT here]` could break existing code that might be intentionally trying to use the following format:\r\n\r\n```\r\nlet h = SafeHTML\r\n`\r\n<h1>${foo}</h1>\r\n<p><${bar}</p>\r\n`\r\n```\r\n\r\nIs it to late for a change? Maybe. I don't have a strong personal opinion on this (I tend to use semicolons anyways), but since Brendan and AWB said this hasn't been discussed and [asked me to file a bug](https://twitter.com/awbjs/status/879459780804321281), here it is. Any insights?"},"comment":{"url":"https://api.github.com/repos/tc39/ecma262/issues/comments/311207217","html_url":"https://github.com/tc39/ecma262/issues/943#issuecomment-311207217","issue_url":"https://api.github.com/repos/tc39/ecma262/issues/943","id":311207217,"user":{"login":"bakkot","id":1653598,"avatar_url":"https://avatars1.githubusercontent.com/u/1653598?v=3","gravatar_id":"","url":"https://api.github.com/users/bakkot","html_url":"https://github.com/bakkot","followers_url":"https://api.github.com/users/bakkot/followers","following_url":"https://api.github.com/users/bakkot/following{/other_user}","gists_url":"https://api.github.com/users/bakkot/gists{/gist_id}","starred_url":"https://api.github.com/users/bakkot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bakkot/subscriptions","organizations_url":"https://api.github.com/users/bakkot/orgs","repos_url":"https://api.github.com/users/bakkot/repos","events_url":"https://api.github.com/users/bakkot/events{/privacy}","received_events_url":"https://api.github.com/users/bakkot/received_events","type":"User","site_admin":false},"created_at":"2017-06-26T23:11:24Z","updated_at":"2017-06-26T23:11:24Z","body":"> And \"/\"? You mean a regex literal being parsed as division?\r\n\r\nYes. It usually ends up as a syntax error, but it's still a hazard:\r\n\r\n```js\r\nx = 0\r\n/b/.test(y) && console.log('hit') // SyntaxError: unexpected token '.'\r\n```"}}
{"actor":{"display_login":"bakkot"}}