How to use the doctrine.parse function in doctrine

To help you get started, we’ve selected a few doctrine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github photonstorm / phaser / v3 / comments.js View on Github external
"name": "type",
        "value": "type",
        "string": "this.type"
      },
      "value": "this.type = type;\r",
      "line": 44,
      "loc": { "start": { "line": 44, "column": 1424 }, "end": { "line": 44, "column": 1442 } }
    }
  },
*/

    for (var i = 0; i < blocks.length; i++)
    {
        var block = blocks[i];

        comments.push(doctrine.parse(block.value, doctrineOptions));
    }

    // comments = JSON.stringify(comments);
    comments = beautify(comments, null, 2, 100); // just for debugging really
    // comments = beautify(blocks, null, 2, 100); // just for debugging really

    fs.writeFile(dest, comments, { encoding: 'utf8', flag: 'w' }, function (error) {

        if (error)
        {
            throw error;
        }
        else
        {
            console.log('Comments written');
        }
github teppeis / fixclosure / lib / parser.js View on Github external
return comments.filter(comment => {
    if (isCommentBlock(comment) && /^\*/.test(comment.value)) {
      const jsdoc = doctrine.parse(`/* ${comment.value}*/`, { unwrap: true });
      return (
        jsdoc.tags.some(tag => tag.title === "typedef") &&
        !jsdoc.tags.some(tag => tag.title === "private")
      );
    }
    return false;
  });
};
github sghall / resonance / docs / app / components / PropTypeDescription / index.js View on Github external
function generateDescription(required, description, type) {
  let deprecated = '';

  if (type.name === 'custom') {
    const deprecatedInfo = getDeprecatedInfo(type);

    if (deprecatedInfo) {
      deprecated = `*Deprecated*. ${deprecatedInfo.explanation}<br><br>`;
    }
  }

  const parsed = parseDoctrine(description);

  // two new lines result in a newline in the table. all other new lines
  // must be eliminated to prevent markdown mayhem.
  const jsDocText = parsed.description.replace(/\n\n/g, '<br>').replace(/\n/g, ' ');

  if (parsed.tags.some((tag) =&gt; tag.title === 'ignore')) return null;
  let signature = '';

  if (type.name === 'func' &amp;&amp; parsed.tags.length &gt; 0) {
    // Remove new lines from tag descriptions to avoid markdown errors.
    parsed.tags.forEach((tag) =&gt; {
      if (tag.description) {
        tag.description = tag.description.replace(/\n/g, ' ');
      }
    });
github Polymer / tools / packages / analyzer / src / javascript / jsdoc.ts View on Github external
export function parseJsdoc(docs: string): doctrine.Annotation {
  docs = removeLeadingAsterisks(docs);
  const d = doctrine.parse(docs, {
    unwrap: false,
    // lineNumbers: true,
    preserveWhitespace: true,
  });
  // Strip any leading and trailing newline characters in the
  // description of multiline comments for readibility.
  // TODO(rictic): figure out if we can trim() here or not. Something something
  //     markdown?
  const description = d.description && d.description.replace(/^\n+|\n+$/g, '');
  return {description, tags: parseCustomTags(d.tags)};
}
github propertybase / react-lds / docs / src / app / components / PropTypeDescription / index.js View on Github external
function generateDescription(required, description, type) {
  let deprecated = '';

  if (type.name === 'custom') {
    const deprecatedInfo = getDeprecatedInfo(type);

    if (deprecatedInfo) {
      deprecated = `*Deprecated*. ${deprecatedInfo.explanation}<br><br>`;
    }
  }

  const parsed = parseDoctrine(description);

  // two new lines result in a newline in the table. all other new lines
  // must be eliminated to prevent markdown mayhem.
  const jsDocText = parsed.description.replace(/\n\n/g, '<br>').replace(/\n/g, ' ');

  if (parsed.tags.some(tag =&gt; tag.title === 'ignore')) return null;
  let signature = '';

  if (type.name === 'func' &amp;&amp; parsed.tags.length &gt; 0) {
    // Remove new lines from tag descriptions to avoid markdown errors.
    parsed.tags = parsed.tags.map((tag) =&gt; {
      if (tag.description) {
        return tag.description.replace(/\n/g, ' ');
      }

      return tag;
github mui-org / material-ui / docs / src / modules / utils / generateMarkdown.js View on Github external
function generatePropDescription(prop) {
  const { description } = prop;
  const type = prop.flowType || prop.type;
  let deprecated = '';

  if (type.name === 'custom') {
    const deprecatedInfo = getDeprecatedInfo(type);
    if (deprecatedInfo) {
      deprecated = `*Deprecated*. ${deprecatedInfo.explanation}<br><br>`;
    }
  }

  const parsed = parseDoctrine(description, {
    sloppy: true,
  });

  // Two new lines result in a newline in the table.
  // All other new lines must be eliminated to prevent markdown mayhem.
  const jsDocText = escapeCell(parsed.description)
    .replace(/(\r?\n){2}/g, '<br>')
    .replace(/\r?\n/g, ' ');

  if (parsed.tags.some(tag =&gt; tag.title === 'ignore')) {
    return null;
  }

  let signature = '';

  if (type.name === 'func' &amp;&amp; parsed.tags.length &gt; 0) {
github styleguidist / react-styleguidist / src / loaders / utils / getProps.js View on Github external
Object.keys(doc.props).forEach(propName => {
			const prop = doc.props[propName];
			const doclets = getDocletsObject(prop.description);

			// When a prop is listed in defaultProps but not in props the prop.description is undefined
			const documentation = doctrine.parse(prop.description || '');

			// documentation.description is the description without tags
			doc.props[propName].description = documentation.description;
			doc.props[propName].tags = getDoctrineTags(documentation);

			// Remove ignored props
			if (doclets && doclets.ignore) {
				delete doc.props[propName];
			}
		});
	}
github algolia / react-instantsearch / docgen / plugins / inlineProps / DocProps.js View on Github external
function Prop(props) {
  const {prop, prefix} = props;

  const {description, tags} = doctrine.parse(prop.description || '');

  const isPublic = tags.some(tag => tag.title === 'public');

  if (!isPublic) {
    return null;
  }

  const defines = tags.find(tag => tag.title === 'defines');
  const typeNames = defines ? defines.description.split(' ') : [];
  const shapes = getShapes(prop.type, prop.name);

  const namedTypes = typeNames.map((name, i) => ({
    name,
    type: shapes[i].type,
  }));
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / depAnalyzer.js View on Github external
tree.comments.forEach(function (comment) {
    if (isFileOrClassScopeComment(comment, topLevelCodeUnitLines)) {
      var jsdoc = doctrine.parse(comment.value, { unwrap: true });
      jsdoc.tags.forEach(function (tag) {
        switch(tag.title) {
          case 'ignore':
            atHints.ignore = atHints.ignore.concat(getClassesFromTagDesc(tag.description));
            break;
          case 'require':
            atHints.require = atHints.require.concat(getClassesFromTagDesc(tag.description));
            break;
          case 'use':
            atHints.use = atHints.use.concat(getClassesFromTagDesc(tag.description));
            break;
          case 'asset':
            atHints.asset = atHints.asset.concat(getResourcesFromTagDesc(tag.description));
            break;
          case 'cldr':
            atHints.cldr = true;
github teambit / bit / src / bit-fs / bit-fs.js View on Github external
static loadBitMeta(name: string, bitContents: string) {
    const ast = esprima.parse(bitContents, {
      loc: true,  
      tolerant: true,
      attachComment: true
    });
    
    const rawDocs = ast.body[0].leadingComments[0].value;
    const docs = doctrine
      .parse(rawDocs, { unwrap: true })
      .tags.reduce(function (previousValue, currentValue) {
        previousValue[currentValue.title] = currentValue.description || currentValue.name;
        return previousValue;
      }, {});
    
    return {
      name: docs.name,
      version: docs.version,
      env: docs.env,
      dependencies: docs.dependencies,
      sig: docs.sig,
      examples: docs.example
    };
  }