Skip to content
New issue

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

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

Already on GitHub? # to your account

Seriously inconsistent whitespace handling in objects #1957

Closed
nicolaskruchten opened this issue Dec 21, 2011 · 2 comments
Closed

Seriously inconsistent whitespace handling in objects #1957

nicolaskruchten opened this issue Dec 21, 2011 · 2 comments

Comments

@nicolaskruchten
Copy link

If you declare objects which contain values which are arrays declared on multiple lines, the way whitespace is interpreted is very inconsistent and leads to subtle bugs.

I'm trying to represent the following object in Javascript:

var myObject = {
  foo: {
    bar: {
      baz: ["hey"]
    },
    quux: "yo"
  }
};

The following code in CoffeeScript compiles as expected:

myObject =
    foo:
        bar:
            baz: [
                   "hey"
            ] #try indenting me!
        quux: "yo"

But depending on how far over you indent the final square-bracket (there are 9 possible legal positions in this case) you get one of three different compilation outputs: the correct one, one where 'quux' is at the same level as 'foo', and one where 'quux' is not included in the object at all!

Here's the most pathological one:

myObject =
    foo:
        bar:
            baz: [
                   "hey"
               ] #indent me!
        quux: "yo"

compiles to

var myObject;

myObject = {
  foo: {
    bar: {
      baz: ["hey"]
    }
  }
};

({
  quux: "yo"
});

I would say that the expected behaviour should be that all 9 valid positions of the final square bracket should result in the same, correct compile :)

Thanks!

@nicolaskruchten
Copy link
Author

Here's a YouTube video of the bug in action: http://www.youtube.com/watch?v=Mc9lVS7V5CE

@satyr
Copy link
Collaborator

satyr commented Dec 21, 2011

#1275

@satyr satyr closed this as completed Dec 21, 2011
@xixixao xixixao mentioned this issue Jan 22, 2014
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants