CodeSampleX

Пример

postcss 8.5.26: Node#next

Проверенный пример — npm postcss 8.5.26: Node#next. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: Node#next returns undefined when…

sha256:037554308553a8051fe798554a144f71278666d30e342cee9b051e839191dc12

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Кейс

HOW
Цель
verify Node#next in pkg:npm/postcss@8.5.26
Пакеты
Символы
  • Node#next
Окружение
node 22.23.2
Создан
2026-08-27T02:00:45Z

Контракт

  1. Node#next returns undefined when called on a node without a parent container
  2. Node#next returns the immediate next sibling node in a container with multiple children
  3. Node#next returns undefined when called on the last child node in a container
  4. Node#next supports forward traversal across mixed child node types including rules, declarations, comments, and at-rules
  5. Node#next dynamically returns the updated adjacent sibling following node insertion or removal in the AST
  6. Node#next enables sequential iterative forward traversal until reaching undefined at the end of child nodes

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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 Node#next in pkg:npm/postcss@8.5.26
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss@8.5.26
Demonstrate these symbols/APIs:
  - Node#next
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:97d9d6d02d6c31a572d9c94adf29d5f963906f12ae309740175ff4cc7805d32c","constraints":{"executionContext":"node"},"contract":["Node#next returns undefined when called on a node without a parent container","Node#next returns the immediate next sibling node in a container with multiple children","Node#next returns undefined when called on the last child node in a container","Node#next supports forward traversal across mixed child node types including rules, declarations, comments, and at-rules","Node#next dynamically returns the updated adjacent sibling following node insertion or removal in the AST","Node#next enables sequential iterative forward traversal until reaching undefined at the end of child nodes"],"goal":"verify Node#next in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["Node#next"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["Node#next"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss-node-next",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-node-next",
      "version": "1.0.0",
      "dependencies": {
        "postcss": "8.5.26"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.18",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
      "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    },
    "node_modules/postcss": {
      "version": "8.5.26",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
      "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
      "license": "MIT",
      "dependencies": {
        "nanoid": "^3.3.17",
        "picocolors": "^1.1.1",
        "source-map-js": "^1.2.1"
      },
      "engines": {
        "node": "^10 || ^12 || >=14"
      }
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-postcss-node-next",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "postcss": "8.5.26"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Node#next in pkg:npm/postcss@8.5.26",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.26"
  ],
  "symbols": [
    "Node#next"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const postcss = require('postcss');

// 1. Node#next returns undefined when called on a node without a parent container
{
  const detachedDecl = postcss.decl({ prop: 'color', value: 'red' });
  assert.equal(detachedDecl.parent, undefined);
  assert.equal(detachedDecl.next(), undefined);

  const detachedRule = postcss.rule({ selector: '.box' });
  assert.equal(detachedRule.parent, undefined);
  assert.equal(detachedRule.next(), undefined);
}

// 2. Node#next returns the immediate next sibling node in a container with multiple children
{
  const root = postcss.parse('a { color: red; font-size: 14px; margin: 0; } b { display: flex; }');
  const firstRule = root.nodes[0];
  const secondRule = root.nodes[1];

  assert.equal(firstRule.next(), secondRule);
  assert.equal(firstRule.next().selector, 'b');

  const firstDecl = firstRule.nodes[0];
  const secondDecl = firstRule.nodes[1];
  const thirdDecl = firstRule.nodes[2];

  assert.equal(firstDecl.next(), secondDecl);
  assert.equal(firstDecl.next().prop, 'font-size');
  assert.equal(secondDecl.next(), thirdDecl);
  assert.equal(secondDecl.next().prop, 'margin');
}

// 3. Node#next returns undefined when called on the last child node in a container
{
  const root = postcss.parse('.card { padding: 10px; border: 1px solid #ccc; }');
  const rule = root.nodes[0];
  assert.equal(root.nodes[0].next(), undefined);

  const lastDecl = rule.nodes[1];
  assert.equal(lastDecl.prop, 'border');
  assert.equal(lastDecl.next(), undefined);
}

// 4. Node#next supports forward traversal across mixed child node types including rules, declarations, comments, and at-rules
{
  const css = '@media (min-width: 768px) { /* comment */ h1 { color: blue; } }';
  const root = postcss.parse(css);
  const atRule = root.nodes[0];

  assert.equal(atRule.type, 'atrule');
  assert.equal(atRule.name, 'media');

  const commentNode = atRule.nodes[0];
  assert.equal(commentNode.type, 'comment');

  const ruleNode = atRule.nodes[1];
  assert.equal(ruleNode.type, 'rule');
  assert.equal(ruleNode.selector, 'h1');

  assert.equal(commentNode.next(), ruleNode);
  assert.equal(ruleNode.next(), undefined);
}

// 5. Node#next dynamically returns the updated adjacent sibling following node insertion or removal in the AST
{
  const root = postcss.parse('div { color: black; font-weight: bold; }');
  const rule = root.nodes[0];
  const firstDecl = rule.nodes[0];
  const originalSecondDecl = rule.nodes[1];

  assert.equal(firstDecl.next(), originalSecondDecl);

  const newDecl = postcss.decl({ prop: 'opacity', value: '0.8' });
  firstDecl.after(newDecl);

  assert.equal(firstDecl.next(), newDecl);
  assert.equal(newDecl.next(), originalSecondDecl);

  newDecl.remove();
  assert.equal(firstDecl.next(), originalSecondDecl);
  assert.equal(newDecl.next(), undefined);
}

// 6. Node#next enables sequential iterative forward traversal until reaching undefined at the end of child nodes
{
  const root = postcss.parse('.list { a: 1; b: 2; c: 3; d: 4; }');
  const rule = root.nodes[0];

  const traversedProps = [];
  let current = rule.nodes[0];
  while (current) {
    traversedProps.push(current.prop);
    current = current.next();
  }

  assert.deepEqual(traversedProps, ['a', 'b', 'c', 'd']);
}

Исходный сидер

аноним