Skip to content

Commit

Permalink
fixed #81
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Aug 15, 2011
1 parent 95bafa5 commit 239d943
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions extras/coco.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coco.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parser.lexer = {
return '';
}
};
exports.VERSION = '0.6.0';
exports.VERSION = '0.6.1b';
exports.compile = function(code, options){
var that;
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function addImplicitIndentation(tokens){
case next !== ',' && next !== 'DOT':
--i;
// fallthrough
case ',' !== ((_ref = tokens[i + 2]) != null ? _ref[0] : void 8):
case !((next === 'ID' || next === 'STRNUM' || next === 'LITERAL' || next === 'SUPER') && ',' === ((_ref = tokens[i + 2]) != null ? _ref[0] : void 8)):
go(0, i += 2);
++i;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/coco.co
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ parser import
upcomingInput : -> ''

exports import
VERSION: \0.6.0
VERSION: \0.6.1b

# Compiles a string of Coco code to JavaScript.
compile: (code, options) ->
Expand Down
12 changes: 8 additions & 4 deletions src/rewriter.co
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ function addImplicitIndentation tokens
else
tokens.splice ++i, 0 indent
switch
case next of <[ , DOT ]> then --i; fallthrough # ->,
case \, is tokens[i+2]?0 then go 0 i+=2; ++i # -> 0,
case next of <[ ( [ { ]> and # -> [0],
\, is tokens[idx = 1 + indexOfPair tokens, i+1]?0
# ->,
case next of <[ , DOT ]> then --i; fallthrough
# -> 0,
case next of <[ ID STRNUM LITERAL SUPER ]> and \, is tokens[i+2]?0
go 0 i+=2; ++i
# -> [0],
case next of <[ ( [ { ]>
and \, is tokens[idx = 1 + indexOfPair tokens, i+1]?0
go 0 idx; ++i
default
seenSwitch = false
Expand Down
18 changes: 6 additions & 12 deletions test/function.co
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ result = I( ->
eq result()(), 'Wrapped'


funcs = [(x) -> x, (x) -> x * x]
eq 25, funcs[0] funcs.1 5


eq 'lo', ("hello".slice) 3


Expand Down Expand Up @@ -244,14 +240,12 @@ eq '''
''', Coco.compile '-> @it', {+bare}


# Bare single line functions are closed by commas.
fn = (count, ...fns) -> eq count, fns.length
fn 2, ->, ->
fn 3, ->, ->, ->
fn 2, -> value, -> value
eq 2, [-> value, -> value].length
numbers = one: -> 1, two: -> 2
funcs = one: -> [-> 1, three: 3], two: -> 2
# Simple functions require no parens when comma-listed.
funs = [->, -> 1, -> it, -> this, null]
eq 1, +funs.3.call funs.2 funs.1()

# [#81](https://github.com/satyr/coco/issues/81)
ok I(->), 'be careful when specialcasing `-> X ,`'


eq 0, (new do -> Array).length
Expand Down

0 comments on commit 239d943

Please sign in to comment.