Registry / serialization / postcss-inherit-parser

postcss-inherit-parser

JSON →
library0.2.0jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · POSTCSS-INHERIT-PA
P
postcss-inherit-parser
serializationjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
const parse = require('postcss-inherit-parser');
import { parse } from 'postcss-inherit-parser';
The package is very old (v0.2.0, published 8 years ago) and primarily supports CommonJS `require`. ESM imports are unlikely to work directly without transpilation or a CommonJS wrapper.
PostCSS with parser
const postcss = require('postcss'); const inheritParser = require('postcss-inherit-parser'); const processor = postcss().use(/* your plugins here */); const root = await processor.process(cssInput, { parser: inheritParser }).root;
const postcss = require('postcss'); const inheritParser = require('postcss-inherit-parser'); const processor = postcss([/* your plugins here */], { parser: inheritParser }); // or const processor = postcss().use(inheritParser);
The parser function should be passed to the `parser` option of `postcss.process` or `postcss.parse`, not directly to `postcss.use` or the plugins array.

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.

const postcss = require('postcss'); const inheritParser = require('postcss-inherit-parser'); async function processCssWithInherit() { const cssInput = ` .b:before { content: ""; color: blue; } .a { inherit: .b:before; font-size: 16px; } .c { extend: .a; border: 1px solid black; } `; // Use the parser with custom propertyRegExp const root = await postcss().process(cssInput, { from: undefined, parser: inheritParser.parse, parserOptions: { propertyRegExp: /^(inherit|extend)s?$/i } }).root; console.log('Parsed AST (first rule selector):', root.nodes[0].selector); // .b:before console.log('Parsed AST (second rule inherit property):', root.nodes[1].nodes[0].prop); // inherit console.log('Parsed AST (third rule extend property):', root.nodes[2].nodes[0].prop); // extend // To apply the actual inheritance, you would typically use postcss-inherit as a plugin: const postcssInherit = require('postcss-inherit'); const result = await postcss([postcssInherit()]).process(cssInput, { from: undefined, parser: inheritParser.parse, parserOptions: { propertyRegExp: /^(inherit|extend)s?$/i } }); console.log('\nCSS after processing with postcss-inherit:\n', result.css); } processCssWithInherit();
Debug
Known issues
breakingThe package is extremely old (v0.2.0, published 8 years ago) and appears to be unmaintained. There will be no further bug fixes, new features, or compatibility updates for newer Node.js versions, PostCSS versions (current PostCSS is v8+), or evolving CSS specifications. This can lead to unexpected behavior or breakage in modern environments.
fix
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.
affects: 0.2.0
gotchaThis package is solely a parser; it converts the custom `inherit` syntax into a PostCSS Abstract Syntax Tree (AST). It does not, by itself, apply any inheritance logic to the CSS. To make the inheritance functional, you *must* use it in conjunction with a PostCSS plugin like `postcss-inherit`.
fix
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.
affects: 0.2.0
gotchaDue to its age, `postcss-inherit-parser` is a CommonJS module. Attempting to use `import { parse } from 'postcss-inherit-parser'` in an ESM environment will likely result in a `TypeError` or similar import error, as it does not explicitly provide an ESM export.
fix
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.
affects: 0.2.0
gotchaThe parser relies on the `propertyRegExp` option for flexible `inherit` property naming. If you introduce custom keywords (e.g., `extends`) but do not update `propertyRegExp` correctly, the parser will not recognize them, treating them as standard CSS properties or throwing a syntax error.
fix
Always pass a `propertyRegExp` option that matches all desired inheritance keywords when initializing the parser, for example: `{ parserOptions: { propertyRegExp: /^(inherit|extend)s?$/i } }`.
affects: 0.2.0
Errors
Common errors & fixes
Error: Unknown word (at line X, column Y)
The parser encountered an unrecognized token or custom `inherit` syntax that it could not process, likely because the `inheritParser` was not configured correctly or not applied as the PostCSS parser.
fix
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`).
TypeError: (0 , _postcssInheritParser.parse) is not a function
This error typically occurs when attempting to use ESM `import { parse } from 'postcss-inherit-parser'` for a package that only provides CommonJS exports, which is the case for this old, unmaintained module. The module is imported, but the `parse` symbol is not found as a named export.
fix
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.
The 'parse' function must be passed to the PostCSS 'parser' option, not 'plugins'.
You've attempted to pass the `postcss-inherit-parser` function directly into the `postcss` plugin array or `.use()` method, rather than specifying it as the parser for the processing step. Parsers and plugins have distinct roles in PostCSS.
fix
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 })`.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
postcssrequiredThis package is a PostCSS parser and requires PostCSS to integrate into a processing pipeline. It should be treated as an implicit peer dependency to ensure AST compatibility.
Agent activity
6 hits · last 30 days
node
6
Resources
postcss-inherit-parser — npm install postcss-inherit-parser · libregistry