Skip to content

Commit 9504515

Browse files
add IINFE support (do fn = -> ...); fixes #43 and #73
1 parent 9b67b5f commit 9504515

File tree

5 files changed

+130
-34
lines changed

5 files changed

+130
-34
lines changed

lib/coffee-script/compiler.js

Lines changed: 25 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/parser.js

Lines changed: 87 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler.coffee

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,17 +823,22 @@ class exports.Compiler
823823
new JS.BinaryExpression '&&', typeofTest, nullTest
824824
else nullTest
825825
]
826-
[CS.DoOp, ({expression, compile}) ->
827-
args = []
828-
if @expression.instanceof CS.Function
829-
args = for param, index in @expression.parameters
826+
[CS.DoOp, do ->
827+
deriveArgsFromParams = (params) ->
828+
args = for param, index in params
830829
switch
831830
when param.instanceof CS.DefaultParam
832-
@expression.parameters[index] = param.param
831+
params[index] = param.param
833832
param.default
834833
when param.instanceof CS.Identifier, CS.MemberAccessOp then param
835834
else helpers.undef()
836-
compile new CS.FunctionApplication @expression, args
835+
({expression, compile}) ->
836+
args = []
837+
if (@expression.instanceof CS.AssignOp) and @expression.expression.instanceof CS.Function
838+
args = deriveArgsFromParams @expression.expression.parameters
839+
else if @expression.instanceof CS.Function
840+
args = deriveArgsFromParams @expression.parameters
841+
compile new CS.FunctionApplication @expression, args
837842
]
838843
[CS.Return, ({expression: e}) -> new JS.ReturnStatement expr e]
839844
[CS.Break, -> new JS.BreakStatement]

src/grammar.pegjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ prefixExpression
370370
/ "-" ws:_ e:(expressionworthy / prefixExpression) { return new CS.UnaryNegateOp(e).r('-' + ws + e.raw).p(line, column, offset); }
371371
/ o:("!" / NOT) ws:_ e:(expressionworthy / prefixExpression) { return new CS.LogicalNotOp(e).r(o + ws + e.raw).p(line, column, offset); }
372372
/ "~" ws:_ e:(expressionworthy / prefixExpression) { return new CS.BitNotOp(e).r('~' + ws + e.raw).p(line, column, offset); }
373+
/ DO ws0:_ !unassignable a:identifier ws1:_ "=" ws2:_ f:functionLiteral {
374+
return new CS.DoOp(new CS.AssignOp(a, f)).r('do' + ws0 + a.raw + ws1 + '+' + ws2 + f.raw).p(line, column, offset);
375+
}
373376
/ DO ws:_ e:(expressionworthy / prefixExpression) { return new CS.DoOp(e).r('do' + ws + e.raw).p(line, column, offset); }
374377
/ TYPEOF ws:_ e:(expressionworthy / prefixExpression) { return new CS.TypeofOp(e).r('typeof' + ws + e.raw).p(line, column, offset); }
375378
/ DELETE ws:_ e:(expressionworthy / prefixExpression) { return new CS.DeleteOp(e).r('delete' + ws + e.raw).p(line, column, offset); }

test/function-invocation.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ suite 'Function Invocation', ->
454454
eq two, 2
455455
eq three, 3
456456

457-
#ret = do func = (two) ->
458-
# eq two, 2
459-
# func
460-
#eq ret, func
457+
ret = do func = (two) ->
458+
eq two, 2
459+
func
460+
eq ret, func
461461

462462
test "soaked function application", ->
463463
nonce = {}

0 commit comments

Comments
 (0)