Skip to content

compilation error with attribute access #3560

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

Closed
loveencounterflow opened this issue Jul 29, 2014 · 5 comments
Closed

compilation error with attribute access #3560

loveencounterflow opened this issue Jul 29, 2014 · 5 comments

Comments

@loveencounterflow
Copy link

i'm feeling a little bit stupid here but i really tried hard to make sure i'm not reporting a ghost. thing is, when i write

d[ 'a' ][ 'b' ][ 'c' ]

i get (using coffeescript 1.7.1 and coffee -c foo.coffee)

error: unexpected 'c'
d[ 'a' ][ 'b' ][ 'c' ]
                 ^^^

when i do the same on http://www.compileonline.com/try_coffeescript_online.php i get

main.coffee:2:18: error: unexpected STRING
d[ 'a' ][ 'b' ][ 'c' ]
                 ^^^

even worse,

x = d[ 'a' ][ 'b' ]
x[ 'c' ]

gives the same error. what's going on here?

@xyrius
Copy link

xyrius commented Jul 29, 2014

obj=
a:
b:
c: 'hi!'

console.log obj['a']['b']['c']

works fine for me on coffee 1.7.1

On Tue, Jul 29, 2014 at 12:31 PM, loveencounterflow <
[email protected]> wrote:

i'm feeling a little bit stupid here but i really tried hard to make sure
i'm not reporting a ghost. thing is, when i write

d[ 'a' ][ 'b' ][ 'c' ]

i get (using coffeescript 1.7.1 and coffee -c foo.coffee)

error: unexpected 'c'
d[ 'a' ][ 'b' ][ 'c' ]
^^^

when i do the same on
http://www.compileonline.com/try_coffeescript_online.php i get

main.coffee:2:18: error: unexpected STRING
d[ 'a' ][ 'b' ][ 'c' ]
^^^

even worse,

x = d[ 'a' ][ 'b' ]
x[ 'c' ]

gives the same error. what's going on here?


Reply to this email directly or view it on GitHub
#3560.

@loveencounterflow
Copy link
Author

i believe i found the culprit—it's a non-breaking space character that i had inadvertently inserted by hitting Altgr-Space instead of Space on my keyboard. you may verify that by copying and inspecting the [ 'c' ] part from the above code.

i still think it's a bug, because

  • writing d[ 'x' ] with U+00A0 instead of U+0020 for the first space character causes error: unexpected 'x' with CoffeeScript 1.7.1, but
  • d[ 0 ] does not cause an error.

this behavior is problematic because

  • it is inconsistent, and
  • the error message is misleading—if there is a problem with d[ 'x' ], it's the space character, not the string literal.

i suggest to either

  • make U+00A0 and U+0020 behave 100% identical, or
  • make U+00A0 illegal for indentation and inter-token spacing.

i favor the second solution: outside of string literals, indentation and spacing between tokens should only consist of U+0020; otherwise, an compile-time error with a message like 'illegal whitespace character found on line...' should be raised.

@Delapouite
Copy link

On a side note, if you're a vim user you could emphasise these guilty chars with something like :
set listchars=nbsp:•

lydell added a commit to lydell/coffee-script that referenced this issue Jan 6, 2015
It is possible to match only valid JavaScript identifiers with a really long
regex (like coco and CoffeeScriptRedux does), but CoffeeScript uses a much
simpler one, which allows a bit too much.

Quoting jashkenas#1718 #issuecomment-2152464 @jashkenas:

> But it still seems very much across the "worth it" line. You'll get the
> SyntaxError as soon as it hits JS, and performance aside -- even the increase
> in filesize for our browser coffee-script.js lib seems too much, considering
> this is something no one ever does, apart from experimentation.

In short, CoffeeScript treats any non-ASCII character as part of an identifier.
However, unicode spaces should be excluded since having blank characters as part
of a _word_ is very confusing. This commit does so, while still keeping the
regex really simple.
jashkenas added a commit that referenced this issue Jan 6, 2015
@lydell
Copy link
Collaborator

lydell commented Jan 15, 2015

Fixed by #3774.

@loveencounterflow
Copy link
Author

@Delapouite definitely helps, i found out using syntax hiliting in the editor.

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

No branches or pull requests

5 participants