@babel/types#CommentLine TypeScript Examples
The following examples show how to use
@babel/types#CommentLine.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: get-all-comments-from-nodes.ts From prettier-plugin-sort-imports with Apache License 2.0 | 6 votes |
getAllCommentsFromNodes = (nodes: Statement[]) =>
nodes.reduce((acc, node) => {
if (
Array.isArray(node.leadingComments) &&
node.leadingComments.length > 0
) {
acc = [...acc, ...node.leadingComments];
}
return acc;
}, [] as (CommentBlock | CommentLine)[])
Example #2
Source File: remove-nodes-from-original-code.ts From prettier-plugin-sort-imports with Apache License 2.0 | 6 votes |
removeNodesFromOriginalCode = (
code: string,
nodes: (
| Statement
| CommentBlock
| CommentLine
| ImportDeclaration
| InterpreterDirective
)[],
) => {
let text = code;
for (const node of nodes) {
const start = Number(node.start);
const end = Number(node.end);
if (Number.isSafeInteger(start) && Number.isSafeInteger(end)) {
text = text.replace(
// only replace imports at the beginning of the line (ignoring whitespace)
// otherwise matching commented imports will be replaced
new RegExp(
'^\\s*' + escapeRegExp(code.substring(start, end)),
'm',
),
'',
);
}
}
return text;
}
Example #3
Source File: get-all-comments-from-nodes.spec.ts From prettier-plugin-sort-imports with Apache License 2.0 | 5 votes |
getComments = (commentNodes: (CommentBlock | CommentLine)[]) =>
commentNodes.map((node) => node.value)