gonzales-pe-sl (CSS Parser Fork for sass-lint)
raw JSON → 4.2.3 verified Fri May 01 auth: no javascript maintenance
A temporary fork of gonzales-pe, version 4.2.3, created specifically for sass-lint. It is a CSS parser that supports SCSS, Sass, and LESS syntaxes, producing a parse tree that can be traversed, modified, and serialized back to CSS. The package is unmaintained and intended only as a transitional dependency for sass-lint; newer projects should use postcss-scss or postcss-less instead. The release cadence is effectively frozen.
Common errors
error Cannot find module 'gonzales-pe-sl' ↓
cause Package not installed
fix
npm install gonzales-pe-sl
error gonzales.parse is not a function ↓
cause Using ES import instead of require
fix
Change import gonzales from 'gonzales-pe-sl' to const gonzales = require('gonzales-pe-sl');
error TypeError: Cannot read property 'type' of undefined ↓
cause Parsing failed, likely due to missing syntax option or invalid CSS
fix
Ensure you pass the correct syntax option (e.g., {syntax: 'scss'}) and valid CSS string.
error Unrecognised input ↓
cause Parser cannot handle the input syntax because it is not supported (e.g., some newer CSS features).
fix
Simplify the input or switch to a more modern parser like postcss-scss.
Warnings
deprecated gonzales-pe-sl is a temporary fork for sass-lint only; not intended for direct use. Use postcss-scss or postcss-less instead. ↓
fix Replace with postcss-scss (npm install postcss-scss) or postcss-less, and use postcss's AST API.
breaking No ES module (ESM) support; only CommonJS require() works. Attempting to import will fail. ↓
fix Use require() as shown in the quickstart, or consider switching to a modern parser.
gotcha The parse tree node types are plain strings; no TypeScript types or documentation beyond node-types.md. Nodes may have unexpected structures. ↓
fix Refer to the original gonzales-pe docs for node types; for TypeScript projects, consider using @types/gonzales-pe (if available) or switch to postcss.
breaking The package is no longer maintained and will not receive security updates or bug fixes. ↓
fix Migrate to a maintained alternative like postcss-scss or gonzales-pe-dev (not recommended).
Install
npm install gonzales-pe-sl yarn add gonzales-pe-sl pnpm add gonzales-pe-sl Imports
- gonzales wrong
import gonzales from 'gonzales-pe-sl';correctconst gonzales = require('gonzales-pe-sl'); - parse
const parseTree = gonzales.parse(css, {syntax: 'scss'}); - createNode wrong
import { createNode } from 'gonzales-pe-sl';correctconst node = gonzales.createNode({ type: 'selector', content: 'div' }); - Types (Node types) wrong
import { NodeType } from 'gonzales-pe-sl';correct// Node types are strings like 'selector', 'declaration', 'value', etc. Refer to docs.
Quickstart
const gonzales = require('gonzales-pe-sl');
// Parse SCSS
const css = `
.container {
$color: red;
.item {
color: $color;
}
}`;
const options = {
syntax: 'scss',
tabSize: 2
};
const parseTree = gonzales.parse(css, options);
console.log(parseTree.type); // 'stylesheet'
// Traverse and find selectors
const findSelectors = (node) => {
if (node.type === 'selector') {
console.log('Found selector:', node.content.map(t => t.content).join(''));
}
if (node.content && Array.isArray(node.content)) {
node.content.forEach(findSelectors);
}
};
findSelectors(parseTree);
// Convert back to string
const stringified = parseTree.toString();
console.log(stringified);