allowing chained calls broken up over multiple lines with periods at the front (jQuery-style)

This commit is contained in:
Jeremy Ashkenas 2010-01-09 12:12:38 -05:00
parent 7befbddae2
commit 2319affa61
2 changed files with 24 additions and 3 deletions

View File

@ -28,7 +28,7 @@ module CoffeeScript
COMMENT = /\A(((\n?[ \t]*)?#.*$)+)/
CODE = /\A(=>)/
REGEX = /\A(\/(.*?)([^\\]|\\\\)\/[imgy]{0,4})/
MULTI_DENT = /\A((\n([ \t]*)?)+)/
MULTI_DENT = /\A((\n([ \t]*))+)(\.)?/
LAST_DENT = /\n([ \t]*)/
ASSIGNMENT = /\A(:|=)\Z/
@ -139,7 +139,9 @@ module CoffeeScript
return false unless indent = @chunk[MULTI_DENT, 1]
@line += indent.scan(MULTILINER).size
@i += indent.size
return suppress_newlines(indent) if last_value.to_s.match(NO_NEWLINE) && last_value != "=>"
next_character = @chunk[MULTI_DENT, 4]
no_newlines = next_character == '.' || (last_value.to_s.match(NO_NEWLINE) && last_value != "=>")
return suppress_newlines(indent) if no_newlines
size = indent.scan(LAST_DENT).last.last.length
return newline_token(indent) if size == @indent
if size > @indent

View File

@ -2,4 +2,23 @@ identity_wrap: x => => x
result: identity_wrap(identity_wrap(true))()()
print(result)
print(result)
str: 'god'
result: str.
split('').
reverse().
reverse().
reverse()
print(result.join('') is 'dog')
result: str
.split('')
.reverse()
.reverse()
.reverse()
print(result.join('') is 'dog')