{"action":"created","comment":{"url":"https://api.github.com/repos/babel/babel/pulls/comments/25312789","id":25312789,"diff_hunk":"@@ -5,6 +5,64 @@ var t    = require(\"../../../types\");\n \n exports.check = t.isRestElement;\n \n+var memberExpressionVisitor = {\n+  enter: function (node, parent, scope, state) {\n+    var localDeclar = scope.getBindingIdentifier(state.name);\n+    if (localDeclar !== state.outerDeclar) return;\n+\n+    if (t.isFunctionDeclaration(node) || t.isFunctionExpression(node)) {\n+      state.isOptimizable = false;\n+      this.skip();\n+      return;\n+    }\n+\n+    if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;\n+\n+    if (parent.type === 'MemberExpression') {\n+      var prop = parent.property;\n+      if (typeof prop.value === 'number' ||\n+          prop.type === 'UnaryExpression' ||","path":"lib/babel/transformation/transformers/es6/parameters.rest.js","position":null,"original_position":20,"commit_id":"e8fd7af6ffe7126c9b7500ccb8922cc089e5539e","original_commit_id":"8055309fba2763b9abf9e027b23eb967b080fc62","user":{"login":"neVERberleRfellerER","id":11160972,"avatar_url":"https://avatars.githubusercontent.com/u/11160972?v=3","gravatar_id":"","url":"https://api.github.com/users/neVERberleRfellerER","html_url":"https://github.com/neVERberleRfellerER","followers_url":"https://api.github.com/users/neVERberleRfellerER/followers","following_url":"https://api.github.com/users/neVERberleRfellerER/following{/other_user}","gists_url":"https://api.github.com/users/neVERberleRfellerER/gists{/gist_id}","starred_url":"https://api.github.com/users/neVERberleRfellerER/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neVERberleRfellerER/subscriptions","organizations_url":"https://api.github.com/users/neVERberleRfellerER/orgs","repos_url":"https://api.github.com/users/neVERberleRfellerER/repos","events_url":"https://api.github.com/users/neVERberleRfellerER/events{/privacy}","received_events_url":"https://api.github.com/users/neVERberleRfellerER/received_events","type":"User","site_admin":false},"body":"Fixed","created_at":"2015-02-25T02:04:08Z","updated_at":"2015-02-25T02:04:08Z","html_url":"https://github.com/babel/babel/pull/889#discussion_r25312789","pull_request_url":"https://api.github.com/repos/babel/babel/pulls/889","_links":{"self":{"href":"https://api.github.com/repos/babel/babel/pulls/comments/25312789"},"html":{"href":"https://github.com/babel/babel/pull/889#discussion_r25312789"},"pull_request":{"href":"https://api.github.com/repos/babel/babel/pulls/889"}}},"pull_request":{"url":"https://api.github.com/repos/babel/babel/pulls/889","id":29951872,"html_url":"https://github.com/babel/babel/pull/889","diff_url":"https://github.com/babel/babel/pull/889.diff","patch_url":"https://github.com/babel/babel/pull/889.patch","issue_url":"https://api.github.com/repos/babel/babel/issues/889","number":889,"state":"open","locked":false,"title":"Add rest parameters optimization","user":{"login":"neVERberleRfellerER","id":11160972,"avatar_url":"https://avatars.githubusercontent.com/u/11160972?v=3","gravatar_id":"","url":"https://api.github.com/users/neVERberleRfellerER","html_url":"https://github.com/neVERberleRfellerER","followers_url":"https://api.github.com/users/neVERberleRfellerER/followers","following_url":"https://api.github.com/users/neVERberleRfellerER/following{/other_user}","gists_url":"https://api.github.com/users/neVERberleRfellerER/gists{/gist_id}","starred_url":"https://api.github.com/users/neVERberleRfellerER/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neVERberleRfellerER/subscriptions","organizations_url":"https://api.github.com/users/neVERberleRfellerER/orgs","repos_url":"https://api.github.com/users/neVERberleRfellerER/repos","events_url":"https://api.github.com/users/neVERberleRfellerER/events{/privacy}","received_events_url":"https://api.github.com/users/neVERberleRfellerER/received_events","type":"User","site_admin":false},"body":"Purpose\r\n=======\r\n\r\nThis pull request introduces optimization of function rest parameters (example in https://babeljs.io/docs/learn-es6/#default-rest-spread).\r\n\r\nThis PRs should fix issue https://github.com/babel/babel/issues/886.\r\n\r\nProblem\r\n=======\r\n\r\nUsage of rest parameters currently creates copy of arguments as show int following example:\r\n\r\n    function f(foo, ...bar) {\r\n      var x = bar[0];\r\n    }\r\n\r\nGenerated code looks like this\r\n\r\n    function f(foo) {\r\n      for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n        bar[_key - 1] = arguments[_key];\r\n      }\r\n\r\n      var x = bar[0];\r\n    }\r\n\r\nProposal\r\n=======\r\n\r\nGenerated code could be simplifies in some cases. This pull request adds some optimizations. These are show in following blocks. Cases that are not optimized are added to show safety and/or limitations of current implementation.\r\n\r\n    function f(foo, ...bar) {\r\n      console.log(bar[0]);\r\n      console.log(bar[1]);\r\n    }\r\n\r\n    function g(foo, ...bar) {\r\n      console.log(bar);\r\n    }\r\n\r\n    function h(foo, ...bar) {\r\n      return bar[0];\r\n    }\r\n\r\n    function m(foo, ...bar) {\r\n      var x = bar[1+1];\r\n      var y = bar[x+5];\r\n    }\r\n\r\n    function o(foo, ...bar) {\r\n      var x = bar[+1];\r\n      var y = bar[+x];\r\n    }\r\n\r\n    function k(foo, ...bar) {\r\n      var z = bar[x || y];\r\n    }\r\n\r\n    function l(foo, ...bar) {\r\n      var x = bar[foo];\r\n      var y = bar[foo.something];\r\n    }\r\n\r\n    function i(foo, ...bar) {\r\n    }\r\n\r\n    function j(foo, ...bar) {\r\n      var x = function z(bar) {\r\n        bar[1] = 5;\r\n      };\r\n    }\r\n\r\n    function n(foo, ...bar) {\r\n        var x = function () {\r\n            bar[1] = 5;\r\n        };\r\n    }\r\n\r\nis now transpiled into\r\n\r\n    function f(foo) {\r\n      console.log(arguments[1]);\r\n      console.log(arguments[2]);\r\n    }\r\n\r\n    function g(foo) {\r\n      for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n        bar[_key - 1] = arguments[_key];\r\n      }\r\n\r\n      console.log(bar);\r\n    }\r\n\r\n    function h(foo) {\r\n      return arguments[1];\r\n    }\r\n\r\n    function m(foo) {\r\n      var x = arguments[1 + 1 + 1];\r\n      var y = arguments[x + 5 + 1];\r\n    }\r\n\r\n    function o(foo) {\r\n      var x = arguments[+1 + 1];\r\n      var y = arguments[+x + 1];\r\n    }\r\n\r\n    function k(foo) {\r\n      for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n        bar[_key - 1] = arguments[_key];\r\n      }\r\n\r\n      var z = bar[x || y];\r\n    }\r\n\r\n    function l(foo) {\r\n      for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n        bar[_key - 1] = arguments[_key];\r\n      }\r\n\r\n      var x = bar[foo];\r\n      var y = bar[foo.something];\r\n    }\r\n\r\n    function i(foo) {}\r\n\r\n    function j(foo) {\r\n      var x = function z(bar) {\r\n        bar[1] = 5;\r\n      };\r\n    }\r\n\r\n    function n(foo) {\r\n      for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\r\n        bar[_key - 1] = arguments[_key];\r\n      }\r\n\r\n      var x = function x() {\r\n        bar[1] = 5;\r\n      };\r\n    }\r\n\r\nCurrent problems\r\n==============\r\n\r\n- patterns in spreads are broken\r\n\r\nFurther improvements\r\n==================\r\n\r\nSeparate strict mode assumptions about numeric indices as described by @sebmck in https://github.com/babel/babel/issues/886#issuecomment-75878863. This will be done before this is [eventually] merged (unless rejected for wharever reason during review).\r\n\r\nOh, and tests would not hurt.","created_at":"2015-02-25T00:53:38Z","updated_at":"2015-02-25T02:04:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8104e388b4047051b241eda540645873e27aafce","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/babel/babel/pulls/889/commits","review_comments_url":"https://api.github.com/repos/babel/babel/pulls/889/comments","review_comment_url":"https://api.github.com/repos/babel/babel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/babel/babel/issues/889/comments","statuses_url":"https://api.github.com/repos/babel/babel/statuses/e8fd7af6ffe7126c9b7500ccb8922cc089e5539e","head":{"label":"neVERberleRfellerER:rest-args-optimization-v2","ref":"rest-args-optimization-v2","sha":"e8fd7af6ffe7126c9b7500ccb8922cc089e5539e","user":{"login":"neVERberleRfellerER","id":11160972,"avatar_url":"https://avatars.githubusercontent.com/u/11160972?v=3","gravatar_id":"","url":"https://api.github.com/users/neVERberleRfellerER","html_url":"https://github.com/neVERberleRfellerER","followers_url":"https://api.github.com/users/neVERberleRfellerER/followers","following_url":"https://api.github.com/users/neVERberleRfellerER/following{/other_user}","gists_url":"https://api.github.com/users/neVERberleRfellerER/gists{/gist_id}","starred_url":"https://api.github.com/users/neVERberleRfellerER/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neVERberleRfellerER/subscriptions","organizations_url":"https://api.github.com/users/neVERberleRfellerER/orgs","repos_url":"https://api.github.com/users/neVERberleRfellerER/repos","events_url":"https://api.github.com/users/neVERberleRfellerER/events{/privacy}","received_events_url":"https://api.github.com/users/neVERberleRfellerER/received_events","type":"User","site_admin":false},"repo":{"id":31214217,"name":"babel","full_name":"neVERberleRfellerER/babel","owner":{"login":"neVERberleRfellerER","id":11160972,"avatar_url":"https://avatars.githubusercontent.com/u/11160972?v=3","gravatar_id":"","url":"https://api.github.com/users/neVERberleRfellerER","html_url":"https://github.com/neVERberleRfellerER","followers_url":"https://api.github.com/users/neVERberleRfellerER/followers","following_url":"https://api.github.com/users/neVERberleRfellerER/following{/other_user}","gists_url":"https://api.github.com/users/neVERberleRfellerER/gists{/gist_id}","starred_url":"https://api.github.com/users/neVERberleRfellerER/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neVERberleRfellerER/subscriptions","organizations_url":"https://api.github.com/users/neVERberleRfellerER/orgs","repos_url":"https://api.github.com/users/neVERberleRfellerER/repos","events_url":"https://api.github.com/users/neVERberleRfellerER/events{/privacy}","received_events_url":"https://api.github.com/users/neVERberleRfellerER/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neVERberleRfellerER/babel","description":"Babel is a transpiler for writing next generation JavaScript. (Previously 6to5)","fork":true,"url":"https://api.github.com/repos/neVERberleRfellerER/babel","forks_url":"https://api.github.com/repos/neVERberleRfellerER/babel/forks","keys_url":"https://api.github.com/repos/neVERberleRfellerER/babel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neVERberleRfellerER/babel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neVERberleRfellerER/babel/teams","hooks_url":"https://api.github.com/repos/neVERberleRfellerER/babel/hooks","issue_events_url":"https://api.github.com/repos/neVERberleRfellerER/babel/issues/events{/number}","events_url":"https://api.github.com/repos/neVERberleRfellerER/babel/events","assignees_url":"https://api.github.com/repos/neVERberleRfellerER/babel/assignees{/user}","branches_url":"https://api.github.com/repos/neVERberleRfellerER/babel/branches{/branch}","tags_url":"https://api.github.com/repos/neVERberleRfellerER/babel/tags","blobs_url":"https://api.github.com/repos/neVERberleRfellerER/babel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neVERberleRfellerER/babel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neVERberleRfellerER/babel/git/refs{/sha}","trees_url":"https://api.github.com/repos/neVERberleRfellerER/babel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neVERberleRfellerER/babel/statuses/{sha}","languages_url":"https://api.github.com/repos/neVERberleRfellerER/babel/languages","stargazers_url":"https://api.github.com/repos/neVERberleRfellerER/babel/stargazers","contributors_url":"https://api.github.com/repos/neVERberleRfellerER/babel/contributors","subscribers_url":"https://api.github.com/repos/neVERberleRfellerER/babel/subscribers","subscription_url":"https://api.github.com/repos/neVERberleRfellerER/babel/subscription","commits_url":"https://api.github.com/repos/neVERberleRfellerER/babel/commits{/sha}","git_commits_url":"https://api.github.com/repos/neVERberleRfellerER/babel/git/commits{/sha}","comments_url":"https://api.github.com/repos/neVERberleRfellerER/babel/comments{/number}","issue_comment_url":"https://api.github.com/repos/neVERberleRfellerER/babel/issues/comments{/number}","contents_url":"https://api.github.com/repos/neVERberleRfellerER/babel/contents/{+path}","compare_url":"https://api.github.com/repos/neVERberleRfellerER/babel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neVERberleRfellerER/babel/merges","archive_url":"https://api.github.com/repos/neVERberleRfellerER/babel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neVERberleRfellerER/babel/downloads","issues_url":"https://api.github.com/repos/neVERberleRfellerER/babel/issues{/number}","pulls_url":"https://api.github.com/repos/neVERberleRfellerER/babel/pulls{/number}","milestones_url":"https://api.github.com/repos/neVERberleRfellerER/babel/milestones{/number}","notifications_url":"https://api.github.com/repos/neVERberleRfellerER/babel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neVERberleRfellerER/babel/labels{/name}","releases_url":"https://api.github.com/repos/neVERberleRfellerER/babel/releases{/id}","created_at":"2015-02-23T15:32:30Z","updated_at":"2015-02-23T15:32:32Z","pushed_at":"2015-02-25T02:03:33Z","git_url":"git://github.com/neVERberleRfellerER/babel.git","ssh_url":"git@github.com:neVERberleRfellerER/babel.git","clone_url":"https://github.com/neVERberleRfellerER/babel.git","svn_url":"https://github.com/neVERberleRfellerER/babel","homepage":"https://babeljs.io/","size":11519,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"babel:master","ref":"master","sha":"2bab2859705ed240dd586db2cf5aecbd5c889516","user":{"login":"babel","id":9637642,"avatar_url":"https://avatars.githubusercontent.com/u/9637642?v=3","gravatar_id":"","url":"https://api.github.com/users/babel","html_url":"https://github.com/babel","followers_url":"https://api.github.com/users/babel/followers","following_url":"https://api.github.com/users/babel/following{/other_user}","gists_url":"https://api.github.com/users/babel/gists{/gist_id}","starred_url":"https://api.github.com/users/babel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babel/subscriptions","organizations_url":"https://api.github.com/users/babel/orgs","repos_url":"https://api.github.com/users/babel/repos","events_url":"https://api.github.com/users/babel/events{/privacy}","received_events_url":"https://api.github.com/users/babel/received_events","type":"Organization","site_admin":false},"repo":{"id":24560307,"name":"babel","full_name":"babel/babel","owner":{"login":"babel","id":9637642,"avatar_url":"https://avatars.githubusercontent.com/u/9637642?v=3","gravatar_id":"","url":"https://api.github.com/users/babel","html_url":"https://github.com/babel","followers_url":"https://api.github.com/users/babel/followers","following_url":"https://api.github.com/users/babel/following{/other_user}","gists_url":"https://api.github.com/users/babel/gists{/gist_id}","starred_url":"https://api.github.com/users/babel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babel/subscriptions","organizations_url":"https://api.github.com/users/babel/orgs","repos_url":"https://api.github.com/users/babel/repos","events_url":"https://api.github.com/users/babel/events{/privacy}","received_events_url":"https://api.github.com/users/babel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/babel/babel","description":"Babel is a transpiler for writing next generation JavaScript. (Previously 6to5)","fork":false,"url":"https://api.github.com/repos/babel/babel","forks_url":"https://api.github.com/repos/babel/babel/forks","keys_url":"https://api.github.com/repos/babel/babel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/babel/babel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/babel/babel/teams","hooks_url":"https://api.github.com/repos/babel/babel/hooks","issue_events_url":"https://api.github.com/repos/babel/babel/issues/events{/number}","events_url":"https://api.github.com/repos/babel/babel/events","assignees_url":"https://api.github.com/repos/babel/babel/assignees{/user}","branches_url":"https://api.github.com/repos/babel/babel/branches{/branch}","tags_url":"https://api.github.com/repos/babel/babel/tags","blobs_url":"https://api.github.com/repos/babel/babel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/babel/babel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/babel/babel/git/refs{/sha}","trees_url":"https://api.github.com/repos/babel/babel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/babel/babel/statuses/{sha}","languages_url":"https://api.github.com/repos/babel/babel/languages","stargazers_url":"https://api.github.com/repos/babel/babel/stargazers","contributors_url":"https://api.github.com/repos/babel/babel/contributors","subscribers_url":"https://api.github.com/repos/babel/babel/subscribers","subscription_url":"https://api.github.com/repos/babel/babel/subscription","commits_url":"https://api.github.com/repos/babel/babel/commits{/sha}","git_commits_url":"https://api.github.com/repos/babel/babel/git/commits{/sha}","comments_url":"https://api.github.com/repos/babel/babel/comments{/number}","issue_comment_url":"https://api.github.com/repos/babel/babel/issues/comments{/number}","contents_url":"https://api.github.com/repos/babel/babel/contents/{+path}","compare_url":"https://api.github.com/repos/babel/babel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/babel/babel/merges","archive_url":"https://api.github.com/repos/babel/babel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/babel/babel/downloads","issues_url":"https://api.github.com/repos/babel/babel/issues{/number}","pulls_url":"https://api.github.com/repos/babel/babel/pulls{/number}","milestones_url":"https://api.github.com/repos/babel/babel/milestones{/number}","notifications_url":"https://api.github.com/repos/babel/babel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/babel/babel/labels{/name}","releases_url":"https://api.github.com/repos/babel/babel/releases{/id}","created_at":"2014-09-28T13:38:23Z","updated_at":"2015-02-25T01:54:53Z","pushed_at":"2015-02-25T00:07:58Z","git_url":"git://github.com/babel/babel.git","ssh_url":"git@github.com:babel/babel.git","clone_url":"https://github.com/babel/babel.git","svn_url":"https://github.com/babel/babel","homepage":"https://babeljs.io/","size":11519,"stargazers_count":3945,"watchers_count":3945,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":150,"mirror_url":null,"open_issues_count":34,"forks":150,"open_issues":34,"watchers":3945,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/babel/babel/pulls/889"},"html":{"href":"https://github.com/babel/babel/pull/889"},"issue":{"href":"https://api.github.com/repos/babel/babel/issues/889"},"comments":{"href":"https://api.github.com/repos/babel/babel/issues/889/comments"},"review_comments":{"href":"https://api.github.com/repos/babel/babel/pulls/889/comments"},"review_comment":{"href":"https://api.github.com/repos/babel/babel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/babel/babel/pulls/889/commits"},"statuses":{"href":"https://api.github.com/repos/babel/babel/statuses/e8fd7af6ffe7126c9b7500ccb8922cc089e5539e"}}}}