Title: Root level for-loop's variables are transpiled to global variables · Issue #1631 · TypeScriptToLua/TypeScriptToLua · GitHub
Open Graph Title: Root level for-loop's variables are transpiled to global variables · Issue #1631 · TypeScriptToLua/TypeScriptToLua
X Title: Root level for-loop's variables are transpiled to global variables · Issue #1631 · TypeScriptToLua/TypeScriptToLua
Description: When for-loop is located at root level of the file, it's variables from initializer are global But when I add any level (empty brackets or a function) they're being local Example: // Uncomment brackets to make `val` local // { for (let v...
Open Graph Description: When for-loop is located at root level of the file, it's variables from initializer are global But when I add any level (empty brackets or a function) they're being local Example: // Uncomment brac...
X Description: When for-loop is located at root level of the file, it's variables from initializer are global But when I add any level (empty brackets or a function) they're being local Example: // Uncomm...
Opengraph URL: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1631
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Root level for-loop's variables are transpiled to global variables","articleBody":"When for-loop is located at root level of the file, it's variables from initializer are global\nBut when I add any level (empty brackets or a function) they're being local\n\n[Example](https://typescripttolua.github.io/play/#code/5.4/PTAEFUDsGMHsFt4FNIBdQCMBOBDaBrJVAZ1FVlHh0NAAMA3HAG1tCdmmYCgRQBvLqCGgAZrCygAFEyKhGTUAF5QABgDcc5qAA8oAEwaA1IfkBKUAAcsASzSSzawcKu3UkgOQAxcW1iwLoCgAJu6mXE5CvADKABawAK5MQZhIoJDWTAA0mPHotkFISMnW6C5opABEehURljZ2ZjxgAL5AA):\n\n```ts\n// Uncomment brackets to make `val` local\n// {\n for (let val = 0; val \u003c 2; ++val) print(val);\n print('For loop end')\n\n // Should be nil, but indeed it prints \"2\"\n print(val)\n// }\n```\n\n```lua\n--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]\ndo\n val = 0 -- here \"local\" keyword missing is\n while val \u003c 2 do\n print(val)\n val = val + 1\n end\nend\nprint(\"For loop end\")\nprint(val)\n```","author":{"url":"https://github.com/inklesspen1rus","@type":"Person","name":"inklesspen1rus"},"datePublished":"2025-05-09T13:58:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1631/TypeScriptToLua/issues/1631"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8d403fc3-998c-6b90-485c-34e1a760f8fb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E446:313CEF:8DEB4E9:C1E6FDA:6973C0CC |
| html-safe-nonce | 7a9344c13c5c9fcdeecf7aaaab3ed890fd1f229191d53942e28ef067b5508f71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDQ2OjMxM0NFRjo4REVCNEU5OkMxRTZGREE6Njk3M0MwQ0MiLCJ2aXNpdG9yX2lkIjoiOTA1NDgxMjI0MTc1MTQyNTIyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a4727fc31c60e740d88bf17ece0a9cd0c03c2c75c96b5f9468e837314b6bd0f |
| hovercard-subject-tag | issue:3052268655 |
| 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/_view_fragments/issues/show/TypeScriptToLua/TypeScriptToLua/1631/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9b010a39580b11bb46860a199bd214c76ac818cd97054179ce073acc3b1ab48d/TypeScriptToLua/TypeScriptToLua/issues/1631 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9b010a39580b11bb46860a199bd214c76ac818cd97054179ce073acc3b1ab48d/TypeScriptToLua/TypeScriptToLua/issues/1631 |
| og:image:alt | When for-loop is located at root level of the file, it's variables from initializer are global But when I add any level (empty brackets or a function) they're being local Example: // Uncomment brac... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | inklesspen1rus |
| hostname | github.com |
| expected-hostname | github.com |
| None | acb8c988baca9616cb18bcb596629b823688faa1ef21a000061fe3616b4e3605 |
| turbo-cache-control | no-preview |
| go-import | github.com/TypeScriptToLua/TypeScriptToLua git https://github.com/TypeScriptToLua/TypeScriptToLua.git |
| octolytics-dimension-user_id | 44121206 |
| octolytics-dimension-user_login | TypeScriptToLua |
| octolytics-dimension-repository_id | 115876595 |
| octolytics-dimension-repository_nwo | TypeScriptToLua/TypeScriptToLua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 115876595 |
| octolytics-dimension-repository_network_root_nwo | TypeScriptToLua/TypeScriptToLua |
| 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 | af4eb23c75c70abd61c0b216b767faf4c9a30817 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width