transformSelector.js 558 B

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