postcss-selector-parser is a utility library designed to parse CSS selector strings into an abstract syntax tree (AST), providing a structured API for inspecting and manipulating these selectors. It is an integral tool within the PostCSS ecosystem, enabling advanced selector transformations, linting, and optimizations by allowing plugins to programmatically interact with selector structures. The current stable version is 7.1.1, with a release cadence that responds to feature demands and bug fixes within the broader PostCSS community. Its key differentiators include a robust AST representation, comprehensive traversal methods (like `walk`), and support for both synchronous and asynchronous processing, making it highly flexible for various build environments. It also includes full TypeScript type definitions to enhance developer experience and ensure type safety.
npm install postcss-selector-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse and transform CSS selectors using `postcss-selector-parser`, showcasing both synchronous and asynchronous API usage and node traversal.
Review existing code that modifies the selector AST during `walk` or `each` iterations. Ensure that insertions/deletions are handled correctly in the new safe iteration context, potentially re-evaluating node indices or references if directly manipulated.
To normalize whitespace and remove comments from the output selector string, pass `{ lossless: false }` as the second argument to `parser().process()` or `parser().processSync()`.For modern projects, use `import parser from 'postcss-selector-parser';`. If you are in a CommonJS environment, `const parser = require('postcss-selector-parser');` remains valid.The main export is a factory function that returns a processor. Call it as `parser(transformFunction)` or `parser()` to get the processing instance, then call `process` or `processSync` on that instance. Example: `parser(transform).processSync(...)` or `parser().processSync(...)`.
Change your import statement from `const parser = require('postcss-selector-parser');` to `import parser from 'postcss-selector-parser';`.Ensure your project's `tsconfig.json` (for TypeScript) or build tool (e.g., Webpack, Rollup) is configured to handle `moduleResolution: 'bundler'` or `node` correctly. Verify that Node.js version is recent enough to support `package.json` `exports` map if applicable. For older setups, consider a CommonJS build or adjusting bundler config.
No dependency data recorded yet.