CodeSampleX

サンプル

@babel/code-frame 7.29.7: default

検証済みサンプル — npm @babel/code-frame 7.29.7: default. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: default exports a function that formats code…

sha256:b01ae7dd2bf4ff7262dcdfe35c6816586d195f1ef20d5806dfc79d819a914f49

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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.default in pkg:npm/%40babel/code-frame@7.29.7
パッケージ
シンボル
  • @babel/code-frame.default
作成日
2026-08-23T04:33:58Z

コントラクト

  1. default exports a function that formats code frames pointing to a line and column location
  2. default highlights a single line-column location with gutter line numbers, active line indicator, and caret marker
  3. default highlights an entire line when column number is zero or omitted
  4. default attaches a custom error message next to the highlighted caret marker
  5. default restricts surrounding visible context using linesAbove and linesBelow options
  6. default offsets displayed line numbers using startLine option

ファイル

  • 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.default 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.default

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:2fec056b1739fc67870bf3715408de0bbed84a4999d185516b169cb54a2a5203","contract":["default exports a function that formats code frames pointing to a line and column location","default highlights a single line-column location with gutter line numbers, active line indicator, and caret marker","default highlights an entire line when column number is zero or omitted","default attaches a custom error message next to the highlighted caret marker","default restricts surrounding visible context using linesAbove and linesBelow options","default offsets displayed line numbers using startLine option"],"goal":"verify @babel/code-frame.default 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.default"]},"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.default"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-code-frame-default",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-code-frame-default",
      "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-default",
  "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.default in pkg:npm/%40babel/code-frame@7.29.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/code-frame@7.29.7"
  ],
  "symbols": [
    "@babel/code-frame.default"
  ]
}
src/index.mjs
import pkg from "@babel/code-frame";

const codeFrame = pkg.default || pkg;

export function formatCodeFrame(rawLines, lineNumber, colNumber, options = {}) {
  return codeFrame(rawLines, lineNumber, colNumber, options);
}

export function formatCodeFrameWithContext(rawLines, lineNumber, colNumber, linesAbove, linesBelow) {
  return codeFrame(rawLines, lineNumber, colNumber, {
    highlightCode: false,
    linesAbove,
    linesBelow
  });
}

export function formatCodeFrameWithMessage(rawLines, lineNumber, colNumber, message) {
  return codeFrame(rawLines, lineNumber, colNumber, {
    highlightCode: false,
    message
  });
}
test/contract.mjs
import assert from "node:assert/strict";
import pkg from "@babel/code-frame";
import { formatCodeFrame, formatCodeFrameWithContext, formatCodeFrameWithMessage } from "../src/index.mjs";

const codeFrame = pkg.default || pkg;

const sampleCode = [
  "function calculateTotal(items) {",
  "  let total = 0;",
  "  for (const item of items) {",
  "    total += item.price * item.quantity;",
  "  }",
  "  return total;",
  "}"
].join("\n");

// Test 1: default exports a function that formats code frames pointing to a line and column location
{
  assert.equal(typeof codeFrame, "function", "default export must be a function");
  const frame = formatCodeFrame(sampleCode, 4, 13, { highlightCode: false });
  assert.ok(typeof frame === "string", "code frame must return a string");
  assert.ok(frame.includes("total += item.price * item.quantity;"), "must contain target line content");
}

// Test 2: default highlights a single line-column location with gutter line numbers, active line indicator, and caret marker
{
  const frame = formatCodeFrame(sampleCode, 4, 13, { highlightCode: false });
  assert.ok(frame.includes("> 4 |"), "must include active line pointer and line number");
  assert.ok(frame.includes("    |"), "must include gutter for marker line");
  assert.ok(frame.includes("            ^"), "must place caret marker at target column position");
}

// Test 3: default highlights an entire line when column number is zero or omitted
{
  const frame = formatCodeFrame(sampleCode, 4, 0, { highlightCode: false });
  assert.ok(frame.includes("> 4 |"), "must mark target line with active indicator");
  assert.ok(!frame.includes("^"), "must not include caret marker when column is 0");
}

// Test 4: default attaches a custom error message next to the highlighted caret marker
{
  const message = "Invalid price calculation";
  const frame = formatCodeFrameWithMessage(sampleCode, 4, 13, message);
  assert.ok(frame.includes(`^ ${message}`), "must append error message after caret marker");
}

// Test 5: default restricts surrounding visible context using linesAbove and linesBelow options
{
  const frame = formatCodeFrameWithContext(sampleCode, 4, 13, 1, 1);
  assert.ok(!frame.includes("1 | function calculateTotal"), "line 1 must be excluded");
  assert.ok(!frame.includes("2 |   let total = 0;"), "line 2 must be excluded");
  assert.ok(frame.includes("3 |   for (const item of items) {"), "line 3 must be included");
  assert.ok(frame.includes("> 4 |"), "line 4 must be included");
  assert.ok(frame.includes("5 |   }"), "line 5 must be included");
  assert.ok(!frame.includes("6 |   return total;"), "line 6 must be excluded");
}

// Test 6: default offsets displayed line numbers using startLine option
{
  const snippet = "const x = 10;\nconst y = 20;\nconst z = x + y;";
  const frame = formatCodeFrame(snippet, 102, 7, { highlightCode: false, startLine: 100 });
  assert.ok(frame.includes("100 | const x = 10;"), "must display line 100");
  assert.ok(frame.includes("101 | const y = 20;"), "must display line 101");
  assert.ok(frame.includes("> 102 | const z = x + y;"), "must display active line 102");
  assert.ok(frame.includes("      |       ^"), "must display caret marker at offset column");
}

console.log("All @babel/code-frame.default contract tests passed successfully.");

オリジンシーダー

匿名