diff --git a/lib/coffeescript/nodes.js b/lib/coffeescript/nodes.js index 914c85d8c5..fbf7458b1a 100644 --- a/lib/coffeescript/nodes.js +++ b/lib/coffeescript/nodes.js @@ -2150,14 +2150,14 @@ astProperties() { var arg; return { - callee: this.variable.toAst(), + callee: this.variable.ast(), arguments: (function() { var j, len1, ref1, results; ref1 = this.args; results = []; for (j = 0, len1 = ref1.length; j < len1; j++) { arg = ref1[j]; - results.push(arg.toAst()); + results.push(arg.ast()); } return results; }).call(this), diff --git a/lib/coffeescript/rewriter.js b/lib/coffeescript/rewriter.js index d28bca7a5d..e2af943ee4 100644 --- a/lib/coffeescript/rewriter.js +++ b/lib/coffeescript/rewriter.js @@ -911,13 +911,13 @@ // primitive string and separately passing any expected token data properties exposeTokenDataToGrammar() { return this.scanTokens(function(token, i) { - var key, ref, ref1, val; - if (token.data && Object.keys(token.data).length || token[0] === 'JS' && token.generated) { + var key, ref, ref1, ref2, val; + if (token.data && Object.keys(token.data).length || ((ref = token[0]) === 'JS' || ref === 'CALL_START') && token.generated) { token[1] = new String(token[1]); - ref1 = (ref = token.data) != null ? ref : {}; - for (key in ref1) { - if (!hasProp.call(ref1, key)) continue; - val = ref1[key]; + ref2 = (ref1 = token.data) != null ? ref1 : {}; + for (key in ref2) { + if (!hasProp.call(ref2, key)) continue; + val = ref2[key]; token[1][key] = val; } if (token.generated) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 6b02af4930..17cc2c926f 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1430,10 +1430,11 @@ exports.Call = class Call extends Base 'CallExpression' astProperties: -> - callee: @variable.toAst() - arguments: arg.toAst() for arg in @args - optional: !!@soak - implicit: !!@implicit + return + callee: @variable.ast() + arguments: arg.ast() for arg in @args + optional: !!@soak + implicit: !!@implicit #### Super diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 093f1968c1..c0e76b31fe 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -655,7 +655,7 @@ exports.Rewriter = class Rewriter # primitive string and separately passing any expected token data properties exposeTokenDataToGrammar: -> @scanTokens (token, i) -> - if token.data and Object.keys(token.data).length or token[0] is 'JS' and token.generated + if token.data and Object.keys(token.data).length or token[0] in ['JS', 'CALL_START'] and token.generated token[1] = new String token[1] token[1][key] = val for own key, val of (token.data ? {}) token[1].generated = yes if token.generated diff --git a/test/abstract_syntax_tree.coffee b/test/abstract_syntax_tree.coffee index 4015c0c093..ca472e3dea 100644 --- a/test/abstract_syntax_tree.coffee +++ b/test/abstract_syntax_tree.coffee @@ -270,47 +270,98 @@ test "AST as expected for BooleanLiteral node", -> # # Comments aren’t nodes, so they shouldn’t appear in the AST. -# test "AST as expected for Call node", -> -# testExpression 'fn()', -# type: 'Call' -# variable: -# value: 'fn' +test "AST as expected for Call node", -> + testExpression 'fn()', + type: 'CallExpression' + callee: + type: 'Identifier' + name: 'fn' + arguments: [] + optional: no + implicit: no -# testExpression 'new Date()', -# type: 'Call' -# variable: -# value: 'Date' -# isNew: yes + testExpression 'new Date()', + type: 'NewExpression' + callee: + type: 'Identifier' + name: 'Date' + arguments: [] + optional: no + implicit: no -# testExpression 'new Old', -# type: 'NewExpression' -# callee: -# type: 'Identifier' -# name: 'Old' + testExpression 'new Date?()', + type: 'NewExpression' + callee: + type: 'Identifier' + name: 'Date' + arguments: [] + optional: yes + implicit: no -# testExpression 'maybe?()', -# type: 'Call' -# soak: yes + testExpression 'new Old', + type: 'NewExpression' + callee: + type: 'Identifier' + name: 'Old' + arguments: [] + optional: no + implicit: no -# testExpression 'goDo this, that', -# type: 'Call' -# args: [ -# {value: 'this'} -# {value: 'that'} -# ] + testExpression 'new Old(1)', + type: 'NewExpression' + callee: + type: 'Identifier' + name: 'Old' + arguments: [ + type: 'NumericLiteral' + value: 1 + ] + optional: no + implicit: no -# testExpression 'do ->', -# type: 'Call' -# do: yes -# variable: -# type: 'Code' + testExpression 'new Old 1', + type: 'NewExpression' + callee: + type: 'Identifier' + name: 'Old' + arguments: [ + type: 'NumericLiteral' + value: 1 + ] + optional: no + implicit: yes -# testExpression 'do fn', -# type: 'Call' -# do: yes -# variable: -# type: 'IdentifierLiteral' -# value: 'fn' + testExpression 'maybe?()', + type: 'CallExpression' + optional: yes + implicit: no + + testExpression 'maybe?(1 + 1)', + type: 'CallExpression' + arguments: [ + type: 'BinaryExpression' + ] + optional: yes + implicit: no + + testExpression 'maybe? 1 + 1', + type: 'CallExpression' + arguments: [ + type: 'BinaryExpression' + ] + optional: yes + implicit: yes + + testExpression 'goDo this, that', + type: 'CallExpression' + arguments: [ + type: 'ThisExpression' + , + type: 'Identifier' + name: 'that' + ] + implicit: yes + optional: no # test "AST as expected for SuperCall node", -> # testExpression 'class child extends parent then constructor: -> super()', @@ -1076,6 +1127,13 @@ test "AST as expected for Op node", -> type: 'Identifier' name: 'x' + # testExpression 'do ->', + # type: 'UnaryExpression' + # operator: 'do' + # prefix: yes + # argument: + # type: 'FunctionExpression' + testExpression '!x', type: 'UnaryExpression' operator: '!' diff --git a/test/abstract_syntax_tree_location_data.coffee b/test/abstract_syntax_tree_location_data.coffee index 0e6bf9fc52..9bdb56c1a8 100644 --- a/test/abstract_syntax_tree_location_data.coffee +++ b/test/abstract_syntax_tree_location_data.coffee @@ -600,27 +600,168 @@ test "AST location data as expected for Op node", -> line: 1 column: 11 -# test "AST location data as expected for Call node", -> -# testAstLocationData 'new Old', -# type: 'NewExpression' -# callee: -# start: 4 -# end: 7 -# range: [4, 7] -# loc: -# start: -# line: 1 -# column: 4 -# end: -# line: 1 -# column: 7 -# start: 0 -# end: 7 -# range: [0, 7] -# loc: -# start: -# line: 1 -# column: 0 -# end: -# line: 1 -# column: 7 +test "AST location data as expected for Call node", -> + testAstLocationData 'fn()', + type: 'CallExpression' + start: 0 + end: 4 + range: [0, 4] + loc: + start: + line: 1 + column: 0 + end: + line: 1 + column: 4 + callee: + start: 0 + end: 2 + range: [0, 2] + loc: + start: + line: 1 + column: 0 + end: + line: 1 + column: 2 + + testAstLocationData 'new Date()', + type: 'NewExpression' + start: 0 + end: 10 + range: [0, 10] + loc: + start: + line: 1 + column: 0 + end: + line: 1 + column: 10 + callee: + start: 4 + end: 8 + range: [4, 8] + loc: + start: + line: 1 + column: 4 + end: + line: 1 + column: 8 + + testAstLocationData ''' + new Old( + 1 + ) + ''', + start: 0 + end: 14 + range: [0, 14] + loc: + start: + line: 1 + column: 0 + end: + line: 3 + column: 1 + type: 'NewExpression' + arguments: [ + start: 11 + end: 12 + range: [11, 12] + loc: + start: + line: 2 + column: 2 + end: + line: 2 + column: 3 + ] + + testAstLocationData 'maybe? 1 + 1', + type: 'CallExpression' + start: 0 + end: 12 + range: [0, 12] + loc: + start: + line: 1 + column: 0 + end: + line: 1 + column: 12 + arguments: [ + start: 7 + end: 12 + range: [7, 12] + loc: + start: + line: 1 + column: 7 + end: + line: 1 + column: 12 + ] + + testAstLocationData ''' + goDo(this, + that) + ''', + type: 'CallExpression' + start: 0 + end: 18 + range: [0, 18] + loc: + start: + line: 1 + column: 0 + end: + line: 2 + column: 7 + arguments: [ + start: 5 + end: 9 + range: [5, 9] + loc: + start: + line: 1 + column: 5 + end: + line: 1 + column: 9 + , + start: 13 + end: 17 + range: [13, 17] + loc: + start: + line: 2 + column: 2 + end: + line: 2 + column: 6 + ] + + testAstLocationData 'new Old', + type: 'NewExpression' + callee: + start: 4 + end: 7 + range: [4, 7] + loc: + start: + line: 1 + column: 4 + end: + line: 1 + column: 7 + start: 0 + end: 7 + range: [0, 7] + loc: + start: + line: 1 + column: 0 + end: + line: 1 + column: 7