CodeSampleX

サンプル

@jridgewell/sourcemap-codec 1.5.5: encode

検証済みサンプル — npm @jridgewell/sourcemap-codec 1.5.5: encode. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert encode returns empty string for…

sha256:62dc75e179df56da14dc1096fd4b3ee66378a0cd7f53641da83954d6d7f3fdfc

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-27

ケース

HOW
ゴール
verify @jridgewell/sourcemap-codec.encode in pkg:npm/%40jridgewell/sourcemap-codec@1.5.5
パッケージ
シンボル
  • @jridgewell/sourcemap-codec.encode
環境
node 22.23.2
作成日
2026-08-27T21:19:01Z

コントラクト

  1. assert encode returns empty string for empty mappings
  2. assert encode separates empty lines with semicolons
  3. assert encode encodes single-field segments containing only generated column
  4. assert encode encodes 4-field segments containing generated column source index original line and original column
  5. assert encode encodes 5-field segments containing name index and applies relative delta encoding
  6. assert encode correctly encodes multi-line mappings and roundtrips with decode

ファイル

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 @jridgewell/sourcemap-codec.encode in pkg:npm/%40jridgewell/sourcemap-codec@1.5.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jridgewell/sourcemap-codec@1.5.5
Demonstrate these symbols/APIs:
  - @jridgewell/sourcemap-codec.encode
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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.
csx.json
{"case":{"caseId":"case:sha256:d4b999e3e34ac4feefbbad279de909a26a94b1dbadf2ffb9696de5bb7da266bb","constraints":{"executionContext":"node"},"contract":["assert encode returns empty string for empty mappings","assert encode separates empty lines with semicolons","assert encode encodes single-field segments containing only generated column","assert encode encodes 4-field segments containing generated column source index original line and original column","assert encode encodes 5-field segments containing name index and applies relative delta encoding","assert encode correctly encodes multi-line mappings and roundtrips with decode"],"goal":"verify @jridgewell/sourcemap-codec.encode in pkg:npm/%40jridgewell/sourcemap-codec@1.5.5","kind":"HOW","packages":["pkg:npm/%40jridgewell/sourcemap-codec@1.5.5"],"schemaVersion":1,"symbols":["@jridgewell/sourcemap-codec.encode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40jridgewell/sourcemap-codec@1.5.5"],"schemaVersion":1,"subject":"pkg:npm/%40jridgewell/sourcemap-codec@1.5.5","symbols":["@jridgewell/sourcemap-codec.encode"],"verifierAdapter":"node-typescript@1"}
index.js
const { encode, decode } = require('@jridgewell/sourcemap-codec');

/**
 * Encodes decoded source map line segments into a VLQ mapping string.
 *
 * @param {Array<Array<Array<number>>>} decoded - Decoded source map mappings.
 * @returns {string} Encoded source map mappings string.
 */
function encodeMappings(decoded) {
  return encode(decoded);
}

module.exports = {
  encodeMappings,
  encode,
  decode,
};
package-lock.json
{
  "name": "sample-sourcemap-codec-encode",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sourcemap-codec-encode",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "1.5.5"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-sourcemap-codec-encode",
  "version": "1.0.0",
  "description": "Clean-room sample verifying @jridgewell/sourcemap-codec.encode",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "@jridgewell/sourcemap-codec": "1.5.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @jridgewell/sourcemap-codec.encode in pkg:npm/%40jridgewell/sourcemap-codec@1.5.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jridgewell/sourcemap-codec@1.5.5"
  ],
  "symbols": [
    "@jridgewell/sourcemap-codec.encode"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import { encode, decode } from '@jridgewell/sourcemap-codec';
import { encodeMappings } from '../index.js';

// 1. Encode empty line mappings returns empty string
assert.strictEqual(encodeMappings([]), '', 'encode must return empty string for empty mappings');

// 2. Encode lines with empty segment arrays separated by semicolons
assert.strictEqual(
  encodeMappings([[], []]),
  ';',
  'encode must separate empty lines with semicolons'
);
assert.strictEqual(
  encodeMappings([[], [], []]),
  ';;',
  'encode must generate consecutive semicolons for multiple empty lines'
);

// 3. Encode single-field segments (generated column only)
assert.strictEqual(
  encodeMappings([[[0]], [[5]]]),
  'A;K',
  'encode must encode 1-field segments with generated column only'
);

// 4. Encode 4-field segments with generated column, source index, original line, original column
assert.strictEqual(
  encodeMappings([[[0, 0, 0, 0]]]),
  'AAAA',
  'encode must encode standard 4-field segment'
);
assert.strictEqual(
  encodeMappings([[[0, 0, 0, 0], [4, 0, 0, 4]]]),
  'AAAA,IAAI',
  'encode must encode multiple segments per line with comma separation and relative delta encoding'
);

// 5. Encode 5-field segments including name index
assert.strictEqual(
  encodeMappings([[[0, 0, 0, 0, 0]]]),
  'AAAAA',
  'encode must encode 5-field segment with name index'
);
assert.strictEqual(
  encodeMappings([[[0, 0, 0, 0, 0], [4, 0, 0, 4, 1]]]),
  'AAAAA,IAAIC',
  'encode must delta-encode name index across adjacent 5-field segments'
);

// 6. Encode multi-line mappings and verify roundtrip decoding
const complexMappings = [
  [[0, 0, 0, 0]],
  [[0, 0, 1, 0]],
  [[2, 0, 2, 5, 0]],
];
const encodedString = encodeMappings(complexMappings);
assert.strictEqual(
  encodedString,
  'AAAA;AACA;EACKA',
  'encode must encode complex multiline mappings with correct state offsets'
);
assert.deepStrictEqual(
  decode(encodedString),
  complexMappings,
  'decode must roundtrip correctly with encode output'
);

console.log('All @jridgewell/sourcemap-codec.encode contract assertions passed.');

オリジンシーダー

匿名