forked from omarkhan/coffeedoc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getNodes and getFullName moved to helpers.coffee
- Loading branch information
Omar Khan
committed
Aug 4, 2011
1 parent
9ef1500
commit cc83ab7
Showing
6 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### | ||
AST helper functions | ||
==================== | ||
Useful functions for dealing with the CoffeeScript parse tree. | ||
### | ||
|
||
coffeescript = require('coffee-script') | ||
|
||
exports.getNodes = (script) -> | ||
### | ||
Generates the AST from coffeescript source code. Adds a 'type' attribute | ||
to each node containing the name of the node's constructor, and returns | ||
the expressions array | ||
### | ||
root_node = coffeescript.nodes(script) | ||
root_node.traverseChildren false, (node) -> | ||
node.type = node.constructor.name | ||
return root_node.expressions | ||
|
||
exports.getFullName = (variable) -> | ||
### | ||
Given a variable node, returns its full name | ||
### | ||
name = variable.base.value | ||
if variable.properties.length > 0 | ||
name += '.' + (p.name.value for p in variable.properties).join('.') | ||
return name | ||
|