Skip to content

Commit

Permalink
proper super compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gkz committed Oct 17, 2012
1 parent 33a9c7e commit 3c8e962
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
21 changes: 19 additions & 2 deletions lib/cscodegen.js

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

11 changes: 8 additions & 3 deletions src/cscodegen.coffee
Expand Up @@ -38,6 +38,7 @@ do (exports = exports ? this.cscodegen = {}) ->
when 'PreIncrementOp', 'PreDecrementOp', 'UnaryPlusOp', 'UnaryNegateOp', 'LogicalNotOp', 'BitNotOp', 'DoOp', 'TypeofOp', 'DeleteOp'
needsParensWhenOnLeft ast.expression
when 'FunctionApplication' then ast.arguments.length > 0
when 'Super' then yes
else no

eq = (nodeA, nodeB) ->
Expand Down Expand Up @@ -652,9 +653,13 @@ do (exports = exports ? this.cscodegen = {}) ->

when 'Super'
options.ancestors = [ast, options.ancestors...]
if ast.arguments
generate new CS.FunctionApplication (new CS.Identifier 'super'),
ast.arguments
if ast.arguments.length
args = for a, i in ast.arguments
arg = generate a, options
arg = parens arg if ((needsParensWhenOnLeft a) and i + 1 isnt ast.arguments.length) or (a.className is 'Function' and i is 0)
arg
_argList = args.join ', '
"super #{_argList}"
else
'super ...'

Expand Down
2 changes: 1 addition & 1 deletion test/classes.coffee
Expand Up @@ -10,7 +10,7 @@ suite 'Classes', ->
@this = new CS.This '@'

test 'super', ->
eq 'super ...', generate new CS.Super()
eq 'super ...', generate new CS.Super []
eq 'super x, y', generate new CS.Super [@x, @y]

test 'no bodied classes', ->
Expand Down

0 comments on commit 3c8e962

Please sign in to comment.