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
indented property access bug #1435
Comments
Can you come up with a more minimal test case so that it's easier to reason about this? Or is this already a minimal case? Also, more-than-2 space indentation would be easier to read. But that's just my preference. |
I was able to reduce it by 1 call. So does moving |
It looks like you're indenting the property accesses when there's no need to do so. Try this instead: jQuery ($) -> foo() .bind -> bar() .baz 'click', -> foobar() .bar() THIS_IS_COMPILED_INSIDE_JQUERY$("Oh yes!") |
Hmm. As Michael says, the stylistically and semantically correct thing to do is to unindent Another interesting observation: If, in the original example, you indent the last line with 6 spaces, you'll get the desired behavior. Any fewer than that, and you get the given bug. If you indent it with 8 spaces, then the line will be in the This is pretty alarming, and gives us a simpler problem case:
compiles to
Seems to me that this should be an
is. |
I disagree with this being stylistically correct. From jQuery documentation: http://api.jquery.com/end/ $('ul.first').find('.foo')
.css('background-color', 'red')
.end().find('.bar')
.css('background-color', 'green')
.end(); From Underscore.js documentation: http://documentcloud.github.com/underscore/ _(lyrics).chain()
.map(function(line) { return line.words.split(' '); })
.flatten()
.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {}).value(); From SproutCore style guide: http://guides.sproutcore.com/style_guide.html return this.get('content')
.getEach('prefix','firstName','middleName',
'lastName','suffix')
.join(' '); There are quite a few reasons on how and why this became a standard in JavaScript. First, nesting lets you clearly indicate which object you are working on: $("#elem1")
.show()
.find(".tab")
.addClass(".active")
.find(".closeButton")
.show()
vs
$("#elem1")
.show()
.find(".tab")
.addClass(".active")
.find(".closeButton")
.show() Second, nesting prevents confusion of this sort mainly: ab()
.b()
.c()
aa()
vs
ab()
.b()
.c()
aa() I am sure one can come up with more reasons if you still don't feel convinced. |
Formattings of this kind appear in test/function_invocation--they are expected to work. |
Excerpt from https://github.com/jashkenas/coffee-script/blob/1.1.1/test/function_invocation.coffee#L198 test "Chained blocks, with proper indentation levels:", ->
counter =
results: []
tick: (func) ->
@results.push func()
this
counter
.tick ->
3
.tick ->
2
.tick ->
1
arrayEq [3,2,1], counter.results |
Fix #1435 by amending away sign reversal.
Took me hours to debug a problem that turned out to be a coffeescript bug:
Found a very evil nesting bug:
coffee v1.1.1 output:
The text was updated successfully, but these errors were encountered: