Skip to content
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

Object literals nest unexpectedly #1577

Closed
jed opened this issue Aug 5, 2011 · 7 comments
Closed

Object literals nest unexpectedly #1577

jed opened this issue Aug 5, 2011 · 7 comments

Comments

@jed
Copy link

jed commented Aug 5, 2011

I'd expect

a: b: c
1: 2: 3

to compile to

({
  a: {
    b: c
  },
  1: {
    2: 3
  }
});

but it compiles to

({
  a: {
    b: c,
    1: {
      2: 3
    }
  }
});

instead. Is there any reason for this?

Having an un-indented element beneath another would indicate that they'd be on the same level, not nested. Thoughts?

@wiemann
Copy link

wiemann commented Aug 5, 2011

+1

@TrevorBurnham
Copy link
Collaborator

This is intentional, because it means you can write

func
  option1: 'foo'
  option2: 'bar'

instead of

func {
    option1: 'foo'
    option2: 'bar'
  }

This supports the common idiom of functions taking a single hash as a last argument. (The same thing is done in Ruby, which is part of why its DSLs are so pretty.)

Edit: Hmm, ignore what I just said. I'd expect the same output as jed. It's really weird that

func
  a: b: c
  1: 2: 3

compiles to

func({
  a: {
    b: c,
    1: {
      2: 3
    }
  }
});

Maybe @michaelficarra can tell us if there's an existing issue on this...

@geraldalewis
Copy link
Contributor

#1116 ( and #1564, #1550 ). It's in the as soon as a patch is available milestone.

@michaelficarra
Copy link
Collaborator

@geraldalewis: beat me to it. Closing as duplicate of #1116.

edit:

as soon as a patch is available

Eh, I'm not so sure the discussion has reached agreement. I'll remove it from the milestone.

@jed
Copy link
Author

jed commented Aug 6, 2011

thank you, @geraldlewis and @michaelficarra, and sorry for the redundant issue (though it seems like it comes up enough that it might merit some attention).

@geraldalewis
Copy link
Contributor

@jed totally agree!

@jashkenas
Copy link
Owner

@jed et al ... this is now fixed on master, as a side effect of fixing #1903. You now get the expected compilation in the original post.

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

No branches or pull requests

6 participants