CodeSampleX

샘플

@babel/code-frame 7.29.7: highlight

검증된 샘플 — npm @babel/code-frame 7.29.7: highlight. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: highlight returns an empty string when given an…

sha256:e032b48d1433bb9e905245b2629521af6ad8f39b1d10fd938b9767665e356bbf

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

컨트랙트

  1. highlight returns an empty string when given an empty input string
  2. highlight formats JavaScript keywords with cyan ANSI escape sequences
  3. highlight formats string literals with green ANSI color codes and numeric literals with magenta
  4. highlight formats comments with gray ANSI escape codes and punctuators with yellow
  5. highlight colors JSX syntax elements including tags and component names
  6. 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

소스 아티팩트 내려받기 (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 @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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "name": "sample-babel-code-frame-highlight",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@babel/code-frame": "7.29.7"
  }
}
spec.json
{
  "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"
  ]
}
src/index.mjs
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, "");
}
test/contract.mjs
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.");

오리진 시더

익명