Title: Issue · GitHub
Open Graph Title: Issue · lightscript/lightscript
X Title: Issue · lightscript/lightscript
Description: JavaScript, with cleaned-up syntax and a few conveniences. - Issue · lightscript/lightscript
Open Graph Description: JavaScript, with cleaned-up syntax and a few conveniences. - Issue · lightscript/lightscript
X Description: JavaScript, with cleaned-up syntax and a few conveniences. - Issue · lightscript/lightscript
Opengraph URL: https://github.com/lightscript/lightscript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[compiler] `IfExpression`s and `AssignmentExpression`s in loop bodies","articleBody":"## Problem\r\n`lightscript@0.5.9`:\r\n[Lscdiag](https://wcjohnson.github.io/lscdiag/?v=1\u0026s=eMOafVDDkU7DgzAMw7wVK0_CoMKVKV0pwrAOUMK_woAfYBMKwqnDm8KFwqVpSRzChMKow7rDrzjCg8KHPsONL8OnO8KfwqzCsyfDkcKab8KKHsKDwqgmw7HDlsKrMWFdw7dIwqpRwqQSw5Mfw7c_ZcOuw7JOchXDpsKuw5zDksODw6ZTwocoKsOyEcOnw6zCkmMSYcKIXmPDqmzDkMKiEsOtw5U1w5w8w68dQDt4wrBIYMOgCcOkwo7DoRHDssKEwqtVwpXDhgBfw4rDssOIwrTCoMKPwqhPw7_DolnDnsKwXizDuV_CjzbDoMOSVsKww612w4nDt05ww55oUhxSw698w7XCq8OMw6QhEwEtasOCw6ZlaDjCq8KLw5bCpsK7BsOXwprDrsO8woPCoR_CjUXDj8O5wq3DqcKOFMK0NyPDlXJdwq7Ct2LCnsOZa00gw552w6EXwod5w74FwqnDhW3Dsg#)\r\n```js\r\nf() -\u003e\r\n for let i = 0; i \u003c 10; i++:\r\n val = if check:\r\n val2 = 3\r\n val2\r\n else:\r\n val3 = 4\r\n val3\r\n```\r\ncompiles to\r\n```js\r\nfunction f() {\r\n for (let i = 0; i \u003c 10; i++) {\r\n const val = check ? function () {\r\n var _ret;\r\n\r\n const val2 = 3;\r\n _ret = val2;\r\n return _ret;\r\n }() : function () {\r\n const val3 = 4;\r\n return _ret = val3;\r\n }();\r\n }\r\n}\r\n```\r\n\r\nThe generated `_ret` var is not in scope in the second `function` block, so this code will crash with a no-undef error if `check` is false. However, it's a mystery to me why that `_ret` var is being generated at all.\r\n\r\nIf the enclosing `for` loop is removed, the problem goes away: [lscdiag](https://wcjohnson.github.io/lscdiag/?v=1\u0026s=eMOafU_DkU7DgzAMw7zClcOITyDClcKpWynCsErCoH7DgX7CgE0owqRuZ3DDky5xEMKiw4rCv8KTw6zCpW_Ds8KLw69OJ8O7bsKBwp5-JTjDtMOQLMOwMcOqOcOvwrYdUXTCp0VnZsK-wp7Dv8Oqwq3DnQ5lwprCisKew6rCvcK8w6wuw4YHaMOEBcKMw4Utw4cCfgrDjmBGw6wNNMOQw5_DncKrwofCt8KjVcOqR8KzelXDlCtzRsOzw51kw6kqw67CklrCrSwjZMKPwqvCoUrChsOHwpUdLcKkEMKBw7IPw5HCn8Kpw4p7WcKUwqcCPDIaw4HDrjB1KcKADcOMOcOsZHsawq7DhcKmcSZGwpdCMQ1nw7HDhsORLG3CucKpN3vCiDF5wpnCvMKkazcKwp5iw7wHwp_Dr2TCkQ)\r\n","author":{"url":"https://github.com/wcjohnson","@type":"Person","name":"wcjohnson"},"datePublished":"2017-09-24T21:02:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/47/lightscript/issues/47"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:e3ac0ac1-fc46-ba7c-00d8-181f7ecbe82e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFD2:12B1F0:E585F9:1509AC4:6A4E31D4 |
| html-safe-nonce | dee57c7165b36ab0fd6cbca43968f71caddc18fdb50dc392399d01e38e4e00a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkQyOjEyQjFGMDpFNTg1Rjk6MTUwOUFDNDo2QTRFMzFENCIsInZpc2l0b3JfaWQiOiI1Mjg5MTczOTkzOTc4MjEyODIwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4bdcd18e0f826ad2f21d254df72fe58619b429afe22d441bab06a9f8404cba4f |
| hovercard-subject-tag | repository:63191213 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/lightscript/lightscript/issues/47 |
| twitter:image | https://opengraph.githubassets.com/4c89904e5df713c7f3f45a6b3858b0a7b1973cf8d9b862c9f979cf9393158b4e/lightscript/lightscript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c89904e5df713c7f3f45a6b3858b0a7b1973cf8d9b862c9f979cf9393158b4e/lightscript/lightscript |
| og:image:alt | JavaScript, with cleaned-up syntax and a few conveniences. - Issue · lightscript/lightscript |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-cache |
| go-import | github.com/lightscript/lightscript git https://github.com/lightscript/lightscript.git |
| octolytics-dimension-user_id | 20427295 |
| octolytics-dimension-user_login | lightscript |
| octolytics-dimension-repository_id | 63191213 |
| octolytics-dimension-repository_nwo | lightscript/lightscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63191213 |
| octolytics-dimension-repository_network_root_nwo | lightscript/lightscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 42a6d378d7587a44c93aca255096cd66b7c8eb2d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width