Skip to content

Commit

Permalink
support libraries defined in a function passed as an argument to IIFE
Browse files Browse the repository at this point in the history
possible solution for #39
  • Loading branch information
dtao committed Jan 4, 2014
1 parent 9a0637c commit 7777a65
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autodoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
return [node.right];

case 'CallExpression':
return [node.callee];
return [node.callee].concat(node.arguments);

case 'ConditionalExpression':
return [node.consequent, node.alternate];
Expand Down
31 changes: 31 additions & 0 deletions example/genieTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function(root, factory) {

root.Genie = factory();

}(this, function() {

/**
* Does whatever.
*/
var Genie = {
/**
* Does something.
*/
foo: function() {},

/**
* Does something else.
*/
bar: function() {}
};

/**
* @private
*/
function baz() {

}

return Genie;

}));
17 changes: 16 additions & 1 deletion test/autodoc_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ describe 'Autodoc', ->
.findWhere({ shortName: shortName })
.name

listPrivateFunctions = (data) ->
Lazy(data.privateMembers)
.pluck('name')
.toArray()

describe '"helloWorld.js" example', ->
data = parseExampleFile('helloWorld.js')

Expand Down Expand Up @@ -153,8 +158,18 @@ describe 'Autodoc', ->
it 'respects the @memberOf tag for the purpose of naming functions', ->
getMemberName(data, 'parse').should.eql 'R.numbers.parse'

describe '"module.js example', ->
describe '"module.js" example', ->
data = parseExampleFile('module.js')

it 'takes reference name from the module.exports line, if there is one', ->
data.referenceName.should.eql 'Module'

describe 'a library defined in a function passed as a parameter to an IIFE', ->
data = parseExampleFile('genieTest.js')

# Not sure how else to describe this!
it 'is able to find the namespaces', ->
listNamespaces(data).should.eql ['Genie', '[private]']

it 'is able to find the private functions', ->
listPrivateFunctions(data).should.eql ['baz']

1 comment on commit 7777a65

@kentcdodds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this change manually to the node module does in fact fix my example. Thanks! Waiting for an update to the npm package.

Please sign in to comment.