{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/53098516","id":53098516,"diff_hunk":"@@ -1751,4 +1791,440 @@ namespace ts {\n             implicitLabels = [];\r\n         }\r\n     }\r\n+\r\n+    /**\r\n+     * Computes the transform flags for a node, given the transform flags of its subtree\r\n+     *\r\n+     * @param node The node to analyze\r\n+     * @param subtreeFlags Transform flags computed for this node's subtree\r\n+     */\r\n+    export function computeTransformFlagsForNode(node: Node, subtreeFlags: TransformFlags) {\r\n+        // Ambient nodes are TypeScript syntax and the flags of their subtree are ignored.\r\n+        if (node.flags & NodeFlags.Ambient) {\r\n+            return (node.transformFlags = TransformFlags.AssertTypeScript)\r\n+                & ~(node.excludeTransformFlags = TransformFlags.NodeExcludes);\r","path":"src/compiler/binder.ts","position":87,"original_position":87,"commit_id":"319ff614a0e824f8f2f4d4b67179883813c40d80","original_commit_id":"319ff614a0e824f8f2f4d4b67179883813c40d80","user":{"login":"rbuckton","id":3902892,"avatar_url":"https://avatars.githubusercontent.com/u/3902892?v=3","gravatar_id":"","url":"https://api.github.com/users/rbuckton","html_url":"https://github.com/rbuckton","followers_url":"https://api.github.com/users/rbuckton/followers","following_url":"https://api.github.com/users/rbuckton/following{/other_user}","gists_url":"https://api.github.com/users/rbuckton/gists{/gist_id}","starred_url":"https://api.github.com/users/rbuckton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbuckton/subscriptions","organizations_url":"https://api.github.com/users/rbuckton/orgs","repos_url":"https://api.github.com/users/rbuckton/repos","events_url":"https://api.github.com/users/rbuckton/events{/privacy}","received_events_url":"https://api.github.com/users/rbuckton/received_events","type":"User","site_admin":false},"body":"Yes, `~` gets the ones-complement of the operand. The result here is the `transformFlags` of the node, excluding `excludeTransformFlags` of the node.","created_at":"2016-02-16T23:33:35Z","updated_at":"2016-02-16T23:33:35Z","html_url":"https://github.com/Microsoft/TypeScript/pull/6983#discussion_r53098516","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/53098516"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/6983#discussion_r53098516"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983","id":58797855,"html_url":"https://github.com/Microsoft/TypeScript/pull/6983","diff_url":"https://github.com/Microsoft/TypeScript/pull/6983.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/6983.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6983","number":6983,"state":"open","locked":false,"title":"Adds the Transform Flags concept for tree transformations","user":{"login":"rbuckton","id":3902892,"avatar_url":"https://avatars.githubusercontent.com/u/3902892?v=3","gravatar_id":"","url":"https://api.github.com/users/rbuckton","html_url":"https://github.com/rbuckton","followers_url":"https://api.github.com/users/rbuckton/followers","following_url":"https://api.github.com/users/rbuckton/following{/other_user}","gists_url":"https://api.github.com/users/rbuckton/gists{/gist_id}","starred_url":"https://api.github.com/users/rbuckton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbuckton/subscriptions","organizations_url":"https://api.github.com/users/rbuckton/orgs","repos_url":"https://api.github.com/users/rbuckton/repos","events_url":"https://api.github.com/users/rbuckton/events{/privacy}","received_events_url":"https://api.github.com/users/rbuckton/received_events","type":"User","site_admin":false},"body":"To ensure tree transformations in the TypeScript compiler are efficient, we compute information about various required transformations for each node. Transform flags are aggregated in a bottom-up fashion, so that we already have information about a node's subtree when we compute the transform flags for the node. These transform flags are initially computed during the **bind** phase of the compiler, as at that point we guarantee a full walk of the tree.\r\n\r\n![transformflags](https://cloud.githubusercontent.com/assets/3902892/12927470/3b5c45cc-cf1d-11e5-92cb-39c0ca0ec4f7.png)\r\n\r\nThe values in the `TransformFlags` enum fall into several categories:\r\n\r\n* *Facts* - State something about a node or its subtree. Facts that start with \"Contains\" indicate that a node somewhere within the current node's subtree requires a transformation. Facts that do not start with \"Contains\" indicate that the current node itself requires a transformation.\r\n  * *Markers* - A special class of *Facts* that indicate specific transformations that need to occur higher in the source tree.\r\n* *Assertions* - Sets of *Facts* to apply to a node. These are used primarily in the `computeTransformFlagsForNode` function in `binder.ts`.\r\n* *Exclusions* - Bitmasks that are used to prevent some *Facts* from being copied up the subtree.\r\n\r\nAs a result, the `Node` interface is extended to include two additional properties:\r\n* `transformFlags` - Contains the `TransformFlags` that pertain to this specific node.\r\n* `excludeTransformFlags` - Contains a bitmask of `TransformFlags` that should be excluded from this node's `transformFlags` when aggregating the transform flags of a subtree containing this node.\r\n\r\nThe binder is modified to compute the transform flags for each node as it walks the tree. As a performance optimization, we skip transform flag aggregation for ambient nodes, type nodes, and declaration files. \r\n\r\nEach transformation phase will likely introduce new nodes. As a result, the `visitNode` and `visitNodes` functions in `visitor.ts` perform supplemental aggregation of transform flags to ensure successive transformation phases have the requisite information to perform additional transformations. \r\n\r\nFor example, it is possible that during the transformation from TypeScript to ES6 we may introduce an arrow function a for more idiomatic ES6 emit. This may then result in a new `this` capture which we would then need to know about during the next transformation. Rather than send the new tree through another pass of the checker, we will instead leverage the `TransformFlags.ContainsLexicalThis` and `TransformFlags.ContainsCapturedLexicalThis` flags to determine whether we need further transformation.\r\n\r\nThese flags will enable us to have more efficient transformers in the long term, that can make decisions about whether to continue to walk a subtree based on querying these flags. The following example builds on the one found in #6892:\r\n\r\n```ts\r\nfunction visitor(node: Node) {\r\n  if (node.transformFlags & TransformFlags.ES7) {\r\n    // This node is an ES7 node and needs a specific transformation\r\n    return visitorWorker(node);\r\n  }\r\n  else if (node.transformFlags & TransformFlags.ContainsES7) {\r\n    // This node contains an ES7 node somewhere in its subtree, so we must walk the subtree\r\n    return visitEachChild(node, visitor);\r\n  }\r\n  else {\r\n    // Neither this node, nor its subtree, require any transformation, so we can simply \r\n    // reuse the node and its subtree and avoid a costly walk\r\n    return node;\r\n  }\r\n}\r\n\r\nfunction visitorWorker(node: Node) {\r\n  switch (node.kind) {\r\n    case SyntaxKind.BinaryExpression:\r\n      return visitBinaryExpression(<BinaryExpression>node);\r\n    ...\r\n    default:\r\n      return visitEachChild(node, visitor);\r\n  }\r\n}\r\n\r\nfunction visitBinaryExpression(node: BinaryExpression) {\r\n  if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskToken) {\r\n    return createCall(\r\n      createPropertyAccess(createIdentifier(\"Math\"), \"pow\"),\r\n      [\r\n        visitNode(node.left, visitor, isExpressionNode),\r\n        visitNode(node.right, visitor, isExpressionNode)\r\n      ]\r\n    );\r\n  }\r\n  else {\r\n    return visitEachChild(node, visitor);\r\n  }\r\n}\r\n```\r\n\r\n**Related Pull Requests:**\r\n* #6892 - Adds the visitor API foundation for tree transformations.\r\n* #6983 - **Adds the Transform Flags concept for tree transformations.**\r\n* #6986 - Adds the transformFiles API for tree transformations.\r\n* #6987 - Adds a simplified pretty printer for tree transformations.","created_at":"2016-02-09T19:40:59Z","updated_at":"2016-02-16T23:33:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3f1602ef1bbeec6e3947be5c6b673a667e33ed1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6983/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/319ff614a0e824f8f2f4d4b67179883813c40d80","head":{"label":"Microsoft:transforms-flags","ref":"transforms-flags","sha":"319ff614a0e824f8f2f4d4b67179883813c40d80","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-02-16T22:56:11Z","pushed_at":"2016-02-16T22:55:28Z","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":476109,"stargazers_count":9437,"watchers_count":9437,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1143,"mirror_url":null,"open_issues_count":1037,"forks":1143,"open_issues":1037,"watchers":9437,"default_branch":"master"}},"base":{"label":"Microsoft:transforms-visitor","ref":"transforms-visitor","sha":"387b30c296e6ef5faff275f3afb7a60db16c15e2","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-02-16T22:56:11Z","pushed_at":"2016-02-16T22:55:28Z","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":476109,"stargazers_count":9437,"watchers_count":9437,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1143,"mirror_url":null,"open_issues_count":1037,"forks":1143,"open_issues":1037,"watchers":9437,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/6983"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/6983"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/6983/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6983/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/319ff614a0e824f8f2f4d4b67179883813c40d80"}}}}