postcss-inherit-parser is a specialized parser for PostCSS, designed to interpret a custom CSS syntax that facilitates "inherit" declarations, specifically in conjunction with the `postcss-inherit` plugin. This parser enables the processing of CSS where rules can leverage inheritance from other selectors, including those with pseudo-classes, as exemplified by syntax like `.a { inherit: .b:before; }`. The package, currently at version 0.2.0, was last published approximately 8 years ago, suggesting it is no longer actively maintained. Its core functionality is to provide the Abstract Syntax Tree (AST) representation for this non-standard inheritance syntax, allowing subsequent PostCSS plugins to apply transformation logic. A key feature is the configurable `propertyRegExp` option, which allows consumers to define custom keywords for inheritance, such as `extend` instead of `inherit`. Given its age and low version, developers should be aware of potential compatibility issues with newer Node.js or PostCSS versions.
npm install postcss-inherit-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `postcss-inherit-parser` to parse CSS containing custom `inherit` or `extend` declarations, and then how to process it with the `postcss-inherit` plugin to apply the inheritance logic, including customizing the property name regex.
Consider re-evaluating the need for custom `inherit` syntax or migrating to modern CSS features or actively maintained PostCSS plugins/syntaxes for similar functionality. If absolutely necessary, pin `postcss` to an older, compatible major version and ensure Node.js compatibility.
Always pair this parser with the `postcss-inherit` plugin (or a custom plugin that processes the generated AST) in your PostCSS pipeline to achieve the desired CSS inheritance behavior.
Use CommonJS `const parse = require('postcss-inherit-parser');` for importing the module in Node.js environments. If used in a bundled client-side application, ensure your build tool (e.g., Webpack, Rollup) is configured to handle CommonJS modules.Always pass a `propertyRegExp` option that matches all desired inheritance keywords when initializing the parser, for example: `{ parserOptions: { propertyRegExp: /^(inherit|extend)s?$/i } }`.Ensure `postcss-inherit-parser` is correctly passed to the `parser` option of `postcss.process` or `postcss.parse`. Verify that the `propertyRegExp` option is configured to match all custom inheritance keywords used in your CSS (e.g., `inherit`, `extend`).
Change your import statement to use CommonJS syntax: `const parse = require('postcss-inherit-parser');`. Ensure your Node.js or bundling environment correctly processes CommonJS modules.Pass the parser function via the `parser` option in `postcss.process(css, { parser: inheritParser.parse })` or when creating a PostCSS processor: `postcss([yourPlugin], { parser: inheritParser.parse })`.