{“ast”:null,“code”:“'use strict';nnObject.defineProperty(exports, "__esModule", {n value: truen});nexports.analyzeElementSiblings = analyzeElementSiblings;nnexports = function (hierarchy, state, validateSelector) {n return hierarchy.reduce(function (selectorState, currentElem, index) {n if (!selectorState.verified) {n // get siblings BEFORE out elementn var prevSiblings = currentElem.prevAll();n var nextSiblings = currentElem.nextAll // get element's index by the number of elements before itn // note that the nth-child selector uses a 1 based index, not 0n ();n var indexOfElement = prevSiblings.length + 1; // If the element has no siblings!n // we have no need for the nth-child selectornn if ((prevSiblings.length || nextSiblings.length) && !analyzeElementSiblings(currentElem, [].concat(_toConsumableArray(prevSiblings), _toConsumableArray(nextSiblings)))) {n // if we don't have a unique tag or a unique class, then we need a nth-child to help usn // differenciate our element from the rest of the packn selectorState.stack.push(':nth-child(' + indexOfElement + ')' // Verify the selector as we don't want to go on and parse the parent's siblingsn // if we don't have to!n );n selectorState.verified = validateSelector(selectorState);n }n }nn return selectorState;n }, state);n};nnvar _lodash = require('lodash.difference');nnvar _lodash2 = _interopRequireDefault(_lodash);nnvar _lodash3 = require('lodash.flatmap');nnvar _lodash4 = _interopRequireDefault(_lodash3);nnfunction _interopRequireDefault(obj) {n return obj && obj.__esModule ? obj : {n "default": objn };n}nnfunction _toConsumableArray(arr) {n if (Array.isArray(arr)) {n for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {n arr2 = arr;n }nn return arr2;n } else {n return Array.from(arr);n }n}n/**n * Inspect the element's siblings by index (nth-child) name and compare them to the analyzed element.n * The sibling comparison is done from level 0 (the analyzed element) upwards in the hierarchy, In an effort to avoid unneeded parsing.n * @param {array} hierarchy. The hierarchy of elementsn * @param {object} state. The current calculated CSS selectorn */nnnvar not = function not(i) {n return !i;n};nnvar getNodeNames = function getNodeNames(siblings) {n return siblings.map(function (sibling) {n return sibling.el.nodeName;n }n /***n * The main method splits up the hierarchy and isolates each element, while this helper method is designedn * to then take each level in the hierarchy and fid into it's surounding siblings.n * We've separated these to make the code more managable.n * @param siblingElementn * @param siblingsn * @returns {boolean}n */n );n};nnfunction analyzeElementSiblings(element, siblings) {n return (0, _lodash2)(element.getClasses(), (0, _lodash4)(siblings, function (sibling) {n return sibling.getClasses();n })).length > 0 || not(getNodeNames(siblings).includes(element.el.nodeName));n}”,“map”:null,“metadata”:{},“sourceType”:“module”}