샘플
@babel/code-frame 8.0.0: highlight
검증된 샘플 — npm @babel/code-frame 8.0.0: highlight. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: highlight returns an empty string when given an…
sha256:ef05de32bf21663da156edab42e53eae497e790e8e79ab77582175039119bf2f
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-20 |
케이스
HOW- 목표
- verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0
- 심벌
-
- @babel/code-frame.highlight
- 환경
- node 22.23.2
- 생성일
- 2026-08-20T21:01:37Z
컨트랙트
- highlight returns an empty string when given an empty input string
- highlight formats JavaScript keywords with cyan ANSI escape sequences
- highlight formats string literals with green ANSI color codes and numeric literals with magenta
- highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow
- highlight colors JSX element tags and capitalized component identifiers
- stripAnsiEscapeCodes restores the original source code text from highlighted output
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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 @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/code-frame@8.0.0
Demonstrate these symbols/APIs:
- @babel/code-frame.highlight
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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.
{"case":{"caseId":"case:sha256:04529d4a687cd068e3eab1ea81f467a541dfee39c203666821eb6390eb5e75fc","constraints":{"executionContext":"node"},"contract":["highlight returns an empty string when given an empty input string","highlight formats JavaScript keywords with cyan ANSI escape sequences","highlight formats string literals with green ANSI color codes and numeric literals with magenta","highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow","highlight colors JSX element tags and capitalized component identifiers","stripAnsiEscapeCodes restores the original source code text from highlighted output"],"goal":"verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0","kind":"HOW","packages":["pkg:npm/%40babel/code-frame@8.0.0"],"schemaVersion":1,"symbols":["@babel/code-frame.highlight"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/code-frame@8.0.0"],"schemaVersion":1,"subject":"pkg:npm/%40babel/code-frame@8.0.0","symbols":["@babel/code-frame.highlight"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-babel-code-frame-highlight",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-babel-code-frame-highlight",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/code-frame": "8.0.0"
}
},
"node_modules/@babel/code-frame": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-8.0.0.tgz",
"integrity": "sha512-dYYg153EyN2Ekbqw2zAsbd6/JR+9N2SEoC7YV2GyyqMM7x9bLDTjBD6XBhSMLH0wtIVyJj03jWNriQhaN+eoCw==",
"license": "MIT",
"dependencies": {
"@babel/helper-validator-identifier": "^8.0.0",
"js-tokens": "^10.0.0"
},
"engines": {
"node": "^22.18.0 || >=24.11.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "8.0.4",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.4.tgz",
"integrity": "sha512-4wFaiLd0bVo4cIoTXI3zKI038NIWE/cr3jvBjejOVYVxV/m8Ltav1USiGzG1fmS5J2RhgEOgXNNK46cRPnRsrg==",
"license": "MIT",
"engines": {
"node": "^22.18.0 || >=24.11.0"
}
},
"node_modules/js-tokens": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz",
"integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==",
"license": "MIT"
}
}
}
{
"name": "sample-babel-code-frame-highlight",
"version": "1.0.0",
"description": "verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"@babel/code-frame": "8.0.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/code-frame@8.0.0"
],
"symbols": [
"@babel/code-frame.highlight"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
const { highlight } = require('@babel/code-frame');
/**
* Highlights a given source code string using Babel code-frame syntax highlighting.
*
* @param {string} source - The source code string to highlight.
* @returns {string} The ANSI highlighted source string.
*/
function highlightSource(source) {
return highlight(source);
}
/**
* Checks if the highlighted output contains ANSI escape sequences.
*
* @param {string} text - The text to check.
* @returns {boolean} True if ANSI escape sequences are present.
*/
function hasAnsiEscapeCodes(text) {
const ansiPattern = /\u001b\[\d+(?:;\d+)*m/;
return ansiPattern.test(text);
}
/**
* Strips ANSI escape sequences from a string to recover the original plain text.
*
* @param {string} text - The ANSI styled text.
* @returns {string} The raw plain text without styling.
*/
function stripAnsiEscapeCodes(text) {
return text.replace(/\u001b\[\d+(?:;\d+)*m/g, '');
}
module.exports = {
highlightSource,
hasAnsiEscapeCodes,
stripAnsiEscapeCodes
};
const assert = require('assert');
const { highlight } = require('@babel/code-frame');
const {
highlightSource,
hasAnsiEscapeCodes,
stripAnsiEscapeCodes
} = require('../src/index');
// 1. highlight returns an empty string when given an empty input string
{
const result = highlightSource('');
assert.strictEqual(result, '', 'Empty input string must return empty string');
assert.strictEqual(hasAnsiEscapeCodes(result), false, 'Empty result must not have ANSI codes');
}
// 2. highlight formats JavaScript keywords with cyan ANSI escape sequences
{
const code = 'const count = function() { return 42; };';
const highlighted = highlightSource(code);
assert(hasAnsiEscapeCodes(highlighted), 'Highlighted code must contain ANSI escape codes');
assert(highlighted.includes('\u001b[36mconst\u001b[39m'), 'const keyword must be highlighted in cyan');
assert(highlighted.includes('\u001b[36mfunction\u001b[39m'), 'function keyword must be highlighted in cyan');
assert(highlighted.includes('\u001b[36mreturn\u001b[39m'), 'return keyword must be highlighted in cyan');
}
// 3. highlight formats string literals with green ANSI color codes and numeric literals with magenta
{
const code = 'const greeting = "hello world"; const val = 12345;';
const highlighted = highlightSource(code);
assert(highlighted.includes('\u001b[32m"hello world"\u001b[39m'), 'String literal must be highlighted in green');
assert(highlighted.includes('\u001b[35m12345\u001b[39m'), 'Numeric literal must be highlighted in magenta');
}
// 4. highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow
{
const code = '// calculate value\nlet x = 10;';
const highlighted = highlightSource(code);
assert(highlighted.includes('\u001b[90m// calculate value\u001b[39m'), 'Comments must be highlighted in gray');
assert(highlighted.includes('\u001b[33m=\u001b[39m'), 'Assignment operator must be highlighted in yellow');
assert(highlighted.includes('\u001b[33m;\u001b[39m'), 'Semicolon must be highlighted in yellow');
}
// 5. highlight colors JSX element tags and capitalized component identifiers
{
const code = '<MyComponent active={true} />';
const highlighted = highlightSource(code);
assert(highlighted.includes('\u001b[33mMyComponent\u001b[39m'), 'Capitalized component name must be highlighted');
assert(highlighted.includes('\u001b[33m<\u001b[39m'), 'Opening JSX bracket must be highlighted');
assert(highlighted.includes('\u001b[33m>\u001b[39m'), 'Closing JSX bracket must be highlighted');
}
// 6. stripAnsiEscapeCodes restores the original source code text from highlighted output
{
const originalCode = 'function add(a, b) {\n // sum two numbers\n return a + b;\n}';
const highlighted = highlightSource(originalCode);
const restored = stripAnsiEscapeCodes(highlighted);
assert.strictEqual(restored, originalCode, 'Stripping ANSI codes must restore the exact original source code');
}
console.log('All contract assertions passed successfully.');
오리진 시더
익명