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

Allow calling functions with a bang! #2289

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/coffee-script/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/rewriter.coffee
Expand Up @@ -181,6 +181,11 @@ class exports.Rewriter
seenControl = no
noCall = no if tag in LINEBREAKS
token.call = yes if prev and not prev.spaced and tag is '?'

if tag is 'UNARY' and token[1] is '!' and prev? and prev[0] is 'IDENTIFIER' and not prev.spaced
callObject = true
tokens.splice i, 1

return 1 if token.fromThen
return 1 unless callObject or
prev?.spaced and (prev.call or prev[0] in IMPLICIT_FUNC) and
Expand Down
9 changes: 9 additions & 0 deletions test/function_invocation.coffee
Expand Up @@ -550,3 +550,12 @@ test "#960: improved 'do'", ->
eq two, 2
func
eq ret, func

test "bang calling a function", ->
class Foo
bar: -> 3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The evil TDD me keeps thinking this means that bar! only returns a 3. :-)


foo = new Foo()

eq 3, foo.bar!