sass-parser (current version 0.4.44) is a JavaScript library that provides a PostCSS-compatible API for parsing Sass and CSS. It serves as a wrapper around the official Dart Sass parser, aiming to offer a fully compatible parsing solution for both Sass and indented Sass syntax, which addresses known limitations of previous PostCSS plugins like `postcss-scss`. The project is under active development and, as of its current version, is explicitly not recommended for production use due to its incomplete support for all CSS and Sass syntax features and its lack of support for parsing raw metadata (which is crucial for certain source-to-source transformations). Its release cadence is independently managed but benefits from updates to the underlying Dart Sass project (which is currently at version 1.99.0). This library is primarily for developers building PostCSS plugins or tools that require programmatic access to the Sass Abstract Syntax Tree (AST) with PostCSS compatibility.
npm install sass-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `scss` parser to transform a Sass string into an Abstract Syntax Tree (AST), then modify the AST using PostCSS-compatible methods, and finally serialize it back to a string. It showcases basic node manipulation and Sass-specific property access.
Use for experimental purposes or in environments where the parsed Sass subset is guaranteed to be compatible. Monitor its development and release candidates for production readiness.
Be aware that formatting information might be lost or altered upon serialization. For transformations requiring raw preservation, this parser might be unsuitable.
Ensure your Node.js environment is at least version 18.0.0. Use `nvm install 18 && nvm use 18` or update your Node.js installation.
Consult `sass-parser`'s own changelog and documentation for specific feature support and breaking changes related to its API, rather than relying solely on Dart Sass releases.
Ensure you are calling `.parse` on one of the exposed syntax objects (e.g., `sassParser.scss.parse()`) and that the `scss`, `sass`, or `css` objects are correctly imported or accessed. For CommonJS: `const { scss } = require('sass-parser');` or `const sassParser = require('sass-parser'); const root = sassParser.scss.parse(cssString);`.Simplify the input Sass/CSS to use only basic, widely supported syntax. Refer to `sass-parser`'s documentation to understand the current scope of supported features. Report unsupported syntax as an issue to the project maintainers.
Upgrade your Node.js environment to version 18.0.0 or later. Consider using a Node Version Manager (NVM) to manage multiple Node.js versions.