-
Notifications
You must be signed in to change notification settings - Fork 2k
Use Strict #2021
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 #2021
Conversation
Gorgeous work -- looking forward to reading through these. |
What's up with the backticks in the Cakefile? Isn't there another backtick-less way to fix 'em? |
Other than that -- looks good to me. The one thing that folks might want to look at is the possibility of cleaning up the |
@jashkenas thanks! You know, I may not need the backticks. If memory serves, octal escape sequences can be at most 3 chars long (after the |
With the patch, |
@paulmillr I <3 octal and Unix so I'm with you. with that API can you pass "0755" (quoted string)? /be |
@paulmillr I agree octal for file permissions is handy. However, you can use: fs.writeFile file, data, parseInt("0755"), callback or, if you know your code isn't going to be used with fs.writeFile file, data, `0755`, callback |
@jashkenas Agreed - I would love to hear feedback on |
@paulmillr |
@BrendanEich: We're taking most of these rules straight from the ES5 spec. What was the thought process of TC39 when deciding to disallow octal literals in strict mode code? Was this use case never discussed? @paulmillr: You should use |
@michaelficarra nice, |
@michaelficarra TC39 was split when octal was banned, but to be fair, the main problem is people write 08 and 09 and want decimal, more often than you might think. Less fair: buncha Unix haters! :-P /be |
|
Other than the issues that have already been discussed, this LGTM. I'm excited to finally get this in. @jashkenas: since this will introduce breaking changes, we should also bump the minor version to |
Sure. |
Great -- thanks guys! I'll pull together a revised commit sometime tomorrow. |
Not to get ahead of myself -- just a heads up -- this branch needs to be rebased before merging Big thanks to everyone for the review, and esp. @michaelficarra for the The diff for the change to I think I may propose that octals be allowed with Python-esque |
LGTM. @jashkenas: I'd be willing to squash/rebase these commits when this pull has your approval. |
FYI - I tried a rebase dry run earlier and I encountered a bug in git. Rebasing with the interactive flag fixed things, though. Happy to do it and push as a new branch if approved. |
One last small discussion to have before merging it: How would y'all (@michaelficarra, @geraldalewis, @satyr) feel about adding all of these errors, with the exception of leaving octal literals alone? Forbidding octal literals doesn't fix their true danger -- which is inside of It may not align quite as closely with where ES5 and 6 are heading, but there are some APIs designed around octal literals in ES3, which is what we're primarily concerned with here, and we should probably continue to support them. |
@jashkenas: I think that's a good idea. TC39 was split on the decision, but for us it seems more clear that different number representations are an appropriate sugar. |
I don't mind, but it'd be inconsistent to leave strict syntax errors.
|
I totally agree. I like @satyr 's suggestion of simply converting them to decimal. We could also require prepending 10 # decimal
0b10 # binary
0o10 # octal
0x10 # hexadecimal |
Whoa, Gerald's idea is pretty neat. It would be quite unexpected for folks coming from JavaScript ... but at the same time, we'd be able to give them a good syntax error, and it would be very clean and consistent. Perhaps |
I could live with |
I think that's a great idea --
I would say that for consistency's sake we aught to disallow them entirely in the |
Agreed. |
As a proof of concept, I created a new branch for octal literals. You can see the commits here. bin/coffee -bpe 'octal = 0o777' var octal;
octal = 511; ... bin/coffee -bpe 'octal = 0777'
**Note_: the Edit: Thanks for the link @michaelficarra :) |
A more helpful link: geraldalewis/coffee-script@strict...octals |
I will mail es-discuss about reviving octal literals. I expect some push-back based on O (uppercase O) being easily mistaken for 0, but it's not an issue if you require only lowercase o -- and anyway, using 007 instead of 0o7 or 0O7 would be caught at compile time with an early error. Haven't had time to look: does the patch mentioned here support both upper- and lowercase o? Hex supports X and x. /be |
@BrendanEich: maybe it would help es-discuss if you included a link to that PEP. Thanks for the link, @showell. The rationale in that PEP is both comprehensive and convincing. |
@michaelficarra already did ;-). /be |
A (gentle) ping for @jashkenas and @michaelficarra. Just making sure the most recent patch didn't get lost in Friday's backbone bloodbath ;) |
@geraldalewis: LGTM. 21 commits is a little ridiculous, though. Can you rebase off |
RegExp updated (thanks @michaelficarra) and hex escapes for colors in Cakefile tests updated (thanks @satyr) error message conforms to existing Lexer SyntaxErrors
…bj literals prohibited
…ibited updated error message (thanks @davidchambers) code style fixes
…iers prohibited
… 0o777 Allows octals in the form '0o777' and '0O777' Case insensitive Disallows decimals prefixed with '0'
I'm bothered by how none of the compiled JS is recognised as such by Github. @josh: is it because of our new "generated by" comment? @geraldalewis: LGTM. Thanks a bunch for tackling this issue. @jashkenas: Are you okay with merging this? |
@michaelficarra Thanks so much for all the help! Edit: nice -- thanks @josh! |
@michaelficarra fixed 7974d23 |
@josh: thanks |
I can't give it a thorough run through, but I'll take y'alls word for it. Go for the merge. |
Great! Thanks @jashkenas + @michaelficarra! |
fucking nice. can't wait for 1.3.0. |
I wanted to get the ball rolling on #1547 "CoffeeScript
use strict
".This patch does not enable
strict
mode. However, it does enforcestrict
mode's "early errors". These are sensible constraints that most JS devs adhere to anyway. As anecdotal evidence, almost no existing CoffeeScript compiler code needed to be rewritten to conform tostrict mode
.Each "early error" gets its own discrete patch. Most commits are only a line or two; this isn't as big a change as it may appear. This
pull
is in the early stages of development, and there are surely some edge cases to address and some code to clean up: my intention is to engender discussion on adopting what we can ofstrict
mode.The following are now considered errors. Links are provided to the relevant commit.
7.8.3 Numeric Literals
Commit 6a44f2c
B.1.2 String Literals
Commit 3fb064f
11.1.5 Object Initialiser
Commit b74efbf
11.4.1 The delete Operator
Commit 6bbc5ae
13 Function Definition (13.1 Strict Mode Restrictions)
Commit 6c9ded8
7.6.1.2 Future Reserved Words
Commit 696d873
eval
andarguments
restrictions12.14 The try Statement (12.14.1 Strict Mode Restrictions)
13 Function Definition (13.1 Strict Mode Restrictions)
11.13.1 Simple Assignment
11.3.1 Postfix Increment Operator
Commit 423f54d
Tests a9cfd06
Thanks!