parseSelector.js 585 B

1234567891011121314151617181920
  1. 'use strict';
  2. const selectorParser = require('postcss-selector-parser');
  3. /**
  4. * @param {string} selector
  5. * @param {import('stylelint').PostcssResult} result
  6. * @param {import('postcss').Node} node
  7. * @param {(root: import('postcss-selector-parser').Root) => void} callback
  8. * @returns {string | undefined}
  9. */
  10. module.exports = function parseSelector(selector, result, node, callback) {
  11. try {
  12. return selectorParser(callback).processSync(selector);
  13. } catch (err) {
  14. result.warn(`Cannot parse selector (${err})`, { node, stylelintType: 'parseError' });
  15. return undefined;
  16. }
  17. };