PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/eslint-plugin-jsdoc/dist
Просмотр файла: alignTransform.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _primitives = require("comment-parser/lib/primitives");
var _util = require("comment-parser/lib/util");
const zeroWidth = {
name: 0,
start: 0,
tag: 0,
type: 0
};
const shouldAlign = (tags, index, source) => {
const tag = source[index].tokens.tag.replace('@', '');
const includesTag = tags.includes(tag);
if (includesTag) {
return true;
}
if (tag !== '') {
return false;
}
for (let iterator = index; iterator >= 0; iterator--) {
const previousTag = source[iterator].tokens.tag.replace('@', '');
if (previousTag !== '') {
if (tags.includes(previousTag)) {
return true;
}
return false;
}
}
return true;
};
const getWidth = tags => {
return (width, {
tokens
}, index, source) => {
if (!shouldAlign(tags, index, source)) {
return width;
}
return {
name: Math.max(width.name, tokens.name.length),
start: tokens.delimiter === _primitives.Markers.start ? tokens.start.length : width.start,
tag: Math.max(width.tag, tokens.tag.length),
type: Math.max(width.type, tokens.type.length)
};
};
};
const space = len => {
return ''.padStart(len, ' ');
};
const alignTransform = (tags, indent) => {
let intoTags = false;
let width;
const alignTokens = tokens => {
const nothingAfter = {
delim: false,
name: false,
tag: false,
type: false
};
if (tokens.description === '') {
nothingAfter.name = true;
tokens.postName = '';
if (tokens.name === '') {
nothingAfter.type = true;
tokens.postType = '';
if (tokens.type === '') {
nothingAfter.tag = true;
tokens.postTag = '';
/* istanbul ignore next: Never happens because the !intoTags return. But it's here for consistency with the original align transform */
if (tokens.tag === '') {
nothingAfter.delim = true;
}
}
}
}
tokens.postDelimiter = nothingAfter.delim ? '' : ' ';
if (!nothingAfter.tag) {
tokens.postTag = space(width.tag - tokens.tag.length + 1);
}
if (!nothingAfter.type) {
tokens.postType = space(width.type - tokens.type.length + 1);
}
if (!nothingAfter.name) {
// If post name is empty for all lines (name width 0), don't add post name spacing.
tokens.postName = width.name === 0 ? '' : space(width.name - tokens.name.length + 1);
}
return tokens;
};
const update = (line, index, source) => {
const tokens = { ...line.tokens
};
if (tokens.tag !== '') {
intoTags = true;
}
const isEmpty = tokens.tag === '' && tokens.name === '' && tokens.type === '' && tokens.description === ''; // dangling '*/'
if (tokens.end === _primitives.Markers.end && isEmpty) {
tokens.start = indent + ' ';
return { ...line,
tokens
};
}
/* eslint-disable indent */
switch (tokens.delimiter) {
case _primitives.Markers.start:
tokens.start = indent;
break;
case _primitives.Markers.delim:
tokens.start = indent + ' ';
break;
default:
tokens.delimiter = ''; // compensate delimiter
tokens.start = indent + ' ';
}
/* eslint-enable */
if (!intoTags) {
tokens.postDelimiter = tokens.description === '' ? '' : ' ';
return { ...line,
tokens
};
} // Not align.
if (!shouldAlign(tags, index, source)) {
return { ...line,
tokens
};
}
return { ...line,
tokens: alignTokens(tokens)
};
};
return ({
source,
...fields
}) => {
width = source.reduce(getWidth(tags), { ...zeroWidth
});
return (0, _util.rewireSource)({ ...fields,
source: source.map(update)
});
};
};
var _default = alignTransform;
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=alignTransform.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!