{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/57753290","id":57753290,"diff_hunk":"@@ -10,6 +10,133 @@ namespace ts {\n         /** Enables substitutions for block-scoped bindings. */\r\n         BlockScopedBindings = 1 << 1,\r\n     }\r\n+    /**\r\n+     * If loop contains block scoped binding captured in some function then loop body is converted to a function.\r\n+     * Lexical bindings declared in loop initializer will be passed into the loop body function as parameters,\r\n+     * however if this binding is modified inside the body - this new value should be propagated back to the original binding.\r\n+     * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body.\r\n+     * On every iteration this variable is initialized with value of corresponding binding.\r\n+     * At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body)\r\n+     * we copy the value inside the loop to the out parameter holder.\r\n+     *\r\n+     * for (let x;;) {\r\n+     *     let a = 1;\r\n+     *     let b = () => a;\r\n+     *     x++\r\n+     *     if (...) break;\r\n+     *     ...\r\n+     * }\r\n+     *\r\n+     * will be converted to\r\n+     *\r\n+     * var out_x;\r\n+     * var loop = function(x) {\r\n+     *     var a = 1;\r\n+     *     var b = function() { return a; }\r\n+     *     x++;\r\n+     *     if (...) return out_x = x, \"break\";\r\n+     *     ...\r\n+     *     out_x = x;\r\n+     * }\r\n+     * for (var x;;) {\r\n+     *     out_x = x;\r\n+     *     var state = loop(x);\r\n+     *     x = out_x;\r\n+     *     if (state === \"break\") break;\r\n+     * }\r\n+     *\r\n+     * NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function\r\n+     * so nobody can observe this new value.\r\n+     */\r\n+    interface LoopOutParameter {\r\n+        originalName: Identifier;\r\n+        outParamName: Identifier;\r\n+    }\r\n+\r\n+    const enum CopyDirection {\r\n+        ToOriginal,\r\n+        ToOutParameter\r\n+    }\r\n+\r\n+    const enum Jump {\r\n+        Break       = 1 << 1,\r\n+        Continue    = 1 << 2,\r\n+        Return      = 1 << 3\r\n+    }\r\n+\r\n+    interface ConvertedLoopState {\r\n+        /*\r\n+         * set of labels that occurred inside the converted loop\r\n+         * used to determine if labeled jump can be emitted as is or it should be dispatched to calling code\r\n+         */\r\n+        labels?: Map<string>;\r\n+        /*\r\n+         * collection of labeled jumps that transfer control outside the converted loop.\r\n+         * maps store association 'label -> labelMarker' where\r\n+         * - label - value of label as it appear in code\r\n+         * - label marker - return value that should be interpreted by calling code as 'jump to <label>'\r\n+         */\r\n+        labeledNonLocalBreaks?: Map<string>;\r\n+        labeledNonLocalContinues?: Map<string>;\r\n+\r\n+        /*\r\n+         * set of non-labeled jumps that transfer control outside the converted loop\r","path":"src/compiler/transformers/es6.ts","position":74,"original_position":74,"commit_id":"646daac6d40f766b4945fd018f53c3a3501c54a7","original_commit_id":"646daac6d40f766b4945fd018f53c3a3501c54a7","user":{"login":"vladima","id":8052307,"avatar_url":"https://avatars.githubusercontent.com/u/8052307?v=3","gravatar_id":"","url":"https://api.github.com/users/vladima","html_url":"https://github.com/vladima","followers_url":"https://api.github.com/users/vladima/followers","following_url":"https://api.github.com/users/vladima/following{/other_user}","gists_url":"https://api.github.com/users/vladima/gists{/gist_id}","starred_url":"https://api.github.com/users/vladima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladima/subscriptions","organizations_url":"https://api.github.com/users/vladima/orgs","repos_url":"https://api.github.com/users/vladima/repos","events_url":"https://api.github.com/users/vladima/events{/privacy}","received_events_url":"https://api.github.com/users/vladima/received_events","type":"User","site_admin":false},"body":"`Jump` represents a combination of flags so I think `set of` expresses this pretty nicely","created_at":"2016-03-29T16:22:13Z","updated_at":"2016-03-29T16:22:13Z","html_url":"https://github.com/Microsoft/TypeScript/pull/7693#discussion_r57753290","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/57753290"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/7693#discussion_r57753290"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693","id":64224536,"html_url":"https://github.com/Microsoft/TypeScript/pull/7693","diff_url":"https://github.com/Microsoft/TypeScript/pull/7693.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/7693.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7693","number":7693,"state":"open","locked":false,"title":"Add support for captured block scoped bindings","user":{"login":"vladima","id":8052307,"avatar_url":"https://avatars.githubusercontent.com/u/8052307?v=3","gravatar_id":"","url":"https://api.github.com/users/vladima","html_url":"https://github.com/vladima","followers_url":"https://api.github.com/users/vladima/followers","following_url":"https://api.github.com/users/vladima/following{/other_user}","gists_url":"https://api.github.com/users/vladima/gists{/gist_id}","starred_url":"https://api.github.com/users/vladima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladima/subscriptions","organizations_url":"https://api.github.com/users/vladima/orgs","repos_url":"https://api.github.com/users/vladima/repos","events_url":"https://api.github.com/users/vladima/events{/privacy}","received_events_url":"https://api.github.com/users/vladima/received_events","type":"User","site_admin":false},"body":"// cc @rbuckton ","created_at":"2016-03-26T01:34:15Z","updated_at":"2016-03-29T16:22:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e698f3ea6d17ff9f1d9695188b918eb46f77099c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7693/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/646daac6d40f766b4945fd018f53c3a3501c54a7","head":{"label":"Microsoft:transforms-block-scoped-bindings","ref":"transforms-block-scoped-bindings","sha":"646daac6d40f766b4945fd018f53c3a3501c54a7","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript/deployments","created_at":"2014-06-17T15:28:39Z","updated_at":"2016-03-29T15:48:06Z","pushed_at":"2016-03-29T04:20:46Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":481304,"stargazers_count":10383,"watchers_count":10383,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1277,"mirror_url":null,"open_issues_count":915,"forks":1277,"open_issues":915,"watchers":10383,"default_branch":"master"}},"base":{"label":"Microsoft:transforms","ref":"transforms","sha":"6e86b13d4681d0fa0d4a61fcd5953d71e631afa4","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript/deployments","created_at":"2014-06-17T15:28:39Z","updated_at":"2016-03-29T15:48:06Z","pushed_at":"2016-03-29T04:20:46Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":481304,"stargazers_count":10383,"watchers_count":10383,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1277,"mirror_url":null,"open_issues_count":915,"forks":1277,"open_issues":915,"watchers":10383,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/7693"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/7693"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/7693/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/7693/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/646daac6d40f766b4945fd018f53c3a3501c54a7"}}}}