CodeSampleX

Sample

postcss-selector-parser 7.1.1

Verified sample for npm postcss-selector-parser 7.1.1. The contract ran on node 22 · linux debian/x64 · docker and passed: parser is exported as a function…

sha256:404e7f7cbaee3e6720e894627b32cbf2018ac3bbe0e3e7469b7417febe9557f8

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-19

Case

HOW
Goal
verify pkg:npm/postcss-selector-parser@7.1.1
Packages
Created
2026-09-18T19:08:20Z

Contract

  1. parser is exported as a function and creates a processor instance
  2. parser transforms class selectors in a CSS selector string synchronously
  3. parser parses compound selectors and combinators into an AST hierarchy
  4. parser AST nodes support tag, class, id, and attribute selector types
  5. parser builder functions construct selector nodes programmatically

Files

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/postcss-selector-parser@7.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss-selector-parser@7.1.1

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:acb4a6b92c7ff4be73ec3e9c7c6c2d427c18d8f49de339d5cd753a0eaa0cb9aa","contract":["parser is exported as a function and creates a processor instance","parser transforms class selectors in a CSS selector string synchronously","parser parses compound selectors and combinators into an AST hierarchy","parser AST nodes support tag, class, id, and attribute selector types","parser builder functions construct selector nodes programmatically"],"goal":"verify pkg:npm/postcss-selector-parser@7.1.1","kind":"HOW","packages":["pkg:npm/postcss-selector-parser@7.1.1"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/postcss-selector-parser@7.1.1"],"schemaVersion":1,"subject":"pkg:npm/postcss-selector-parser@7.1.1","verifierAdapter":"node-typescript@1"}
index.mjs
import parser from 'postcss-selector-parser';

export const parse = parser;

/**
 * Synchronously parses a CSS selector string into an AST.
 *
 * @param {string} selector - CSS selector string to parse.
 * @returns {object} Root AST node.
 */
export function parseSelector(selector) {
  return parser().astSync(selector);
}

/**
 * Transforms class selectors in a CSS selector string using a mapping function.
 *
 * @param {string} selector - CSS selector string.
 * @param {function(string): string} rename - Mapping function for class names.
 * @returns {string} Transformed selector string.
 */
export function renameClasses(selector, rename) {
  const transform = (selectors) => {
    selectors.walkClasses((node) => {
      node.value = rename(node.value);
    });
  };
  return parser(transform).processSync(selector);
}

export default parser;
package-lock.json
{
  "name": "sample-postcss-selector-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-selector-parser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss-selector-parser": "7.1.1"
      }
    },
    "node_modules/cssesc": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
      "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==",
      "license": "MIT",
      "bin": {
        "cssesc": "bin/cssesc"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/postcss-selector-parser": {
      "version": "7.1.1",
      "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.1.tgz",
      "integrity": "sha512-orRsuYpJVw8LdAwqqLykBj9ecS5/cRHlI5+nvTo8LcCKmzDmqVORXtOIYEEQuL9D4BxtA1lm5isAqzQZCoQ6Eg==",
      "license": "MIT",
      "dependencies": {
        "cssesc": "^3.0.0",
        "util-deprecate": "^1.0.2"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/util-deprecate": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
      "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-postcss-selector-parser",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "postcss-selector-parser": "7.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/postcss-selector-parser@7.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss-selector-parser@7.1.1"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import parser from 'postcss-selector-parser';
import { parseSelector, renameClasses } from '../index.mjs';

// 1. parser is exported as a function and creates a processor instance
assert.equal(typeof parser, 'function');
const processor = parser();
assert.equal(typeof processor.processSync, 'function');
assert.equal(typeof processor.astSync, 'function');

// 2. parser transforms class selectors in a CSS selector string synchronously
const transformed = renameClasses('.old-btn > .active', (cls) => `new-${cls}`);
assert.equal(transformed, '.new-old-btn > .new-active');

const customTransform = parser((selectors) => {
  selectors.walkClasses((cls) => {
    cls.value = 'renamed';
  });
}).processSync('div.foo, span.bar');
assert.equal(customTransform, 'div.renamed, span.renamed');

// 3. parser parses compound selectors and combinators into an AST hierarchy
const root = parseSelector('div.card > span#header');
assert.equal(root.type, 'root');
assert.equal(root.nodes.length, 1);

const selectorNode = root.nodes[0];
assert.equal(selectorNode.type, 'selector');
assert.equal(selectorNode.nodes.length, 5);

const [tag1, class1, combinator, tag2, id1] = selectorNode.nodes;
assert.equal(tag1.type, 'tag');
assert.equal(tag1.value, 'div');
assert.equal(class1.type, 'class');
assert.equal(class1.value, 'card');
assert.equal(combinator.type, 'combinator');
assert.equal(combinator.value, '>');
assert.equal(tag2.type, 'tag');
assert.equal(tag2.value, 'span');
assert.equal(id1.type, 'id');
assert.equal(id1.value, 'header');

// 4. parser AST nodes support tag, class, id, and attribute selector types
const attrRoot = parseSelector('[data-role="primary"]');
const attrNode = attrRoot.nodes[0].nodes[0];
assert.equal(attrNode.type, 'attribute');
assert.equal(attrNode.attribute, 'data-role');
assert.equal(attrNode.value, 'primary');

// 5. parser builder functions construct selector nodes programmatically
const builtClass = parser.className({ value: 'button' });
assert.equal(builtClass.type, 'class');
assert.equal(builtClass.toString(), '.button');

const builtId = parser.id({ value: 'root' });
assert.equal(builtId.type, 'id');
assert.equal(builtId.toString(), '#root');

const builtTag = parser.tag({ value: 'article' });
assert.equal(builtTag.type, 'tag');
assert.equal(builtTag.toString(), 'article');

const builtAttr = parser.attribute({ attribute: 'disabled' });
assert.equal(builtAttr.type, 'attribute');
assert.equal(builtAttr.toString(), '[disabled]');

console.log('All postcss-selector-parser contract assertions passed.');

Origin Seeder

anonymous