Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c219adf

Browse files
committed
removing special rule from rewriter for naked functions in arrays
1 parent cd6dd5a commit c219adf

6 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
// The remainder of the source code.
8686
this.i = 0;
8787
// Current character position we're parsing.
88-
this.line = 1;
88+
this.line = 0;
8989
// The current line.
9090
this.indent = 0;
9191
// The current indent level.

lib/rewriter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
idx += 1;
253253
tok = this.tokens[idx];
254254
pre = this.tokens[idx - 1];
255-
if ((!tok || (SINGLE_CLOSERS.indexOf(tok[0]) >= 0 && tok[1] !== ';') || (pre[0] === ',' && tok[0] === 'PARAM_START') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
255+
if ((!tok || (SINGLE_CLOSERS.indexOf(tok[0]) >= 0 && tok[1] !== ';') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
256256
insertion = pre[0] === "," ? idx - 1 : idx;
257257
this.tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]);
258258
break;

src/lexer.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ exports.Lexer: class Lexer
115115
tokenize: (code) ->
116116
@code : code # The remainder of the source code.
117117
@i : 0 # Current character position we're parsing.
118-
@line : 1 # The current line.
118+
@line : 0 # The current line.
119119
@indent : 0 # The current indent level.
120120
@indents : [] # The stack of all indent levels we are currently within.
121121
@tokens : [] # Collection of all parsed tokens in the form ['TOKEN_TYPE', value, line]

src/rewriter.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ exports.Rewriter: class Rewriter
180180
pre: @tokens[idx - 1]
181181
if (not tok or
182182
(SINGLE_CLOSERS.indexOf(tok[0]) >= 0 and tok[1] isnt ';') or
183-
(pre[0] is ',' and tok[0] is 'PARAM_START') or
184183
(tok[0] is ')' && parens is 0)) and
185184
not (starter is 'ELSE' and tok[0] is 'ELSE')
186185
insertion: if pre[0] is "," then idx - 1 else idx

test/test_functions.coffee

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ ok y.x.name is 'x'
1414
() ->
1515

1616

17+
# Multiple nested function declarations mixed with implicit calls should not
18+
# cause a syntax error.
19+
(one) -> (two) -> three four, (five) -> six seven, eight, (nine) ->
20+
21+
1722
obj: {
1823
name: "Fred"
1924

@@ -70,7 +75,7 @@ ok result is 10
7075

7176
# And even with strange things like this:
7277

73-
funcs: [(x) -> x, (x) -> x * x]
78+
funcs: [((x) -> x), ((x) -> x * x)]
7479
result: funcs[1] 5
7580

7681
ok result is 25

test/test_literals.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
a: [(x) -> x, (x) -> x * x]
1+
a: [((x) -> x), ((x) -> x * x)]
22

33
ok a.length is 2
44

0 commit comments

Comments
 (0)