moveLeadingCommentsToSibling()

in legacy/javascript/src/refactor.js [258:274]


    moveLeadingCommentsToSibling(node, parent) {
        if ('body' in parent && Array.isArray(parent.body)) {
            var nodeIndex = parent.body.indexOf(node);
            var previousSiblingIndex = nodeIndex !== 0 ? nodeIndex - 1 : null;
            var nextSiblingIndex = nodeIndex !== parent.body.length - 1 ? nodeIndex + 1 : null;

            let [leadingComments] = this.collateCommentsByPosition(node);

            if (nextSiblingIndex != null) {
                this.attachCommentsAtBeginning(parent.body[nextSiblingIndex], leadingComments);
            } else if (previousSiblingIndex != null) {
                var consolidatedComments = leadingComments.map(this.flipCommentPosition);

                this.attachCommentsAtEnd(parent.body[previousSiblingIndex], consolidatedComments);
            }
        }
    }