-
Notifications
You must be signed in to change notification settings - Fork 2k
Parser trips on hard tabs with misleading error message: Unexpected '{' #2141
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
Comments
Mixed spaces and tabs should be disallowed by #1275 anyway. |
how about an immediate syntax error when any tabs are encountered at all in the entire file? |
Why? Tabs are valid indentation characters. It's the mixing of tabs and spaces that is the problem. |
It's highly recommended to use 2-spaces for indentation in coffee-script, correct? Why not enforce it at the compiler level? It would simplify everybody's lives, including the compiler. |
Some people like tabs. We shouldn't disallow tabs if they're used consistently and unambiguously. Tabs are not evil. Just don't mix spaces/tabs. Or get a text editor smart enough to tell you when there's a problem or just handle the indentation for you. |
Some people like mixing tabs and spaces too. I don't care either way, I just want it to be enforced so I don't have to deal with more than one style. It's a pretty radical idea though, probably not a good idea for Coffee-Script's goals, so I'll drop it. |
So -- spaces and tabs can be mixed ... if you use the same number of them for each level of indentation. Your example above does not do this, hence the indentation error. CoffeeScript just counts tabs and counts spaces -- you can't possibly expect it to guess how wide your text editor is configured to visually show tab characters. |
This issue is not that the examples should compile. This issue is that the error message is not helpful. |
It turns out that the tabs vs. spaces is not even relevant, and the misleading parser error comes even with pure spaces. I agree with the closure of this (my) issue, because there is now too much noise in here. Based on jashkenas explanation of how tabs are treated, I've reproduced the behavior (bad error message) using only spaces, and filed a new issue. Please see now #2144. |
Presence of hard tabs in certain places in .coffee source causes confusing and irrelevant parser error: Unexpected '{'
Tested with v1.2.0.
Specifically see example when object property line with tab is followed by regularly space-indented property line ("Test 2" below).
Test case with proper tabs preserved: http://pastebin.ca/2121616
Or test case inline below, but github converted the tab character to spaces, so you must convert it back yourself:
The text was updated successfully, but these errors were encountered: