Skip to content

Commit

Permalink
test: avoid need for expect (also fixes linting)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jan 26, 2022
1 parent 1cb4f00 commit 0b0a90b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
57 changes: 38 additions & 19 deletions dist/index.cjs.cjs
Expand Up @@ -22,6 +22,26 @@ const stripEncapsulatingBrackets = (container, isArr) => {
container.rawType = container.rawType.replace(/^\{/u, '').replace(/\}$/u, '');
};

const cleanUpLastTag = (lastTag, mode) => {
// Strip out `}` that encapsulates and is not part of
// the type
stripEncapsulatingBrackets(lastTag);

if (lastTag.typeLines.length) {
stripEncapsulatingBrackets(lastTag.typeLines, true);
} // With even a multiline type now in full, add parsing


let parsedType = null;

try {
parsedType = jsdocTypePrattParser.parse(lastTag.rawType, mode);
} catch {// Ignore
}

lastTag.parsedType = parsedType;
};

const commentParserToESTree = (jsdoc, mode) => {
const {
tokens: {
Expand All @@ -45,7 +65,9 @@ const commentParserToESTree = (jsdoc, mode) => {
const tags = [];
let lastDescriptionLine;
let lastTag = null;
jsdoc.source.slice(1).forEach((info, idx) => {
const isSingleLineBlock = Boolean(jsdoc.source.length === 1 && jsdoc.source[0].tokens.end);
const source = isSingleLineBlock ? jsdoc.source : jsdoc.source.slice(1);
source.forEach((info, idx) => {
const {
tokens
} = info;
Expand All @@ -66,26 +88,12 @@ const commentParserToESTree = (jsdoc, mode) => {


if (lastTag) {
// Strip out `}` that encapsulates and is not part of
// the type
stripEncapsulatingBrackets(lastTag);

if (lastTag.typeLines.length) {
stripEncapsulatingBrackets(lastTag.typeLines, true);
} // With even a multiline type now in full, add parsing
cleanUpLastTag(lastTag, mode);
} // Stop the iteration when we reached the last tag
// but only when we have multi-line block comment


let parsedType = null;

try {
parsedType = jsdocTypePrattParser.parse(lastTag.rawType, mode);
} catch {// Ignore
}

lastTag.parsedType = parsedType;
}

if (end) {
if (end && !isSingleLineBlock) {
ast.end = end;
return;
}
Expand Down Expand Up @@ -127,6 +135,17 @@ const commentParserToESTree = (jsdoc, mode) => {
type: 'JsdocDescriptionLine'
});
holder.description += holder.description ? '\n' + description : description;
} // Clean-up in single line mode


if (isSingleLineBlock) {
if (end) {
ast.end = end;
}

if (lastTag) {
cleanUpLastTag(lastTag, mode);
}
}
});
ast.lastDescriptionLine = lastDescriptionLine;
Expand Down
2 changes: 0 additions & 2 deletions test/commentParserToESTree.js
@@ -1,5 +1,3 @@
import {expect} from 'chai';

import {commentParserToESTree} from '../src/commentParserToESTree.js';
import {parseComment} from '../src/parseComment.js';

Expand Down

0 comments on commit 0b0a90b

Please sign in to comment.