-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chainable methods with function multiinline as arguments #34
Comments
Using the latest CoffeeScript, this compiles just fine (despite looking like a mess) -- of course, you have to indent it correctly:
Compiles into:
Closing the ticket... |
Ah so you can't use the () in this case $('a').each() => $(this).css() $(this).css() $(this).css() .map() => $(this).attr('href') => syntax error fail |
Yeah, absolutely -- if you want to chain off a function, you'll have to enclose the call with parenthesis. I don't really think that your example should be able to compile. Chaining, block syntax, and significant whitespace don't mix too well. If it could, we could end up with ambiguous looking things like this:
Notice how that reverse is two blocks back. |
right, so is it correct that because of the way whitespace works differently to python, you can only close one block per line? |
No, you can close as many as you'd like. I just think that allowing the above example to compile is asking for trouble. If you're going to call a method on something, just visually speaking, you need to attach that period to the thing that you're calling, not just a level of indentation. Looking at the example, I would have a hard time figuring out what's being reversed. |
* The start of an artificial CSX call was the start of the tag name instead of the start of the `<`, so the range of the decaffeinate node was wrong. * The artificial `)` after a nested CSX tag was placed so that the end of the `)` is one after the end of the `>`. This made nested CSX tags one character too long, which broke some interpolation code in decaffeinate-parser. This is sort of a quick fix and I'll use tests in decaffeinate-parser to verify correctness. The first change also makes one of the CS error messages worse. There may be a more robust fix to these issues, but this seems to work for now.
i have see that isn't possible having chainable methods with function multiinline as arguments.
$("a").each(
=> $(this).css()
$(this).css()
$(this).css()
).
map(=> $(this).attr("href") ).
end()
this is compiled in this
(function(){$(this).css(), $ (this).css()).map(function() {
$("a").each(function() {
return $(this).css();
},
return $(this).attr("href");
}).end();
})();
and if i use the point for close the function in this mode:
$("a").each(
=> $(this).css()
$(this).css()
$(this).css()
.
).
map(=> $(this).attr("href") ).
end()
i have this error:
ine 5: syntax error for '.'
The text was updated successfully, but these errors were encountered: