Skip to content

Commit

Permalink
Fixes #1813
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Dec 15, 2011
1 parent 510fb59 commit 121009d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/coffee-script/rewriter.js

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

4 changes: 2 additions & 2 deletions src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ class exports.Rewriter
condition = (token, i) ->
[tag] = token
return yes if not seenSingle and token.fromThen
seenSingle = yes if tag in ['IF', 'ELSE', 'CATCH', '->', '=>']
seenSingle = yes if tag in ['IF', 'ELSE', 'CATCH', '->', '=>', 'CLASS']
seenControl = yes if tag in ['IF', 'ELSE', 'SWITCH', 'TRY', '=']
return yes if tag in ['.', '?.', '::'] and @tag(i - 1) is 'OUTDENT'
not token.generated and @tag(i - 1) isnt ',' and (tag in IMPLICIT_END or
(tag is 'INDENT' and not seenControl)) and
(tag isnt 'INDENT' or
(@tag(i - 2) isnt 'CLASS' and @tag(i - 1) not in IMPLICIT_BLOCK and
(@tag(i - 2) not in ['CLASS', 'EXTENDS'] and @tag(i - 1) not in IMPLICIT_BLOCK and
not ((post = @tokens[i + 1]) and post.generated and post[0] is '{')))

action = (token, i) ->
Expand Down
12 changes: 12 additions & 0 deletions test/classes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,16 @@ test "#1876: Class @A extends A", ->
class @A extends A

ok (new @A) instanceof A

test "#1813: Passing class definitions as expressions", ->
ident = (x) -> x

result = ident class A then x = 1

eq result, A

result = ident class B extends A
x = 1

eq result, B

0 comments on commit 121009d

Please sign in to comment.