Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helixbass committed Oct 7, 2018
1 parent 67c47d0 commit fb2d0c0
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 72 deletions.
4 changes: 2 additions & 2 deletions lib/coffeescript/nodes.js

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

12 changes: 6 additions & 6 deletions lib/coffeescript/rewriter.js

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

9 changes: 5 additions & 4 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
128 changes: 93 additions & 35 deletions test/abstract_syntax_tree.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
Expand Down Expand Up @@ -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: '!'
Expand Down
Loading

0 comments on commit fb2d0c0

Please sign in to comment.