示例
@babel/code-frame 7.29.7: highlight
已验证示例 — npm @babel/code-frame 7.29.7: highlight. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: highlight returns an empty string when given an empty…
sha256:e032b48d1433bb9e905245b2629521af6ad8f39b1d10fd938b9767665e356bbf
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
案例
HOW- 目标
- verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@7.29.7
- 符号
-
- @babel/code-frame.highlight
- 创建时间
- 2026-08-23T04:29:30Z
契约
- 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 comments with gray ANSI escape codes and punctuators with yellow
- highlight colors JSX syntax elements including tags and component names
- stripAnsiEscapeCodes restores the original source code text from highlighted output
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- 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 @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@7.29.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/code-frame@7.29.7
Demonstrate these symbols/APIs:
- @babel/code-frame.highlight
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:78aaab708b3fd8ce7a3d521b4a6f0051de70114c43bbf36b3d4305a86000693c","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 comments with gray ANSI escape codes and punctuators with yellow","highlight colors JSX syntax elements including tags and component names","stripAnsiEscapeCodes restores the original source code text from highlighted output"],"goal":"verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/code-frame@7.29.7"],"schemaVersion":1,"symbols":["@babel/code-frame.highlight"]},"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/%40babel/code-frame@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/code-frame@7.29.7","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": "7.29.7"
}
},
"node_modules/@babel/code-frame": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz",
"integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==",
"license": "MIT",
"dependencies": {
"@babel/helper-validator-identifier": "^7.29.7",
"js-tokens": "^4.0.0",
"picocolors": "^1.1.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
"integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"license": "MIT"
},
"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"
}
}
}
{
"name": "sample-babel-code-frame-highlight",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"@babel/code-frame": "7.29.7"
}
}
{
"schemaVersion": 1,
"goal": "verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@7.29.7",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/code-frame@7.29.7"
],
"symbols": [
"@babel/code-frame.highlight"
]
}
import { highlight } from "@babel/code-frame";
export function highlightCode(code) {
return highlight(code);
}
export function stripAnsiEscapeCodes(str) {
return str.replace(/\u001b\[[0-9;]*m/g, "");
}
import assert from "node:assert/strict";
import { highlight } from "@babel/code-frame";
import { highlightCode, stripAnsiEscapeCodes } from "../src/index.mjs";
// Test 1: highlight returns an empty string when given an empty input string
{
const result = highlightCode("");
assert.equal(result, "");
}
// Test 2: highlight formats JavaScript keywords with cyan ANSI escape sequences
{
const code = "const x = 1; function test() { return true; }";
const highlighted = highlightCode(code);
assert.ok(highlighted.includes("\u001b[36mconst\u001b[39m"), "const should be colored cyan");
assert.ok(highlighted.includes("\u001b[36mfunction\u001b[39m"), "function should be colored cyan");
assert.ok(highlighted.includes("\u001b[36mreturn\u001b[39m"), "return should be colored cyan");
}
// Test 3: highlight formats string literals with green ANSI color codes and numeric literals with magenta
{
const code = 'const greeting = "hello"; const count = 42;';
const highlighted = highlightCode(code);
assert.ok(highlighted.includes('\u001b[32m"hello"\u001b[39m'), 'string literal should be colored green');
assert.ok(highlighted.includes('\u001b[35m42\u001b[39m'), 'numeric literal should be colored magenta');
}
// Test 4: highlight formats comments with gray ANSI escape codes and punctuators with yellow
{
const code = "// calculate total\na = b + c;";
const highlighted = highlightCode(code);
assert.ok(highlighted.includes("\u001b[90m// calculate total\u001b[39m"), "comment should be colored gray");
assert.ok(highlighted.includes("\u001b[33m=\u001b[39m"), "= should be colored yellow");
assert.ok(highlighted.includes("\u001b[33m+\u001b[39m"), "+ should be colored yellow");
assert.ok(highlighted.includes("\u001b[33m;\u001b[39m"), "; should be colored yellow");
}
// Test 5: highlight colors JSX syntax elements including tags and component names
{
const code = "<AppContainer title=\"main\"><Button>Click</Button></AppContainer>";
const highlighted = highlightCode(code);
assert.ok(highlighted.includes("\u001b[33m<\u001b[39m"), "< should be colored yellow");
assert.ok(highlighted.includes("\u001b[33mAppContainer\u001b[39m"), "component name should be colored yellow");
assert.ok(highlighted.includes("\u001b[33mButton\u001b[39m"), "nested component name should be colored yellow");
}
// Test 6: stripAnsiEscapeCodes restores the original source code text from highlighted output
{
const inputs = [
"",
"const value = 100;",
"function render() {\n return <Component key={1}>{'text'}</Component>;\n}",
"// single line comment\nlet x = 'string';"
];
for (const input of inputs) {
const highlighted = highlightCode(input);
const restored = stripAnsiEscapeCodes(highlighted);
assert.equal(restored, input, "Restored text must match original input exactly");
}
}
console.log("All @babel/code-frame.highlight contract tests passed successfully.");
原始种子者
匿名