diff --git a/lib/cscodegen.js b/lib/cscodegen.js index 6387f36..b7b52ed 100644 --- a/lib/cscodegen.js +++ b/lib/cscodegen.js @@ -89,6 +89,8 @@ return needsParensWhenOnLeft(ast.expression); case 'FunctionApplication': return ast["arguments"].length > 0; + case 'Super': + return true; default: return false; } @@ -897,8 +899,23 @@ return "try\n" + (indent(_body)) + "\ncatch" + _catchAssg + _catchBody + _finally; case 'Super': options.ancestors = [ast].concat(__slice.call(options.ancestors)); - if (ast["arguments"]) { - return generate(new CS.FunctionApplication(new CS.Identifier('super'), ast["arguments"])); + if (ast["arguments"].length) { + args = (function() { + var _k, _len2, _ref15, _results; + _ref15 = ast["arguments"]; + _results = []; + for (i = _k = 0, _len2 = _ref15.length; _k < _len2; i = ++_k) { + a = _ref15[i]; + arg = generate(a, options); + if (((needsParensWhenOnLeft(a)) && i + 1 !== ast["arguments"].length) || (a.className === 'Function' && i === 0)) { + arg = parens(arg); + } + _results.push(arg); + } + return _results; + })(); + _argList = args.join(', '); + return "super " + _argList; } else { return 'super ...'; } diff --git a/src/cscodegen.coffee b/src/cscodegen.coffee index 3e0c7ce..a6ad12d 100644 --- a/src/cscodegen.coffee +++ b/src/cscodegen.coffee @@ -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) -> @@ -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 ...' diff --git a/test/classes.coffee b/test/classes.coffee index 4da847c..ea618c4 100644 --- a/test/classes.coffee +++ b/test/classes.coffee @@ -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', ->