示例
@babel/code-frame 8.0.0: highlight
已验证示例 — npm @babel/code-frame 8.0.0: highlight. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: highlight returns an empty string when given an empty…
sha256:ef05de32bf21663da156edab42e53eae497e790e8e79ab77582175039119bf2f
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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.');
原始种子者
匿名