{"action":"created","comment":{"url":"https://api.github.com/repos/angular/angular/pulls/comments/70316184","id":70316184,"diff_hunk":"@@ -235,23 +247,125 @@ class _AstToIrVisitor implements cdAst.AstVisitor {\n       receiver = this._implicitReceiver;\n     }\n     return convertToStatementIfNeeded(\n-        mode, receiver.prop(ast.name).set(ast.value.visit(this, _Mode.Expression)));\n+        mode, receiver.prop(ast.name).set(this.visit(ast.value, _Mode.Expression)));\n   }\n   visitSafePropertyRead(ast: cdAst.SafePropertyRead, mode: _Mode): any {\n-    var receiver = ast.receiver.visit(this, _Mode.Expression);\n-    return convertToStatementIfNeeded(\n-        mode, receiver.isBlank().conditional(o.NULL_EXPR, receiver.prop(ast.name)));\n+    return this.convertSafeAccess(ast, this.leftMostSafeNode(ast), mode);\n   }\n   visitSafeMethodCall(ast: cdAst.SafeMethodCall, mode: _Mode): any {\n-    var receiver = ast.receiver.visit(this, _Mode.Expression);\n-    var args = this.visitAll(ast.args, _Mode.Expression);\n-    return convertToStatementIfNeeded(\n-        mode, receiver.isBlank().conditional(o.NULL_EXPR, receiver.callMethod(ast.name, args)));\n+    return this.convertSafeAccess(ast, this.leftMostSafeNode(ast), mode);\n   }\n-  visitAll(asts: cdAst.AST[], mode: _Mode): any { return asts.map(ast => ast.visit(this, mode)); }\n+  visitAll(asts: cdAst.AST[], mode: _Mode): any { return asts.map(ast => this.visit(ast, mode)); }\n   visitQuote(ast: cdAst.Quote, mode: _Mode): any {\n     throw new BaseException('Quotes are not supported for evaluation!');\n   }\n+\n+  private visit(ast: cdAst.AST, mode: _Mode): any {\n+    return (this._map.get(ast) || ast).visit(this, mode);\n+  }\n+\n+  private convertSafeAccess(\n+      ast: cdAst.AST, leftMostSafe: cdAst.SafeMethodCall|cdAst.SafePropertyRead, mode: _Mode): any {\n+    // If the expression contains a safe access node on the left it needs to be converted to\n+    // an expression that guards the access to the member by checking the receiver for blank. As\n+    // execution proceeds from left to right, the left most part of the expression must be guarded\n+    // first but, because member access is left associative, the right side of the expression is at\n+    // the top of the AST. The desired result requires lifting a copy of the the left part of the\n+    // expression up to test it for blank before generating the unguarded version.\n+\n+    // Consider, for example the following expression: a?.b.c?.d.e\n+\n+    // This results in the ast:\n+    //         .\n+    //        / \\\n+    //       ?.   e\n+    //      /  \\\n+    //     .    d\n+    //    / \\\n+    //   ?.  c\n+    //  /  \\\n+    // a    b\n+\n+    // The following tree should be generated:\n+    //\n+    //        /---- ? ----\\\n+    //       /      |      \\\n+    //     a   /--- ? ---\\  null\n+    //        /     |     \\\n+    //       .      .     null\n+    //      / \\    / \\\n+    //     .  c   .   e\n+    //    / \\    / \\\n+    //   a   b  ,   d\n+    //         / \\\n+    //        .   c\n+    //       / \\\n+    //      a   b\n+    //\n+    // Notice that the first guard condition is the left hand of the left most safe access node\n+    // which comes in as leftMostSafe to this routine.\n+\n+    const condition = this.visit(leftMostSafe.receiver, mode).isBlank();\n+\n+    // Convert the ast to an unguarded access to the receiver's member. The map will substitute\n+    // leftMostNode with its unguarded version in the call to `this.visit()`.\n+    if (leftMostSafe instanceof cdAst.SafeMethodCall) {\n+      this._map.set(\n+          leftMostSafe,\n+          new cdAst.MethodCall(\n+              leftMostSafe.span, leftMostSafe.receiver, leftMostSafe.name, leftMostSafe.args));\n+    } else {\n+      this._map.set(\n+          leftMostSafe,\n+          new cdAst.PropertyRead(leftMostSafe.span, leftMostSafe.receiver, leftMostSafe.name));\n+    }\n+\n+    // Recursively convert the node now without the guarded member access.\n+    const access = this.visit(ast, mode);\n+\n+    // Remove the mapping. This is not strictly required as the converter only traverses each node\n+    // once but is safer if the conversion is changed to traverse the nodes more than once.\n+    this._map.delete(leftMostSafe);\n+\n+    // Produce the conditional\n+    return condition.conditional(o.literal(null), access);\n+  }\n+\n+  // Given a expression of the form a?.b.c?.d.e the the left most safe node is\n+  // the (a?.b). The . and ?. are left associative thus can be rewritten as:\n+  // ((((a?.c).b).c)?.d).e. This returns the most deeply nested safe read or\n+  // safe method call as this needs be transform initially to:\n+  //   a == null ? null : a.c.b.c?.d.e\n+  // then to:\n+  //   a == null ? null : a.b.c == null ? null : a.b.c.d.e\n+  private leftMostSafeNode(ast: cdAst.AST): cdAst.SafePropertyRead|cdAst.SafeMethodCall {\n+    let visit = (visitor: cdAst.AstVisitor, ast: cdAst.AST): any => {","path":"modules/@angular/compiler/src/view_compiler/expression_converter.ts","position":300,"original_position":300,"commit_id":"26617634bfac1cbb97d0be7ab82147047193fe3b","original_commit_id":"26617634bfac1cbb97d0be7ab82147047193fe3b","user":{"login":"vicb","id":248818,"avatar_url":"https://avatars.githubusercontent.com/u/248818?v=3","gravatar_id":"","url":"https://api.github.com/users/vicb","html_url":"https://github.com/vicb","followers_url":"https://api.github.com/users/vicb/followers","following_url":"https://api.github.com/users/vicb/following{/other_user}","gists_url":"https://api.github.com/users/vicb/gists{/gist_id}","starred_url":"https://api.github.com/users/vicb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vicb/subscriptions","organizations_url":"https://api.github.com/users/vicb/orgs","repos_url":"https://api.github.com/users/vicb/repos","events_url":"https://api.github.com/users/vicb/events{/privacy}","received_events_url":"https://api.github.com/users/vicb/received_events","type":"User","site_admin":false},"body":"`let visit = (visitor: cdAst.AstVisitor, ast: cdAst.AST): any => this.visit(vistor, ast);`","created_at":"2016-07-11T18:58:52Z","updated_at":"2016-07-11T18:58:52Z","html_url":"https://github.com/angular/angular/pull/9965#discussion_r70316184","pull_request_url":"https://api.github.com/repos/angular/angular/pulls/9965","_links":{"self":{"href":"https://api.github.com/repos/angular/angular/pulls/comments/70316184"},"html":{"href":"https://github.com/angular/angular/pull/9965#discussion_r70316184"},"pull_request":{"href":"https://api.github.com/repos/angular/angular/pulls/9965"}}},"pull_request":{"url":"https://api.github.com/repos/angular/angular/pulls/9965","id":76989140,"html_url":"https://github.com/angular/angular/pull/9965","diff_url":"https://github.com/angular/angular/pull/9965.diff","patch_url":"https://github.com/angular/angular/pull/9965.patch","issue_url":"https://api.github.com/repos/angular/angular/issues/9965","number":9965,"state":"open","locked":false,"title":"fix(compiler): Fixed ?. operator to short-circut execution","user":{"login":"chuckjaz","id":372013,"avatar_url":"https://avatars.githubusercontent.com/u/372013?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckjaz","html_url":"https://github.com/chuckjaz","followers_url":"https://api.github.com/users/chuckjaz/followers","following_url":"https://api.github.com/users/chuckjaz/following{/other_user}","gists_url":"https://api.github.com/users/chuckjaz/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckjaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckjaz/subscriptions","organizations_url":"https://api.github.com/users/chuckjaz/orgs","repos_url":"https://api.github.com/users/chuckjaz/repos","events_url":"https://api.github.com/users/chuckjaz/events{/privacy}","received_events_url":"https://api.github.com/users/chuckjaz/received_events","type":"User","site_admin":false},"body":"**Please check if the PR fulfills these requirements**\r\n- [x] The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format\r\n- [x] Tests for the changes have been added (for bug fixes / features)\r\n- [ ] Docs have been added / updated (for bug fixes / features)\r\n\r\n\r\n**What kind of change does this PR introduce?** (check one with \"x\")\r\n```\r\n[x] Bugfix\r\n[ ] Feature\r\n[ ] Code style update (formatting, local variables)\r\n[ ] Refactoring (no functional changes, no api changes)\r\n[ ] Build related changes\r\n[ ] CI related changes\r\n[ ] Other... Please describe:\r\n```\r\n\r\n**What is the current behavior?** (You can also link to an open issue here)\r\n\r\nThe expression `a?.b.c` will result in an exception if `a` is `null` or `undefined` requiring the expression to be `a?.b?.c` even if `b` is guaranteed to never be `null`.  See #9850.\r\n\r\n**What is the new behavior?**\r\n\r\nThe expression `a?.b.c` will short-circuit to `null` if `a` is `null` or `undefined`.  The expression is transformed into the equivalent of `a == null ? null : a.b.c` instead of `(a == null ? null : a.b).c`.\r\n\r\n**Does this PR introduce a breaking change?** (check one with \"x\")\r\n```\r\n[ ] Yes\r\n[x] No\r\n```\r\n\r\n**Other information**:\r\n\r\n\r\nFixes: #9850","created_at":"2016-07-11T17:07:54Z","updated_at":"2016-07-11T18:58:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"956e9aeef7f884b29c972b4b7bdec7a9ab447adf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/angular/angular/pulls/9965/commits","review_comments_url":"https://api.github.com/repos/angular/angular/pulls/9965/comments","review_comment_url":"https://api.github.com/repos/angular/angular/pulls/comments{/number}","comments_url":"https://api.github.com/repos/angular/angular/issues/9965/comments","statuses_url":"https://api.github.com/repos/angular/angular/statuses/26617634bfac1cbb97d0be7ab82147047193fe3b","head":{"label":"chuckjaz:issue9850","ref":"issue9850","sha":"26617634bfac1cbb97d0be7ab82147047193fe3b","user":{"login":"chuckjaz","id":372013,"avatar_url":"https://avatars.githubusercontent.com/u/372013?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckjaz","html_url":"https://github.com/chuckjaz","followers_url":"https://api.github.com/users/chuckjaz/followers","following_url":"https://api.github.com/users/chuckjaz/following{/other_user}","gists_url":"https://api.github.com/users/chuckjaz/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckjaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckjaz/subscriptions","organizations_url":"https://api.github.com/users/chuckjaz/orgs","repos_url":"https://api.github.com/users/chuckjaz/repos","events_url":"https://api.github.com/users/chuckjaz/events{/privacy}","received_events_url":"https://api.github.com/users/chuckjaz/received_events","type":"User","site_admin":false},"repo":{"id":50690962,"name":"angular","full_name":"chuckjaz/angular","owner":{"login":"chuckjaz","id":372013,"avatar_url":"https://avatars.githubusercontent.com/u/372013?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckjaz","html_url":"https://github.com/chuckjaz","followers_url":"https://api.github.com/users/chuckjaz/followers","following_url":"https://api.github.com/users/chuckjaz/following{/other_user}","gists_url":"https://api.github.com/users/chuckjaz/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckjaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckjaz/subscriptions","organizations_url":"https://api.github.com/users/chuckjaz/orgs","repos_url":"https://api.github.com/users/chuckjaz/repos","events_url":"https://api.github.com/users/chuckjaz/events{/privacy}","received_events_url":"https://api.github.com/users/chuckjaz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chuckjaz/angular","description":"","fork":true,"url":"https://api.github.com/repos/chuckjaz/angular","forks_url":"https://api.github.com/repos/chuckjaz/angular/forks","keys_url":"https://api.github.com/repos/chuckjaz/angular/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chuckjaz/angular/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chuckjaz/angular/teams","hooks_url":"https://api.github.com/repos/chuckjaz/angular/hooks","issue_events_url":"https://api.github.com/repos/chuckjaz/angular/issues/events{/number}","events_url":"https://api.github.com/repos/chuckjaz/angular/events","assignees_url":"https://api.github.com/repos/chuckjaz/angular/assignees{/user}","branches_url":"https://api.github.com/repos/chuckjaz/angular/branches{/branch}","tags_url":"https://api.github.com/repos/chuckjaz/angular/tags","blobs_url":"https://api.github.com/repos/chuckjaz/angular/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chuckjaz/angular/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chuckjaz/angular/git/refs{/sha}","trees_url":"https://api.github.com/repos/chuckjaz/angular/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chuckjaz/angular/statuses/{sha}","languages_url":"https://api.github.com/repos/chuckjaz/angular/languages","stargazers_url":"https://api.github.com/repos/chuckjaz/angular/stargazers","contributors_url":"https://api.github.com/repos/chuckjaz/angular/contributors","subscribers_url":"https://api.github.com/repos/chuckjaz/angular/subscribers","subscription_url":"https://api.github.com/repos/chuckjaz/angular/subscription","commits_url":"https://api.github.com/repos/chuckjaz/angular/commits{/sha}","git_commits_url":"https://api.github.com/repos/chuckjaz/angular/git/commits{/sha}","comments_url":"https://api.github.com/repos/chuckjaz/angular/comments{/number}","issue_comment_url":"https://api.github.com/repos/chuckjaz/angular/issues/comments{/number}","contents_url":"https://api.github.com/repos/chuckjaz/angular/contents/{+path}","compare_url":"https://api.github.com/repos/chuckjaz/angular/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chuckjaz/angular/merges","archive_url":"https://api.github.com/repos/chuckjaz/angular/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chuckjaz/angular/downloads","issues_url":"https://api.github.com/repos/chuckjaz/angular/issues{/number}","pulls_url":"https://api.github.com/repos/chuckjaz/angular/pulls{/number}","milestones_url":"https://api.github.com/repos/chuckjaz/angular/milestones{/number}","notifications_url":"https://api.github.com/repos/chuckjaz/angular/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chuckjaz/angular/labels{/name}","releases_url":"https://api.github.com/repos/chuckjaz/angular/releases{/id}","deployments_url":"https://api.github.com/repos/chuckjaz/angular/deployments","created_at":"2016-01-29T21:00:52Z","updated_at":"2016-01-29T21:01:07Z","pushed_at":"2016-07-11T18:49:01Z","git_url":"git://github.com/chuckjaz/angular.git","ssh_url":"git@github.com:chuckjaz/angular.git","clone_url":"https://github.com/chuckjaz/angular.git","svn_url":"https://github.com/chuckjaz/angular","homepage":"https://angular.io","size":141465,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"angular:master","ref":"master","sha":"a05f7b2d763039868cf3926f9e9c32ad17d1f7bc","user":{"login":"angular","id":139426,"avatar_url":"https://avatars.githubusercontent.com/u/139426?v=3","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"repo":{"id":24195339,"name":"angular","full_name":"angular/angular","owner":{"login":"angular","id":139426,"avatar_url":"https://avatars.githubusercontent.com/u/139426?v=3","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/angular/angular","description":"","fork":false,"url":"https://api.github.com/repos/angular/angular","forks_url":"https://api.github.com/repos/angular/angular/forks","keys_url":"https://api.github.com/repos/angular/angular/keys{/key_id}","collaborators_url":"https://api.github.com/repos/angular/angular/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/angular/angular/teams","hooks_url":"https://api.github.com/repos/angular/angular/hooks","issue_events_url":"https://api.github.com/repos/angular/angular/issues/events{/number}","events_url":"https://api.github.com/repos/angular/angular/events","assignees_url":"https://api.github.com/repos/angular/angular/assignees{/user}","branches_url":"https://api.github.com/repos/angular/angular/branches{/branch}","tags_url":"https://api.github.com/repos/angular/angular/tags","blobs_url":"https://api.github.com/repos/angular/angular/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/angular/angular/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/angular/angular/git/refs{/sha}","trees_url":"https://api.github.com/repos/angular/angular/git/trees{/sha}","statuses_url":"https://api.github.com/repos/angular/angular/statuses/{sha}","languages_url":"https://api.github.com/repos/angular/angular/languages","stargazers_url":"https://api.github.com/repos/angular/angular/stargazers","contributors_url":"https://api.github.com/repos/angular/angular/contributors","subscribers_url":"https://api.github.com/repos/angular/angular/subscribers","subscription_url":"https://api.github.com/repos/angular/angular/subscription","commits_url":"https://api.github.com/repos/angular/angular/commits{/sha}","git_commits_url":"https://api.github.com/repos/angular/angular/git/commits{/sha}","comments_url":"https://api.github.com/repos/angular/angular/comments{/number}","issue_comment_url":"https://api.github.com/repos/angular/angular/issues/comments{/number}","contents_url":"https://api.github.com/repos/angular/angular/contents/{+path}","compare_url":"https://api.github.com/repos/angular/angular/compare/{base}...{head}","merges_url":"https://api.github.com/repos/angular/angular/merges","archive_url":"https://api.github.com/repos/angular/angular/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/angular/angular/downloads","issues_url":"https://api.github.com/repos/angular/angular/issues{/number}","pulls_url":"https://api.github.com/repos/angular/angular/pulls{/number}","milestones_url":"https://api.github.com/repos/angular/angular/milestones{/number}","notifications_url":"https://api.github.com/repos/angular/angular/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/angular/angular/labels{/name}","releases_url":"https://api.github.com/repos/angular/angular/releases{/id}","deployments_url":"https://api.github.com/repos/angular/angular/deployments","created_at":"2014-09-18T16:12:01Z","updated_at":"2016-07-11T17:51:11Z","pushed_at":"2016-07-11T18:57:40Z","git_url":"git://github.com/angular/angular.git","ssh_url":"git@github.com:angular/angular.git","clone_url":"https://github.com/angular/angular.git","svn_url":"https://github.com/angular/angular","homepage":"https://angular.io","size":641946,"stargazers_count":13767,"watchers_count":13767,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3568,"mirror_url":null,"open_issues_count":1263,"forks":3568,"open_issues":1263,"watchers":13767,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/angular/angular/pulls/9965"},"html":{"href":"https://github.com/angular/angular/pull/9965"},"issue":{"href":"https://api.github.com/repos/angular/angular/issues/9965"},"comments":{"href":"https://api.github.com/repos/angular/angular/issues/9965/comments"},"review_comments":{"href":"https://api.github.com/repos/angular/angular/pulls/9965/comments"},"review_comment":{"href":"https://api.github.com/repos/angular/angular/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/angular/angular/pulls/9965/commits"},"statuses":{"href":"https://api.github.com/repos/angular/angular/statuses/26617634bfac1cbb97d0be7ab82147047193fe3b"}}}}
{"actor":{"display_login":"vicb"}}