UNPKG

734 BJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4
5/** @typedef {import('postcss').Node} Node */
6
7/**
8 * @param {Node | void} node
9 */
10function getNodeLine(node) {
11 return _.get(node, 'source.start.line');
12}
13
14/**
15 * @param {Node | void} node
16 * @returns {Node | void}
17 */
18module.exports = function getNextNonSharedLineCommentNode(node) {
19 if (node === undefined) {
20 return undefined;
21 }
22
23 /** @type {Node | void} */
24 const nextNode = node.next();
25
26 if (_.get(nextNode, 'type') !== 'comment') {
27 return nextNode;
28 }
29
30 if (
31 getNodeLine(node) === getNodeLine(nextNode) ||
32 (nextNode !== undefined && getNodeLine(nextNode) === getNodeLine(nextNode.next()))
33 ) {
34 return getNextNonSharedLineCommentNode(nextNode);
35 }
36
37 return nextNode;
38};