{"action":"created","issue":{"url":"https://api.github.com/repos/pugjs/pug/issues/2618","repository_url":"https://api.github.com/repos/pugjs/pug","labels_url":"https://api.github.com/repos/pugjs/pug/issues/2618/labels{/name}","comments_url":"https://api.github.com/repos/pugjs/pug/issues/2618/comments","events_url":"https://api.github.com/repos/pugjs/pug/issues/2618/events","html_url":"https://github.com/pugjs/pug/issues/2618","id":189341928,"number":2618,"title":"Node v4 with pug in strict mode","user":{"login":"Velenir","id":5121491,"avatar_url":"https://avatars.githubusercontent.com/u/5121491?v=3","gravatar_id":"","url":"https://api.github.com/users/Velenir","html_url":"https://github.com/Velenir","followers_url":"https://api.github.com/users/Velenir/followers","following_url":"https://api.github.com/users/Velenir/following{/other_user}","gists_url":"https://api.github.com/users/Velenir/gists{/gist_id}","starred_url":"https://api.github.com/users/Velenir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Velenir/subscriptions","organizations_url":"https://api.github.com/users/Velenir/orgs","repos_url":"https://api.github.com/users/Velenir/repos","events_url":"https://api.github.com/users/Velenir/events{/privacy}","received_events_url":"https://api.github.com/users/Velenir/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-15T09:36:09Z","updated_at":"2016-11-15T11:09:56Z","closed_at":null,"body":"When I try to compile a pug file, for example:\r\n\r\n```pug\r\n- let txt = \"World\";\r\n\r\np Hello #{txt}\r\n```\r\n\r\nin Node v4.6.2, it throws:\r\n```shell\r\nlet txt = \"World\";\r\n^^^\r\n\r\nSyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode\r\n```\r\n\r\nAdding `\"use strict\"` to pug file doesn't help.\r\n\r\n```pug\r\n- \"use strict\";\r\n- let txt = \"World\";\r\n\r\np Hello #{txt}\r\n```\r\n\r\nwhen passed through `pug.compileFile(...).toString()` in Node v>=6 produces:\r\n\r\n```javascript\r\n// indented for readability\r\nfunction template(locals) {\r\n\tvar pug_html = \"\", pug_mixins = {}, pug_interp;\r\n\tvar pug_debug_filename, pug_debug_line;\r\n\r\n\ttry {\r\n\t\tpug_debug_line = 1;\r\n\t\tpug_debug_filename = \"ttp.pug\";\r\n\t\t\"use strict\";\r\n\t\tpug_debug_line = 3;\r\n\t\tpug_debug_filename = \"ttp.pug\";\r\n\t\tlet txt = \"World\";\r\n\t\tpug_debug_line = 5;\r\n\t\tpug_debug_filename = \"ttp.pug\";\r\n\t\tpug_html = pug_html + \"\\u003Cp\\u003E\";\r\n\t\tpug_debug_line = 5;\r\n\t\tpug_debug_filename = \"ttp.pug\";\r\n\t\tpug_html = pug_html + \"Hello \";\r\n\t\tpug_debug_line = 5;\r\n\t\tpug_debug_filename = \"ttp.pug\";\r\n\t\tpug_html = pug_html + (pug.escape(null == (pug_interp = txt) ? \"\" : pug_interp)) + \"\\u003C\\u002Fp\\u003E\";\r\n\t} catch (err) {\r\n\t\tpug.rethrow(err, pug_debug_filename, pug_debug_line);\r\n\t}\r\n\t\r\n\treturn pug_html;\r\n}\r\n```\r\n\r\n`\"use strict\"` has effect only at the top of the function, therefore function template here isn't in strict mode and strictness can't actually be enforced through template code.\r\n\r\nEven this minimalistic example:\r\n\r\n```javascript\r\n\"use strict\";\r\n\r\nconst pug = require('pug');\r\nconst compiled = pug.compile(\"- 'use strict'; let h = 's';\");\r\n```\r\n\r\nthrows in Node v4:\r\n\r\n```shell\r\n'use strict'; let h = 's';} catch (err) {pug.rethrow(err, pug_debug_filename, pug_debug_line);};return pug_html;}\r\n              ^^^\r\n\r\nSyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode\r\n```\r\n\r\nIn newer Node versions `compiled.toString()` produces:\r\n\r\n```javascript\r\nfunction template(locals) {\r\n\tvar pug_html = \"\", pug_mixins = {}, pug_interp;\r\n\tvar pug_debug_filename, pug_debug_line;\r\n\r\n\ttry {\r\n\t\tpug_debug_line = 1;\r\n\t\t'use strict';\r\n\t\tlet h = 's';\r\n\t} catch (err) {\r\n\t\tpug.rethrow(err, pug_debug_filename, pug_debug_line);\r\n\t}\r\n\r\n\treturn pug_html;\r\n}\r\n```\r\n\r\nAs you can see it isn't possible to apply strict mode to entire pug files."},"comment":{"url":"https://api.github.com/repos/pugjs/pug/issues/comments/260613817","html_url":"https://github.com/pugjs/pug/issues/2618#issuecomment-260613817","issue_url":"https://api.github.com/repos/pugjs/pug/issues/2618","id":260613817,"user":{"login":"ForbesLindesay","id":1260646,"avatar_url":"https://avatars.githubusercontent.com/u/1260646?v=3","gravatar_id":"","url":"https://api.github.com/users/ForbesLindesay","html_url":"https://github.com/ForbesLindesay","followers_url":"https://api.github.com/users/ForbesLindesay/followers","following_url":"https://api.github.com/users/ForbesLindesay/following{/other_user}","gists_url":"https://api.github.com/users/ForbesLindesay/gists{/gist_id}","starred_url":"https://api.github.com/users/ForbesLindesay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ForbesLindesay/subscriptions","organizations_url":"https://api.github.com/users/ForbesLindesay/orgs","repos_url":"https://api.github.com/users/ForbesLindesay/repos","events_url":"https://api.github.com/users/ForbesLindesay/events{/privacy}","received_events_url":"https://api.github.com/users/ForbesLindesay/received_events","type":"User","site_admin":false},"created_at":"2016-11-15T11:09:56Z","updated_at":"2016-11-15T11:09:56Z","body":"I think we should probably consider enabling strict mode by default in the long run.  Not sure what process we should take though to make the transition smooth."}}
{"actor":{"display_login":"ForbesLindesay"}}