parseSelector.js 564 B

123456789101112131415161718
  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. }
  16. };