Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ module.exports = function(file, callback) {
/**
* Determine the module type from an AST node
*
* @param {Object} node
* @return {String | null}
* @param {Object|null|undefined} node
* @return {String|null}
*/
function fromAST(node) {
if (!node) return null;

if (types.isNamedForm(node)) return 'named';
if (types.isDependencyForm(node)) return 'deps';
if (types.isREMForm(node)) return 'rem';
Expand Down
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ fromSourceTests('should throw an error if an argument is missing', () => {
});

fromSourceTests.run();

const fromASTTests = suite('From AST tests');

fromASTTests('returns null for a null node', () => {
assert.equal(getType.fromAST(null), null);
});

fromASTTests('returns null for an undefined node', () => {
assert.equal(getType.fromAST(undefined), null);
});

fromASTTests.run();
Loading