Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function insertPragma(text) {
const parsedDocblock = docblock.parseWithComments(docblock.extract(text));
const pragmas = Object.assign({ format: "" }, parsedDocblock.pragmas);
const newDocblock = docblock
.print({
pragmas,
comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
})
.replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
const strippedText = docblock.strip(text);
const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
return newDocblock + separatingNewlines + strippedText;
}
function insertPragma(text) {
const parsedDocblock = docblock.parseWithComments(docblock.extract(text));
const pragmas = { format: "", ...parsedDocblock.pragmas };
const newDocblock = docblock
.print({
pragmas,
comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, ""), // remove leading newlines
})
.replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
const strippedText = docblock.strip(text);
const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
return newDocblock + separatingNewlines + strippedText;
}
export function getCssDocsForSymbol(meta: StylableMeta, symbol: StylableSymbol): CssDoc | null {
let commentNode;
if (symbol._kind === 'class' || symbol._kind === 'element') {
commentNode =
meta.simpleSelectors[symbol.name] && meta.simpleSelectors[symbol.name].node.prev();
} else if (symbol._kind === 'var') {
commentNode = symbol.node.prev();
}
if (commentNode && commentNode.type === 'comment') {
const { comments, pragmas } = parseWithComments(extract(commentNode.toString()));
const res: CssDoc = {
description: comments,
tags: {}
};
for (const [pragmaName, pragmaValue] of Object.entries(pragmas)) {
res.tags[pragmaName] = Array.isArray(pragmaValue) ? pragmaValue.join(' ') : pragmaValue;
}
return res;
}
return null;
}