Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS2 Discussion: Output: Drop top-level function safety wrapper? #4934

Closed
coffeescriptbot opened this issue Feb 19, 2018 · 2 comments
Closed
Labels

Comments

@coffeescriptbot
Copy link
Collaborator

From @GeoffreyBooth on 2016-09-16 19:52

CoffeeScript by default adds a top-level function safety wrapper around all the code in each file. It’s just (function(){ ... })();. It can be disabled by setting the --bare flag.

Per the ES2015 spec, import or export statements must appear at the topmost scope, and cannot be within a function block like this. So when modules support was added, we automatically set bare to enabled for any file with module statements.

For 2.0, do we want to get rid of this safety wrapper? ”Bare” mode would become the default, and we would remove the --bare flag as well. Is there any reason to keep them in an ESNext-outputting version of CoffeeScript?

@coffeescriptbot
Copy link
Collaborator Author

From @mrmowgli on 2016-09-16 21:15

I understood the original intent of the closure, however I personally have never found it useful.

I can see it having being worked around in many situations, and if code relies upon the original behavior then that code would break.

Perhaps this could be kept, but on module definition removed? Or removed and allowed back by a flag, although flags seem to be no-no generally.

@coffeescriptbot
Copy link
Collaborator Author

From @GeoffreyBooth on 2016-12-08 04:31

I’ve given this a lot of thought 🤔 and it occurs to me there is one big and probably fairly common use case where the safety wrapper is needed: people who concatenate the output of a bunch of compiled .coffee files. You know, the first example in the documentation:

coffee --compile --output lib/ src/

Without the safety wrapper, any variables declared at the top scope in one file would remain declared at the start of the next file, and so on. Obviously this isn’t an issue for a project using ES modules, so we’re fine ditching the safety wrapper there. But as a default for general projects, we should probably leave the safety wrapper as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant