Rework CSS AST Declaration Visitor

1.0.0 · abandoned · verified Sun Apr 19

rework-visit is a utility package providing a declaration visitor for the Rework CSS preprocessor's Abstract Syntax Tree (AST). Released as version 1.0.0 in June 2013, it has not seen active development or new releases since. The package enables Rework plugins to traverse and manipulate CSS declarations programmatically within the AST. It is specifically designed for the `rework` ecosystem, which has largely been superseded by more modern and actively maintained CSS tooling like PostCSS. Therefore, rework-visit is considered abandoned, with no ongoing release cadence or new feature development. Its core differentiator is its tight integration with the now-legacy Rework AST, making it unsuitable for contemporary CSS processing pipelines.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `rework-visit` within a `rework` plugin to iterate over and modify CSS declarations in an AST. It changes 'font-size' and adds 'align-items' to flex containers.

const rework = require('rework');
const visit = require('rework-visit');

const cssInput = `
  .container {
    color: blue;
    font-size: 16px;
    display: flex;
  }
  .item {
    margin: 10px;
    padding: 5px;
  }
`;

function myReworkPlugin(stylesheet) {
  visit.declarations(stylesheet, function (declarations, node) {
    declarations.forEach(function (declaration) {
      // Example: Convert all font-size values to '1.2em' (for demonstration)
      if (declaration.property === 'font-size') {
        declaration.value = '1.2em';
      }
      // Example: Add a new declaration
      if (declaration.property === 'display' && declaration.value === 'flex') {
        declarations.push({
          type: 'declaration',
          property: 'align-items',
          value: 'center'
        });
      }
    });
  });
}

// Apply the plugin
const outputCss = rework(cssInput)
  .use(myReworkPlugin)
  .toString();

console.log(outputCss);
/*
  Expected Output:
  .container {
    color: blue;
    font-size: 1.2em;
    display: flex;
    align-items: center;
  }
  .item {
    margin: 10px;
    padding: 5px;
  }
*/

view raw JSON →