샘플
postcss 8.5.26: parse
검증된 샘플 — npm postcss 8.5.26: parse. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: postcss.parse is exported as a function from postcss
sha256:0a611587400ea5a23256bf6b76d0f257e9f3ad1ad200bb58af961cacfeb70e66
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 postcss.parse in pkg:npm/postcss@8.5.26
- 패키지
- 심벌
-
- postcss.parse
- 생성일
- 2026-08-27T02:13:11Z
컨트랙트
- postcss.parse is exported as a function from postcss
- postcss.parse returns a Root AST node with type 'root' for valid CSS string
- postcss.parse populates child nodes with rule, declaration, and at-rule AST structures
- postcss.parse accepts options object including from path and propagates to source.input
- postcss.parse handles comments and whitespace without losing structural nodes
- postcss.parse throws CssSyntaxError when parsing malformed or unclosed CSS blocks
- postcss.parse parsed Root node serializes back to CSS string matching input via toString
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
소스
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 postcss.parse 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:
- postcss.parse
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.
{"case":{"caseId":"case:sha256:ae61485afade347c3dffe2352fbb39afdfb1b5fea06cd6034cf0c57701629fa3","contract":["postcss.parse is exported as a function from postcss","postcss.parse returns a Root AST node with type 'root' for valid CSS string","postcss.parse populates child nodes with rule, declaration, and at-rule AST structures","postcss.parse accepts options object including from path and propagates to source.input","postcss.parse handles comments and whitespace without losing structural nodes","postcss.parse throws CssSyntaxError when parsing malformed or unclosed CSS blocks","postcss.parse parsed Root node serializes back to CSS string matching input via toString"],"goal":"verify postcss.parse in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["postcss.parse"]},"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@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["postcss.parse"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-postcss-parse",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-postcss-parse",
"version": "1.0.0",
"license": "MIT-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==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"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==",
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/postcss/"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/postcss"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"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"
}
}
}
}
{
"name": "sample-postcss-parse",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for postcss.parse in postcss@8.5.26",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"postcss": "8.5.26"
}
}
{
"schemaVersion": 1,
"goal": "verify postcss.parse in pkg:npm/postcss@8.5.26",
"kind": "HOW",
"packages": [
"pkg:npm/postcss@8.5.26"
],
"symbols": [
"postcss.parse"
]
}
const postcss = require('postcss');
/**
* Parses CSS text into a PostCSS AST Root node.
*
* @param {string} css - The CSS string to parse.
* @param {object} [opts] - Optional parsing options (e.g. { from: string }).
* @returns {object} PostCSS Root AST node.
*/
function parseCss(css, opts) {
return postcss.parse(css, opts);
}
/**
* Checks whether a given string contains valid CSS syntax without throwing.
*
* @param {string} css - The CSS string to check.
* @returns {boolean} True if syntax is valid CSS, false otherwise.
*/
function isValidCss(css) {
try {
postcss.parse(css);
return true;
} catch (err) {
if (err.name === 'CssSyntaxError') {
return false;
}
throw err;
}
}
/**
* Extracts all rule selectors from CSS string.
*
* @param {string} css - The CSS string to inspect.
* @returns {string[]} Array of selector strings.
*/
function extractSelectors(css) {
const root = postcss.parse(css);
const selectors = [];
root.walkRules((rule) => {
selectors.push(rule.selector);
});
return selectors;
}
module.exports = {
postcss,
parseCss,
isValidCss,
extractSelectors
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
postcss,
parseCss,
isValidCss,
extractSelectors
} = require('../src/index.js');
async function runTests() {
// 1. postcss.parse is exported as a function from postcss
assert.equal(typeof postcss.parse, 'function', 'postcss.parse must be a function');
assert.equal(typeof parseCss, 'function', 'parseCss helper must be a function');
assert.equal(typeof isValidCss, 'function', 'isValidCss helper must be a function');
assert.equal(typeof extractSelectors, 'function', 'extractSelectors helper must be a function');
// 2. postcss.parse returns a Root AST node with type 'root' for valid CSS string
const emptyRoot = parseCss('');
assert.equal(emptyRoot.type, 'root', 'Empty string parses to a root AST node');
assert.equal(Array.isArray(emptyRoot.nodes), true, 'root.nodes must be an array');
assert.equal(emptyRoot.nodes.length, 0, 'Empty CSS produces zero nodes');
const css = 'a { color: red; }';
const root = parseCss(css);
assert.equal(root.type, 'root', 'Root node type must be root');
assert.equal(root.nodes.length, 1, 'Single rule produces one top-level node');
// 3. postcss.parse populates child nodes with rule, declaration, and at-rule AST structures
const complexCss = `
@charset "UTF-8";
@media (min-width: 600px) {
.card {
padding: 16px;
margin: 0 auto;
}
}
h1, h2 {
font-size: 2rem;
}
`;
const complexRoot = parseCss(complexCss);
assert.equal(complexRoot.nodes.length, 3, 'Expected 3 top-level nodes in complex CSS');
const [atCharset, atMedia, ruleH] = complexRoot.nodes;
assert.equal(atCharset.type, 'atrule');
assert.equal(atCharset.name, 'charset');
assert.equal(atCharset.params, '"UTF-8"');
assert.equal(atMedia.type, 'atrule');
assert.equal(atMedia.name, 'media');
assert.equal(atMedia.params, '(min-width: 600px)');
assert.equal(atMedia.nodes.length, 1);
assert.equal(atMedia.first.type, 'rule');
assert.equal(atMedia.first.selector, '.card');
assert.equal(atMedia.first.nodes.length, 2);
assert.equal(atMedia.first.nodes[0].type, 'decl');
assert.equal(atMedia.first.nodes[0].prop, 'padding');
assert.equal(atMedia.first.nodes[0].value, '16px');
assert.equal(atMedia.first.nodes[1].type, 'decl');
assert.equal(atMedia.first.nodes[1].prop, 'margin');
assert.equal(atMedia.first.nodes[1].value, '0 auto');
assert.equal(ruleH.type, 'rule');
assert.equal(ruleH.selector, 'h1, h2');
assert.equal(ruleH.first.type, 'decl');
assert.equal(ruleH.first.prop, 'font-size');
assert.equal(ruleH.first.value, '2rem');
const selectors = extractSelectors(complexCss);
assert.deepEqual(selectors, ['.card', 'h1, h2']);
// 4. postcss.parse accepts options object including from path and propagates to source.input
const rootWithOptions = parseCss('body { margin: 0; }', { from: '/path/to/style.css' });
assert.ok(rootWithOptions.source, 'Root node has source information');
assert.ok(rootWithOptions.source.input, 'Source has input descriptor');
assert.equal(rootWithOptions.source.input.from, '/path/to/style.css', 'from option is preserved on input');
// 5. postcss.parse handles comments and whitespace without losing structural nodes
const commentedCss = '/* header styles */ nav { display: flex; /* align */ }';
const commentedRoot = parseCss(commentedCss);
assert.equal(commentedRoot.nodes.length, 2, 'Comment and rule are top-level nodes');
assert.equal(commentedRoot.nodes[0].type, 'comment');
assert.equal(commentedRoot.nodes[0].text, 'header styles');
assert.equal(commentedRoot.nodes[1].type, 'rule');
assert.equal(commentedRoot.nodes[1].nodes.length, 2);
assert.equal(commentedRoot.nodes[1].nodes[0].type, 'decl');
assert.equal(commentedRoot.nodes[1].nodes[1].type, 'comment');
assert.equal(commentedRoot.nodes[1].nodes[1].text, 'align');
// 6. postcss.parse throws CssSyntaxError when parsing malformed or unclosed CSS blocks
const invalidCss = 'a { color: red';
assert.equal(isValidCss('a { color: red; }'), true);
assert.equal(isValidCss(invalidCss), false);
assert.throws(
() => parseCss(invalidCss),
(err) => {
assert.equal(err.name, 'CssSyntaxError', 'Error name must be CssSyntaxError');
assert.equal(typeof err.line, 'number', 'CssSyntaxError must have line number');
assert.equal(typeof err.column, 'number', 'CssSyntaxError must have column number');
assert.equal(typeof err.reason, 'string', 'CssSyntaxError must have reason string');
return true;
}
);
// 7. postcss.parse parsed Root node serializes back to CSS string matching input via toString
const inputSnippet = 'button.primary { background-color: #007bff; border: none; }';
const parsedRoot = parseCss(inputSnippet);
assert.equal(parsedRoot.toString(), inputSnippet, 'toString() output must match original input text');
console.log('All contract assertions for postcss.parse passed successfully.');
}
runTests().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
오리진 시더
익명