{"action":"created","issue":{"url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/12","labels_url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/12/comments","events_url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/12/events","html_url":"https://github.com/rollup/rollup-plugin-commonjs/pull/12","id":118792409,"number":12,"title":"Optimise module exports","user":{"login":"Victorystick","id":703602,"avatar_url":"https://avatars.githubusercontent.com/u/703602?v=3","gravatar_id":"","url":"https://api.github.com/users/Victorystick","html_url":"https://github.com/Victorystick","followers_url":"https://api.github.com/users/Victorystick/followers","following_url":"https://api.github.com/users/Victorystick/following{/other_user}","gists_url":"https://api.github.com/users/Victorystick/gists{/gist_id}","starred_url":"https://api.github.com/users/Victorystick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Victorystick/subscriptions","organizations_url":"https://api.github.com/users/Victorystick/orgs","repos_url":"https://api.github.com/users/Victorystick/repos","events_url":"https://api.github.com/users/Victorystick/events{/privacy}","received_events_url":"https://api.github.com/users/Victorystick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-25T09:16:48Z","updated_at":"2015-11-25T10:39:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/pulls/12","html_url":"https://github.com/rollup/rollup-plugin-commonjs/pull/12","diff_url":"https://github.com/rollup/rollup-plugin-commonjs/pull/12.diff","patch_url":"https://github.com/rollup/rollup-plugin-commonjs/pull/12.patch"},"body":"With this PR we will try to optimise assignments to `module.exports` where we can determine that it's safe.\r\n\r\n```js\r\n// example.js\r\nmodule.exports = function(it){\r\n  return typeof it === 'object' ? it !== null : typeof it === 'function';\r\n}\r\n```\r\n\r\n```js\r\n// master branch\r\nvar example = (function (module) {\r\nvar exports = module.exports;\r\nmodule.exports = function(it){\r\n  return typeof it === 'object' ? it !== null : typeof it === 'function';\r\n}\r\nreturn module.exports;\r\n})({exports:{}});\r\n\r\nexport default example;\r\n```\r\n\r\n```js\r\n// optimise-module-exports branch\r\nfunction example(it){\r\n  return typeof it === 'object' ? it !== null : typeof it === 'function';\r\n}\r\n\r\nexport default example;\r\n```\r\n\r\n@Swatinem Does this fix #4 for you?"},"comment":{"url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/comments/159567245","html_url":"https://github.com/rollup/rollup-plugin-commonjs/pull/12#issuecomment-159567245","issue_url":"https://api.github.com/repos/rollup/rollup-plugin-commonjs/issues/12","id":159567245,"user":{"login":"Swatinem","id":580492,"avatar_url":"https://avatars.githubusercontent.com/u/580492?v=3","gravatar_id":"","url":"https://api.github.com/users/Swatinem","html_url":"https://github.com/Swatinem","followers_url":"https://api.github.com/users/Swatinem/followers","following_url":"https://api.github.com/users/Swatinem/following{/other_user}","gists_url":"https://api.github.com/users/Swatinem/gists{/gist_id}","starred_url":"https://api.github.com/users/Swatinem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Swatinem/subscriptions","organizations_url":"https://api.github.com/users/Swatinem/orgs","repos_url":"https://api.github.com/users/Swatinem/repos","events_url":"https://api.github.com/users/Swatinem/events{/privacy}","received_events_url":"https://api.github.com/users/Swatinem/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T10:39:40Z","updated_at":"2015-11-25T10:39:40Z","body":"You have to make sure the `module.exports = ` expression is at the file root.\r\nhttps://github.com/zloirock/core-js/blob/master/modules/_redefine.js <- this file is getting transformed to invalid code:\r\n\r\n```\r\n(export default function(O, key, val, safe){\r\n  if(typeof val == 'function'){\r\n    val.hasOwnProperty(SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));\r\n    val.hasOwnProperty('name') || hide(val, 'name', key);\r\n  }\r\n  if(O === global){\r\n    O[key] = val;\r\n  } else {\r\n    if(!safe){\r\n      delete O[key];\r\n      hide(O, key, val);\r\n    } else {\r\n      if(O[key])O[key] = val;\r\n      else hide(O, key, val);\r\n    }\r\n  }\r\n})(Function.prototype, TO_STRING, function toString(){\r\n  return typeof this == 'function' && this[SRC] || $toString.call(this);\r\n});\r\n```"}}