diff --git a/index.js b/index.js index 5c5de13..4a8d666 100644 --- a/index.js +++ b/index.js @@ -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'; diff --git a/test/test.js b/test/test.js index 41a89dc..a14583a 100644 --- a/test/test.js +++ b/test/test.js @@ -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();