Sha256: f66eaa13a92c7e0eb38480a0b478b7acea02c3a3748bd0f5974827dc265941c1

Contents?: true

Size: 1023 Bytes

Versions: 24

Compression:

Stored size: 1023 Bytes

Contents

module.exports = function resolveNestedSelector(selector, node) {
  var parent = node.parent;
  var parentIsNestAtRule = parent.type === 'atrule' && parent.name === 'nest';

  if (parent.type === 'root') return [selector];
  if (parent.type !== 'rule' && !parentIsNestAtRule) return resolveNestedSelector(selector, parent);

  var parentSelectors = (parentIsNestAtRule)
    ? parent.params.split(',').map(function(s) { return s.trim(); })
    : parent.selectors;

  var resolvedSelectors = parentSelectors.reduce(function(result, parentSelector) {
    if (selector.indexOf('&') !== -1) {
      var newlyResolvedSelectors = resolveNestedSelector(parentSelector, parent).map(function(resolvedParentSelector) {
        return selector.replace(/&/g, resolvedParentSelector);
      });
      return result.concat(newlyResolvedSelectors);
    }

    var combinedSelector = [ parentSelector, selector ].join(' ');
    return result.concat(resolveNestedSelector(combinedSelector, parent));
  }, []);

  return resolvedSelectors;
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.7 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.6 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.5 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.4 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.3 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.2 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.1 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3.5 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-5.0.0 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3.4 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3.3 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3.2 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3.1 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.3 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.2.3 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.2.2 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.2.1 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.2 node_modules/postcss-resolve-nested-selector/index.js
trusty-cms-4.1.9 node_modules/postcss-resolve-nested-selector/index.js