Skip to content

Commit

Permalink
Call AST (#5117)
Browse files Browse the repository at this point in the history
* op ast

* test expected errors

* use new ast methods

* remove unused abstraction

* logical ?

* fix rebase

* follow convention

* fixes from code review

* test helper naming

* always convert new to Call

* new cases

* don't mutate locationData

* updated grammar

* tests

* Rebuild

* always expose generated

* todo for OptionalMemberExpression
  • Loading branch information
helixbass authored and GeoffreyBooth committed Oct 15, 2018
1 parent e934a42 commit fe7377a
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 78 deletions.
1 change: 1 addition & 0 deletions lib/coffeescript/grammar.js

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

28 changes: 28 additions & 0 deletions lib/coffeescript/nodes.js

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

30 changes: 18 additions & 12 deletions lib/coffeescript/parser.js

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

2 changes: 1 addition & 1 deletion lib/coffeescript/rewriter.js

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

8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ grammar =
# The list of arguments to a function call.
Arguments: [
o 'CALL_START CALL_END', -> []
o 'CALL_START ArgList OptComma CALL_END', -> $2
o 'CALL_START ArgList OptComma CALL_END', -> $2.implicit = $1.generated; $2
]

# A reference to the *this* current object.
Expand Down
14 changes: 14 additions & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ exports.Call = class Call extends Base
constructor: (@variable, @args = [], @soak, @token) ->
super()

@implicit = @args.implicit
@isNew = no
if @variable instanceof Value and @variable.isNotCallable()
@variable.error "literal is not a function"
Expand Down Expand Up @@ -1426,6 +1427,19 @@ exports.Call = class Call extends Base
fragments.push @makeCode(' />')
fragments

astType: ->
if @isNew
'NewExpression'
else
'CallExpression'

astProperties: ->
return
callee: @variable.ast()
arguments: arg.ast() for arg in @args
optional: !!@soak
implicit: !!@implicit

#### Super

# Takes care of converting `super()` calls into calls against the prototype's
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.generated or (token.data and Object.keys(token.data).length isnt 0)
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
Loading

0 comments on commit fe7377a

Please sign in to comment.