{"action":"created","issue":{"url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/935","labels_url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/935/labels{/name}","comments_url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/935/comments","events_url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/935/events","html_url":"https://github.com/mishoo/UglifyJS2/issues/935","id":128615489,"number":935,"title":"[ES1-7] `return` outside of function","user":{"login":"Martii","id":114709,"avatar_url":"https://avatars.githubusercontent.com/u/114709?v=3","gravatar_id":"","url":"https://api.github.com/users/Martii","html_url":"https://github.com/Martii","followers_url":"https://api.github.com/users/Martii/followers","following_url":"https://api.github.com/users/Martii/following{/other_user}","gists_url":"https://api.github.com/users/Martii/gists{/gist_id}","starred_url":"https://api.github.com/users/Martii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Martii/subscriptions","organizations_url":"https://api.github.com/users/Martii/orgs","repos_url":"https://api.github.com/users/Martii/repos","events_url":"https://api.github.com/users/Martii/events{/privacy}","received_events_url":"https://api.github.com/users/Martii/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2016-01-25T19:20:58Z","updated_at":"2016-01-26T21:06:08Z","closed_at":null,"body":"So we've got a few failures in minification already... this report is the first one, tested and confirmed.\r\n\r\nA great way to circumvent by throwing a monkey wrench into *UglifyJS2* *(with the API)* via Greasemonkey *(GM)* is to use the following script:\r\n\r\n``` js\r\n// ==UserScript==\r\n// @name          RFC 2606§3 - Hello, World!\r\n// @namespace     http://localhost.localdomain\r\n// @description   Test minification with return statement\r\n// @copyright     2007+, Marti Martz (https://openuserjs.org/users/Marti)\r\n// @license       GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html\r\n// @license       (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/\r\n// @version       0.0.0\r\n// @author        Marti Martz <somewhere@example.com> (https://openuserjs.org/users/Marti)\r\n\r\n// @include   http://www.example.com/*\r\n// @include   http://www.example.net/*\r\n// @include   http://www.example.org/*\r\n// ==/UserScript==\r\n\r\n// ==OpenUserJS==\r\n// @author Marti\r\n// ==/OpenUserJS==\r\n\r\n\r\nvar condition = true;\r\n\r\nif (condition) {\r\n  return; // NOTE: Sabotage any minification with this valid code\r\n} else {\r\n  console.log('I am going to be doing something else now');\r\n}\r\n```\r\n... which with our error trap will return this:\r\n\r\n``` sh-session\r\nMINIFICATION WARNING (harmony):\r\n  message: 'return' outside of function\r\n  installName: Marti/RFC_2606§3_-_Hello,_World!.user.js\r\n  line: 25 col: 8 pos: 859\r\n```\r\nWith GM there **may be** a wrapped function call depending on version and in most browsers there is always an implied \"caller\". With some versions of recent Mozilla based browsers the caller is usually a restricted privileged application in which scoped `caller` will be forced to `null` or `undefined` for the scope of the script depending on injection.\r\n\r\nWork around:\r\n\r\n1. This code can obviously be rewritten without the `return` statement and/or optionally placed in [an IIFE](https://developer.mozilla.org/docs/Glossary/IIFE) *(both the preferred Mozilla style and Chrome style included)* however however it may be inconvenient for some and not fully backward compatible... and definitely a way to destroy the feature.\r\n2. Something else?\r\n\r\n\r\nSuggestion*(s)*:\r\n\r\n1. Add a [generator](http://lisperator.net/uglifyjs/codegen) and/or [compressor](http://lisperator.net/uglifyjs/compress) option to ignore this **warning** *(__not__ supposed to be an error)* that we can set for looser strictness. *(I'm not seeing [this commit methodology](https://github.com/mishoo/UglifyJS2/commit/f36a1eaa8b5203ab7e4616108c33a0b68668a8db) referenced at these docs... __Did I miss it?__)*\r\n2. Something else?\r\n\r\nExternal refs:\r\n* https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/return\r\n* [ES1 spec](http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf) *(Do a search in the PDF... more tightly restricted here)*\r\n* [ES6 spec](http://www.ecma-international.org/ecma-262/6.0/#sec-return-statement) *(Less restricted here by denoting `caller`)*\r\n* https://github.com/greasemonkey/greasemonkey/issues/1670\r\n* https://github.com/greasemonkey/greasemonkey/commit/d0a47f3a3efc29a59d08a5c2e512234a8602a03e  *(special note on how this is currently handled)*\r\n* greasemonkey/greasemonkey#1592\r\n\r\nHistorical refs:\r\n* https://github.com/mishoo/UglifyJS2/issues/288  *(the assumptions here are too vague as are the ECMAScript specs of course)*\r\n* https://github.com/mishoo/UglifyJS2/search?q=bare+returns&type=Code&utf8=%E2%9C%93\r\n\r\nTIA\r\n\r\nCc: @fabiosantoscode and @avdg *(mishoo will always get these as owner so omitting)*"},"comment":{"url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/comments/175230182","html_url":"https://github.com/mishoo/UglifyJS2/issues/935#issuecomment-175230182","issue_url":"https://api.github.com/repos/mishoo/UglifyJS2/issues/935","id":175230182,"user":{"login":"Martii","id":114709,"avatar_url":"https://avatars.githubusercontent.com/u/114709?v=3","gravatar_id":"","url":"https://api.github.com/users/Martii","html_url":"https://github.com/Martii","followers_url":"https://api.github.com/users/Martii/followers","following_url":"https://api.github.com/users/Martii/following{/other_user}","gists_url":"https://api.github.com/users/Martii/gists{/gist_id}","starred_url":"https://api.github.com/users/Martii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Martii/subscriptions","organizations_url":"https://api.github.com/users/Martii/orgs","repos_url":"https://api.github.com/users/Martii/repos","events_url":"https://api.github.com/users/Martii/events{/privacy}","received_events_url":"https://api.github.com/users/Martii/received_events","type":"User","site_admin":false},"created_at":"2016-01-26T21:06:08Z","updated_at":"2016-01-26T21:06:08Z","body":"> straightforwardly implemented in the cli right now.\r\n\r\nThe CLI isn't organized in the same representational logic as the API though... which is why I mentioned both API Objects [above](https://github.com/mishoo/UglifyJS2/issues/935#issue-128615489) under suggestions e.g. I don't know if this would be a generator option, compressor option, or at the \"top-level\" where `fromString` resides... or another object that is specific to `parser`... this is the part of the flow I haven't fully figured out yet with the \"shortcut\" of `minify`... being only a few weeks into this project directly."}}