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…

sha256:e032b48d1433bb9e905245b2629521af6ad8f39b1d10fd938b9767665e356bbf

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.");

オリジンシーダー

匿名