{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/7636","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/7636/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/7636/comments","events_url":"https://api.github.com/repos/babel/babel/issues/7636/events","html_url":"https://github.com/babel/babel/issues/7636","id":308957908,"number":7636,"title":"'this' becomes 'undefined' in es2015 preset","user":{"login":"thany","id":152227,"avatar_url":"https://avatars1.githubusercontent.com/u/152227?v=4","gravatar_id":"","url":"https://api.github.com/users/thany","html_url":"https://github.com/thany","followers_url":"https://api.github.com/users/thany/followers","following_url":"https://api.github.com/users/thany/following{/other_user}","gists_url":"https://api.github.com/users/thany/gists{/gist_id}","starred_url":"https://api.github.com/users/thany/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thany/subscriptions","organizations_url":"https://api.github.com/users/thany/orgs","repos_url":"https://api.github.com/users/thany/repos","events_url":"https://api.github.com/users/thany/events{/privacy}","received_events_url":"https://api.github.com/users/thany/received_events","type":"User","site_admin":false},"labels":[{"id":441815993,"url":"https://api.github.com/repos/babel/babel/labels/i:%20question","name":"i: question","color":"e99695","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-27T12:58:28Z","updated_at":"2018-03-28T13:32:44Z","closed_at":"2018-03-27T13:35:53Z","author_association":"NONE","body":"<!---\r\nThanks for filing an issue 😄 ! Before you submit, please read the following:\r\n\r\nSearch open/closed issues before submitting since someone might have asked the same thing before!\r\n\r\nIf you have a support request or question please submit them to one of this resources:\r\n\r\n* Slack Community: https://slack.babeljs.io/\r\n* StackOverflow: http://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`\r\n* Also have a look at the readme for more information on how to get support:\r\n  https://github.com/babel/babel/blob/master/README.md\r\n\r\nIssues on GitHub are only related to problems of Babel itself and we cannot answer \r\nsupport questions here.\r\n-->\r\n\r\nBug: when using `this` at the global level of your js code, using the `es2015` or `env` preset, it will be transformed to `undefined`, which is not correct.\r\n\r\n<!--- Provide a general summary of the issue in the title above -->\r\n\r\n### Input Code\r\n<!--- If you're describing a bug, please let us know which sample code reproduces your problem -->\r\n<!--- If you have link to our REPL or a standalone repo please link that! -->\r\n\r\n```js\r\n(function($) {\r\n  // ...\r\n}(this.jQuery));\r\n```\r\n\r\n### Output\r\n```js\r\n\"use strict\";\r\n\r\n(function ($) {\r\n  // ...\r\n})(undefined.jQuery);\r\n```\r\n\r\n### Babel Configuration\r\nCalling babel via gulp:\r\n```js\r\n.pipe(babel({\r\n    presets: [ \"env\" ]\r\n}))\r\n```\r\nNo config file otherwise.\r\n\r\n### Expected Behavior\r\n`this` should not be transformed into `undefined`. There is no reason to.\r\n\r\n### Current Behavior\r\n`this` at the global context is transformed into `undefined`.\r\n\r\n### Possible Solution\r\nIt works fine in the `es2017` preset, so perhaps copy over what that preset is doing, into es2015.\r\n\r\n### Context\r\nI'm trying to transform modern javascript into javascript that oldIE can understand, and the above code is how we write our top-level IIFE to avoid conflicts in the global context. `this` in the global context means the `window` object.\r\n\r\n### Your Environment\r\n<!--- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n| software         | version(s)\r\n| ---------------- | -------\r\n| Babel            |  6.26.0\r\n| Babel-preset-env            |  1.6.1\r\n| Babel-preset-es2015            |  6.24.1\r\n| Gulp-babel            |  7.0.1\r\n| node             | 8.10.0\r\n| npm              | 5.7.1\r\n| Operating System | Windows 10\r\n\r\nNoet: the issue can also be reproduced on the [Try it out](https://babeljs.io/repl/) thing."},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/376887926","html_url":"https://github.com/babel/babel/issues/7636#issuecomment-376887926","issue_url":"https://api.github.com/repos/babel/babel/issues/7636","id":376887926,"user":{"login":"nicolo-ribaudo","id":7000710,"avatar_url":"https://avatars3.githubusercontent.com/u/7000710?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolo-ribaudo","html_url":"https://github.com/nicolo-ribaudo","followers_url":"https://api.github.com/users/nicolo-ribaudo/followers","following_url":"https://api.github.com/users/nicolo-ribaudo/following{/other_user}","gists_url":"https://api.github.com/users/nicolo-ribaudo/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolo-ribaudo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolo-ribaudo/subscriptions","organizations_url":"https://api.github.com/users/nicolo-ribaudo/orgs","repos_url":"https://api.github.com/users/nicolo-ribaudo/repos","events_url":"https://api.github.com/users/nicolo-ribaudo/events{/privacy}","received_events_url":"https://api.github.com/users/nicolo-ribaudo/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T13:32:44Z","updated_at":"2018-03-28T13:32:44Z","author_association":"MEMBER","body":"The global `this` is (and must be) always `undefined` in modules. Since the es2015 preset transpiles modules, it must set `this = undefined`. If you don't want this behavior, you need to diable the modules transformer."}}
{"actor":{"display_login":"nicolo-ribaudo"}}