Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const validNamepathParsing = function (namepath, tagName) {
try {
parse(namepath);
} catch (error) {
let handled = false;
if (tagName) {
if (['memberof', 'memberof!'].includes(tagName)) {
const endChar = namepath.slice(-1);
if (['#', '.', '~'].includes(endChar)) {
try {
parse(namepath.slice(0, -1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
} else if (tagName === 'borrows') {
const startChar = namepath.charAt();
source: originalComment,
content: [],
}
// strip the leading stars, if any
const commentContent = commentMatch[1].replace(leadingStarsRegex, '')
const re = jsDocTagRegex
let tagMatch: ReturnType
// get each part of each JSDoc tag
while ((tagMatch = re.exec(commentContent))) {
let type: any
try {
type = tagMatch[2] && jsdocTypeParse(tagMatch[2])
type.source = tagMatch[2]
} catch (e) {
type = tagMatch[2]
}
comment.content.push({
source: tagMatch[0],
tag: tagMatch[1],
type: type || undefined,
name: tagMatch[3],
description: (tagMatch[4] && tagMatch[4].trim()) || undefined,
})
}
comments.push(comment)
if (tagName) {
if (['memberof', 'memberof!'].includes(tagName)) {
const endChar = namepath.slice(-1);
if (['#', '.', '~'].includes(endChar)) {
try {
parse(namepath.slice(0, -1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
} else if (tagName === 'borrows') {
const startChar = namepath.charAt();
if (['#', '.', '~'].includes(startChar)) {
try {
parse(namepath.slice(1));
handled = true;
} catch (memberofError) {
// Use the original error for including the whole type
}
}
}
}
if (!handled) {
report(`Syntax error in namepath: ${namepath}`, null, tag);
return false;
}
}
return true;
jsdocTagsWithPossibleType.forEach((tag) => {
let parsedType;
try {
parsedType = parseType(tag.type);
} catch (error) {
// On syntax error, will be handled by valid-types.
return;
}
traverse(parsedType, ({type, name}) => {
if (type === 'NAME') {
if (!allDefinedTypes.includes(name)) {
report(`The type '${name}' is undefined.`, null, tag);
} else if (!_.includes(extraTypes, name)) {
context.markVariableAsUsed(name);
}
}
});
});
}, {
}
break;
case node instanceof TypeBuilder.RecordType:
// entries: Array.
node.typeName = 'Object';
res = cb(node) || [];
if (node.entries) {
res.concat(node.entries.map(function(subnode) {
subnode.parentElement = node;
_iterateDocTypes(subnode, cb);
}));
}
break;
case node instanceof TypeBuilder.RecordType.Entry:
// name: string,
// typeUnion: TypeUnion
node.typeUnion.collectionNode = node;
res = _iterateDocTypes(node.typeUnion, cb);
break;
case node instanceof TypeBuilder.ModuleName:
node.typeName = node.name;
node.module = true;
res = cb(node);
break;
default:
throw new Error('DocType: Unsupported doc node');
}
var assert = require('assert');
var commentParser = require('comment-parser');
var TypeParser = require('jsdoctypeparser').Parser;
var TypeBuilder = require('jsdoctypeparser').Builder;
var getNodeColumn = require('./utils').getNodeColumn;
var getLineInfo = require('./utils').getLineInfo;
// wtf but it needed to stop writing warnings to stdout
// and revert exceptions functionality
TypeBuilder.ENABLE_EXCEPTIONS = true;
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var PARSERS = {
tag: commentParser.PARSERS.parse_tag,
type: commentParser.PARSERS.parse_type,
description: commentParser.PARSERS.parse_description,
};
// jscs:enable
var RE_SPACE = /\s/;
// all: boolean,
// unknown: boolean,
// types: Array.
res = node.types.map(function(subnode) {
if (node.collectionNode) {
subnode.parentElement = node.collectionNode;
}
return _iterateDocTypes(subnode, cb);
}) || [];
if (node.nullable) {
var subnode = {typeName: 'null', collectionNode: node};
res.concat(cb(subnode));
}
break;
case node instanceof TypeBuilder.TypeName:
// name: string
node.typeName = node.name;
res = cb(node);
break;
case node instanceof TypeBuilder.GenericType:
// genericTypeName: string,
// parameterTypeUnions: Array.
node.typeName = node.genericTypeName.type;
res = cb(node) || [];
if (node.parameterTypeUnions) {
// node.parameterTypeUnions.collectionNode = node;
res.concat(node.parameterTypeUnions.map(function(subnode) {
subnode.parentElement = node;
_iterateDocTypes(subnode, cb);
}));
function _iterateDocTypes(node, cb) {
var res;
switch (true) {
case node instanceof TypeBuilder.TypeUnion:
// optional: boolean,
// nullable: boolean,
// variable: boolean,
// nonNullable: boolean,
// all: boolean,
// unknown: boolean,
// types: Array.
res = node.types.map(function(subnode) {
if (node.collectionNode) {
subnode.parentElement = node.collectionNode;
}
return _iterateDocTypes(subnode, cb);
}) || [];
if (node.nullable) {
var subnode = {typeName: 'null', collectionNode: node};
res.concat(cb(subnode));
jsdocTagsWithPossibleType.forEach((tag) => {
let parsedType;
try {
parsedType = parseType(tag.type);
} catch (error) {
// On syntax error, will be handled by valid-types.
return;
}
traverse(parsedType, ({type, name}) => {
if (type === 'NAME') {
if (!allDefinedTypes.includes(name)) {
report(`The type '${name}' is undefined.`, null, tag);
} else if (!_.includes(extraTypes, name)) {
context.markVariableAsUsed(name);
}
}
});
});
}, {
var assert = require('assert');
var commentParser = require('comment-parser');
var TypeParser = require('jsdoctypeparser').Parser;
var TypeBuilder = require('jsdoctypeparser').Builder;
var getNodeColumn = require('./utils').getNodeColumn;
var getLineInfo = require('./utils').getLineInfo;
// wtf but it needed to stop writing warnings to stdout
// and revert exceptions functionality
TypeBuilder.ENABLE_EXCEPTIONS = true;
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var PARSERS = {
tag: commentParser.PARSERS.parse_tag,
type: commentParser.PARSERS.parse_type,
description: commentParser.PARSERS.parse_description,
};
// jscs:enable
var RE_SPACE = /\s/;
module.exports = {
/**
* @param {string} commentNode
* @returns {DocComment}
*/