CodeSampleX

샘플

postcss-value-parser 4.2.0: ValueParser

검증된 샘플 — npm postcss-value-parser 4.2.0: ValueParser. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: postcss-value-parser package.json declares…

sha256:eb5ba6d579605ec7eb7fcc98cd4fb1f9577046eede927f794be06c08dd2f5d08

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-01

케이스

HOW
목표
verify ValueParser in pkg:npm/postcss-value-parser@4.2.0
패키지
심벌
  • ValueParser
환경
node 22.23.2
생성일
2026-09-01T19:57:52Z

컨트랙트

  1. postcss-value-parser package.json declares export mappings and version 4.2.0
  2. postcss-value-parser exports ValueParser constructor and factory function
  3. ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets
  4. ValueParser parses nested function invocations into function nodes with nested argument nodes
  5. ValueParser parses quoted string literals preserving quote delimiters and unescaped values
  6. ValueParser walk traverses the AST recursively and supports early branch termination
  7. ValueParser toString serializes the AST back into equivalent CSS string
  8. ValueParser.unit parses CSS numeric values and dimension units
  9. ValueParser.stringify serializes an array of AST nodes into CSS string

파일

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

소스 아티팩트 내려받기 (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 ValueParser in pkg:npm/postcss-value-parser@4.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss-value-parser@4.2.0
Demonstrate these symbols/APIs:
  - ValueParser

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:f50a82768bae3087ee9ccdc884509e4c21095f09b0df9f8a63c85e1d311702cc","contract":["postcss-value-parser package.json declares export mappings and version 4.2.0","postcss-value-parser exports ValueParser constructor and factory function","ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets","ValueParser parses nested function invocations into function nodes with nested argument nodes","ValueParser parses quoted string literals preserving quote delimiters and unescaped values","ValueParser walk traverses the AST recursively and supports early branch termination","ValueParser toString serializes the AST back into equivalent CSS string","ValueParser.unit parses CSS numeric values and dimension units","ValueParser.stringify serializes an array of AST nodes into CSS string"],"goal":"verify ValueParser in pkg:npm/postcss-value-parser@4.2.0","kind":"HOW","packages":["pkg:npm/postcss-value-parser@4.2.0"],"schemaVersion":1,"symbols":["ValueParser"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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-value-parser@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/postcss-value-parser@4.2.0","symbols":["ValueParser"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss-value-parser-value-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-value-parser-value-parser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss-value-parser": "4.2.0"
      }
    },
    "node_modules/postcss-value-parser": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
      "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-postcss-value-parser-value-parser",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "postcss-value-parser": "4.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ValueParser in pkg:npm/postcss-value-parser@4.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss-value-parser@4.2.0"
  ],
  "symbols": [
    "ValueParser"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import ValueParser from 'postcss-value-parser';

const require = createRequire(import.meta.url);

// Contract 1: postcss-value-parser package.json declares export mappings and version 4.2.0
{
  const pkgJsonPath = require.resolve('postcss-value-parser/package.json');
  assert.ok(fs.existsSync(pkgJsonPath));
  const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
  assert.strictEqual(pkgJson.name, 'postcss-value-parser');
  assert.strictEqual(pkgJson.version, '4.2.0');
  assert.ok(pkgJson.main);
}

// Contract 2: postcss-value-parser exports ValueParser constructor and factory function
{
  assert.strictEqual(typeof ValueParser, 'function');
  const instance = new ValueParser('10px');
  assert.ok(instance instanceof ValueParser);
  const called = ValueParser('10px');
  assert.ok(called instanceof ValueParser);
}

// Contract 3: ValueParser parses CSS declaration values into word, space, and literal nodes with source index offsets
{
  const parsed = ValueParser('10px solid #333');
  assert.ok(Array.isArray(parsed.nodes));
  assert.strictEqual(parsed.nodes.length, 5);
  assert.deepStrictEqual(parsed.nodes[0], {
    type: 'word',
    sourceIndex: 0,
    sourceEndIndex: 4,
    value: '10px'
  });
  assert.deepStrictEqual(parsed.nodes[1], {
    type: 'space',
    sourceIndex: 4,
    sourceEndIndex: 5,
    value: ' '
  });
  assert.deepStrictEqual(parsed.nodes[2], {
    type: 'word',
    sourceIndex: 5,
    sourceEndIndex: 10,
    value: 'solid'
  });
  assert.deepStrictEqual(parsed.nodes[3], {
    type: 'space',
    sourceIndex: 10,
    sourceEndIndex: 11,
    value: ' '
  });
  assert.deepStrictEqual(parsed.nodes[4], {
    type: 'word',
    sourceIndex: 11,
    sourceEndIndex: 15,
    value: '#333'
  });
}

// Contract 4: ValueParser parses nested function invocations into function nodes with nested argument nodes
{
  const parsed = ValueParser('calc(100% - 20px)');
  assert.strictEqual(parsed.nodes.length, 1);
  const fnNode = parsed.nodes[0];
  assert.strictEqual(fnNode.type, 'function');
  assert.strictEqual(fnNode.value, 'calc');
  assert.strictEqual(fnNode.sourceIndex, 0);
  assert.strictEqual(fnNode.sourceEndIndex, 17);
  assert.strictEqual(fnNode.before, '');
  assert.strictEqual(fnNode.after, '');
  assert.ok(Array.isArray(fnNode.nodes));
  assert.strictEqual(fnNode.nodes.length, 5);
  assert.strictEqual(fnNode.nodes[0].type, 'word');
  assert.strictEqual(fnNode.nodes[0].value, '100%');
  assert.strictEqual(fnNode.nodes[0].sourceIndex, 5);
  assert.strictEqual(fnNode.nodes[0].sourceEndIndex, 9);
  assert.strictEqual(fnNode.nodes[2].type, 'word');
  assert.strictEqual(fnNode.nodes[2].value, '-');
  assert.strictEqual(fnNode.nodes[4].type, 'word');
  assert.strictEqual(fnNode.nodes[4].value, '20px');
}

// Contract 5: ValueParser parses quoted string literals preserving quote delimiters and unescaped values
{
  const parsed = ValueParser('url("image.png") \'Helvetica Neue\'');
  const urlFn = parsed.nodes[0];
  assert.strictEqual(urlFn.type, 'function');
  assert.strictEqual(urlFn.value, 'url');
  assert.strictEqual(urlFn.nodes[0].type, 'string');
  assert.strictEqual(urlFn.nodes[0].value, 'image.png');
  assert.strictEqual(urlFn.nodes[0].quote, '"');
  assert.strictEqual(urlFn.nodes[0].sourceIndex, 4);
  assert.strictEqual(urlFn.nodes[0].sourceEndIndex, 15);

  const quotedFont = parsed.nodes[2];
  assert.strictEqual(quotedFont.type, 'string');
  assert.strictEqual(quotedFont.value, 'Helvetica Neue');
  assert.strictEqual(quotedFont.quote, "'");
  assert.strictEqual(quotedFont.sourceIndex, 17);
  assert.strictEqual(quotedFont.sourceEndIndex, 33);
}

// Contract 6: ValueParser walk traverses the AST recursively and supports early branch termination
{
  const parsed = ValueParser('rgba(255, 0, 0, 0.5) 10px');
  const visited = [];
  parsed.walk((node) => {
    visited.push(node.value);
  });
  assert.ok(visited.includes('rgba'));
  assert.ok(visited.includes('255'));
  assert.ok(visited.includes('10px'));

  const stopped = [];
  parsed.walk((node) => {
    stopped.push(node.value);
    if (node.type === 'function') {
      return false; // Skip walking inside the function
    }
  });
  assert.ok(stopped.includes('rgba'));
  assert.ok(!stopped.includes('255'));
  assert.ok(stopped.includes('10px'));
}

// Contract 7: ValueParser toString serializes the AST back into equivalent CSS string
{
  const input = 'linear-gradient(to right, red, blue)';
  const parsed = ValueParser(input);
  assert.strictEqual(parsed.toString(), input);

  parsed.nodes[0].nodes[2].value = 'bottom';
  assert.strictEqual(parsed.toString(), 'linear-gradient(to bottom, red, blue)');
}

// Contract 8: ValueParser.unit parses CSS numeric values and dimension units
{
  assert.strictEqual(typeof ValueParser.unit, 'function');
  assert.deepStrictEqual(ValueParser.unit('12.5px'), {
    number: '12.5',
    unit: 'px'
  });
  assert.deepStrictEqual(ValueParser.unit('-4rem'), {
    number: '-4',
    unit: 'rem'
  });
  assert.deepStrictEqual(ValueParser.unit('100%'), {
    number: '100',
    unit: '%'
  });
  assert.deepStrictEqual(ValueParser.unit('42'), {
    number: '42',
    unit: ''
  });
  assert.strictEqual(ValueParser.unit('auto'), false);
  assert.strictEqual(ValueParser.unit(''), false);
}

// Contract 9: ValueParser.stringify serializes an array of AST nodes into CSS string
{
  assert.strictEqual(typeof ValueParser.stringify, 'function');
  const nodes = [
    { type: 'word', value: '1px' },
    { type: 'space', value: ' ' },
    { type: 'word', value: 'solid' },
    { type: 'space', value: ' ' },
    { type: 'word', value: 'black' }
  ];
  assert.strictEqual(ValueParser.stringify(nodes), '1px solid black');
}

console.log('All postcss-value-parser ValueParser contract tests passed.');

오리진 시더

익명