Skip to content

Commit

Permalink
Fixes #1903
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Dec 15, 2011
1 parent ad39150 commit af0ee70
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
9 changes: 6 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.

6 changes: 5 additions & 1 deletion src/rewriter.coffee
Expand Up @@ -93,13 +93,15 @@ class exports.Rewriter
addImplicitBraces: ->
stack = []
start = null
startsLine = null
startIndent = 0
condition = (token, i) ->
[one, two, three] = @tokens[i + 1 .. i + 3]
return false if 'HERECOMMENT' is one?[0]
[tag] = token
(tag in ['TERMINATOR', 'OUTDENT'] and
not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':')) or
((!startsLine and @tag(i - 1) isnt ',') or
not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':'))) or
(tag is ',' and one and
one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT'])
action = (token, i) ->
Expand All @@ -118,6 +120,8 @@ class exports.Rewriter
stack.push ['{']
idx = if ago is '@' then i - 2 else i - 1
idx -= 2 while @tag(idx - 2) is 'HERECOMMENT'
prevTag = @tag(idx - 1)
startsLine = not prevTag or (prevTag in LINEBREAKS)
value = new String('{')
value.generated = yes
tok = ['{', value, token[2]]
Expand Down
19 changes: 19 additions & 0 deletions test/classes.coffee
Expand Up @@ -272,6 +272,25 @@ test "nothing classes", ->

c = class
ok c instanceof Function


test "classes with static-level implicit objects", ->

class A
@static = one: 1
two: 2

class B
@static = one: 1,
two: 2

eq A.static.one, 1
eq A.static.two, undefined
eq (new A).two, 2

eq B.static.one, 1
eq B.static.two, 2
eq (new B).two, undefined


test "classes with value'd constructors", ->
Expand Down
2 changes: 1 addition & 1 deletion test/objects.coffee
Expand Up @@ -157,7 +157,7 @@ test "invoking functions with implicit object literals", ->
b:1
eq undefined, result

result = getA b:1
result = getA b:1,
a:43
eq 43, result

Expand Down

0 comments on commit af0ee70

Please sign in to comment.