-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Use strict. For real. #2337
Use strict. For real. #2337
Conversation
Interesting, coffeescript code doesn't pass strict mode checker. Working on this.
|
@paulmillr: Both of those are obvious failures. The first is because it's looking for a specific output. The second is because a |
Yep, fixed. |
nope, not really. still fails browser tests because it has different execution context. |
@michaelficarra can test for #855 be removed at all? Doesn't seem to be very useful in our context. |
contextTest array # this is undefined
contextTest.apply undefined, array # this is undefined
contextTest array... # this is null Should we pass |
@@ -305,10 +305,11 @@ test "Prefix unary assignment operators are allowed in parenless calls.", -> | |||
ok (func --val) is 5 | |||
|
|||
test "#855: execution context for `func arr...` should be `null`", -> | |||
contextTest = -> eq @, if window? then window else global | |||
contextTest = -> | |||
eq this, window ? global if this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now no longer does the test at all in strict mode. That's not desirable.
Love ((x) -> x = 2; arguments[0] is 2)(1) #true and more problematic/far reaching: Amazon bitten by strict |
@geraldalewis any other issues? These were a long time ago and right now every stable version of every browser (ie isn't one) supports strict mode, so it would be quite hard to run into any of these in production env not spotting them in dev env. |
I think it's important to add use strict because forgetting it can make code do things you wouldn't always immediately expect, often erroneous, and worse still, continue plodding on until it hits some other error, making code difficult to debug. For instance, forgetting a |
What's the status of this? I agree that it should not be the default, but I think it'd be great to have it as an option. Is that the consensus and we're just waiting for an updated patch, or is there some doubt about whether this should be included even as an option? |
Having wished for having "use strict" enabled for the first time of my life (chasing a global which turned out to be coming from a missing double arrow and doing |
Whats the current state of this issue? I want TypeErrors when trying to add properties to sealed objects - without 'use strict' statement, these fail silently. Therefore i'd like to have an option that generates 'use strict' statements in the top-level function safety wrapper. |
Writing 'use strict'; at the top of a CoffeeScript file's really inelegant, and I don't even know if it works properly. Would be nice if CS had a proper directive for it. |
so... the merge conflicts on this branch are probably way out of hand to easily resolve at this point... but would it be possible to re-use this work and make this a default thing? |
In ES2015, strict mode is automatically enabled for ES modules or classes, so for many projects this shouldn’t be an issue anymore. In CS2, it is assumed that most people will probably be piping CoffeeScript’s output through Babel or a similar transpiler; if Babel is used, the strict mode transform can be enabled to automatically prepend Closing, but willing to reopen if people can convince the maintainers that this is something CoffeeScript should handle. At this point we have very limited resources for development, so in general if there’s something that Babel can do for us, we want to offload that responsibility onto Babel (hence CS2 outputs ES2015 and leaves the ES2015-to-ES5 conversion to Babel). |
This will auto-add
'use strict';
to every coffeescript file if—bare
wasn't passed to options.Closes #2335.