122 lines
4.1 KiB
JavaScript
122 lines
4.1 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getJSDocDescription = getJSDocDescription;
|
|
exports.getJSDocComment = getJSDocComment;
|
|
exports.getJSDocComments = getJSDocComments;
|
|
exports.getJSDocTagNames = getJSDocTagNames;
|
|
exports.getJSDocTags = getJSDocTags;
|
|
exports.isExistJSDocTag = isExistJSDocTag;
|
|
exports.commentToString = commentToString;
|
|
const ts = __importStar(require("typescript"));
|
|
const exceptions_1 = require("../metadataGeneration/exceptions");
|
|
function getJSDocDescription(node) {
|
|
const jsDocs = node.jsDoc;
|
|
if (!jsDocs || !jsDocs.length) {
|
|
return undefined;
|
|
}
|
|
return commentToString(jsDocs[0].comment) || undefined;
|
|
}
|
|
function getJSDocComment(node, tagName) {
|
|
const comments = getJSDocComments(node, tagName);
|
|
if (comments && comments.length !== 0) {
|
|
return comments[0];
|
|
}
|
|
return;
|
|
}
|
|
function getJSDocComments(node, tagName) {
|
|
const tags = getJSDocTags(node, tag => tag.tagName.text === tagName || tag.tagName.escapedText === tagName);
|
|
if (tags.length === 0) {
|
|
return;
|
|
}
|
|
const comments = [];
|
|
tags.forEach(tag => {
|
|
const comment = commentToString(tag.comment);
|
|
if (comment)
|
|
comments.push(comment);
|
|
});
|
|
return comments;
|
|
}
|
|
function getJSDocTagNames(node, requireTagName = false) {
|
|
let tags;
|
|
if (node.kind === ts.SyntaxKind.Parameter) {
|
|
const parameterName = node.name.text;
|
|
tags = getJSDocTags(node.parent, tag => {
|
|
if (ts.isJSDocParameterTag(tag)) {
|
|
return false;
|
|
}
|
|
else if (tag.comment === undefined) {
|
|
throw new exceptions_1.GenerateMetadataError(`Orphan tag: @${String(tag.tagName.text || tag.tagName.escapedText)} should have a parameter name follows with.`);
|
|
}
|
|
return commentToString(tag.comment)?.startsWith(parameterName) || false;
|
|
});
|
|
}
|
|
else {
|
|
tags = getJSDocTags(node, tag => {
|
|
return requireTagName ? tag.comment !== undefined : true;
|
|
});
|
|
}
|
|
return tags.map(tag => {
|
|
return tag.tagName.text;
|
|
});
|
|
}
|
|
function getJSDocTags(node, isMatching) {
|
|
const jsDocs = node.jsDoc;
|
|
if (!jsDocs || jsDocs.length === 0) {
|
|
return [];
|
|
}
|
|
const jsDoc = jsDocs[0];
|
|
if (!jsDoc.tags) {
|
|
return [];
|
|
}
|
|
return jsDoc.tags.filter(isMatching);
|
|
}
|
|
function isExistJSDocTag(node, isMatching) {
|
|
const tags = getJSDocTags(node, isMatching);
|
|
if (tags.length === 0) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function commentToString(comment) {
|
|
if (typeof comment === 'string') {
|
|
return comment;
|
|
}
|
|
else if (comment) {
|
|
return comment.map(node => node.text).join(' ');
|
|
}
|
|
return undefined;
|
|
}
|
|
//# sourceMappingURL=jsDocUtils.js.map
|