Code coverage report for lib/parse.js

Statements: 100% (16 / 16)      Branches: 100% (2 / 2)      Functions: 100% (1 / 1)      Lines: 100% (16 / 16)      Ignored: none     

All files » lib/ » parse.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51    36                             36 331                     331 331 331   331 331 466 466 3 6   3   463       331     36  
'use strict';
 
var doctrine = require('doctrine'),
  flatten = require('./flatten'),
  normalize = require('./normalize');
 
/**
 * Parse a comment with doctrine, decorate the result with file position and code
 * context, handle parsing errors, and fix up various infelicities in the structure
 * outputted by doctrine.
 *
 * @param {string} comment input to be parsed
 * @param {Object} loc location of the input
 * @param {Object} context code context of the input
 * @return {Object} an object conforming to the
 * [documentation JSON API](https://github.com/documentationjs/api-json) schema
 */
function parseJSDoc(comment, loc, context) {
  var result = doctrine.parse(comment, {
    // have doctrine itself remove the comment asterisks from content
    unwrap: true,
    // enable parsing of optional parameters in brackets, JSDoc3 style
    sloppy: true,
    // `recoverable: true` is the only way to get error information out
    recoverable: true,
    // include line numbers
    lineNumbers: true
  });
 
  result.loc = loc;
  result.context = context;
  result.errors = [];
 
  var i = 0;
  while (i < result.tags.length) {
    var tag = result.tags[i];
    if (tag.errors) {
      for (var j = 0; j < tag.errors.length; j++) {
        result.errors.push({message: tag.errors[j]});
      }
      result.tags.splice(i, 1);
    } else {
      i++;
    }
  }
 
  return flatten(normalize(result));
}
 
module.exports = parseJSDoc;