CodeSampleX

サンプル

@jridgewell/trace-mapping 0.3.31: decodedMappings

検証済みサンプル — npm @jridgewell/trace-mapping 0.3.31: decodedMappings. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: decodedMappings returns the 2D…

sha256:746666cb523dc115e8464cf2c35d8f410532f4fd2ce37cf0f1101c2e5b0ed43d

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-05

ケース

HOW
ゴール
verify @jridgewell/trace-mapping.decodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31
パッケージ
シンボル
  • @jridgewell/trace-mapping.decodedMappings
環境
node 22.23.2
作成日
2026-09-05T13:23:26Z

コントラクト

  1. decodedMappings returns the 2D array of decoded segments from a TraceMap initialized with encoded VLQ string
  2. decodedMappings decodes 1-segment, 4-segment, and 5-segment mapping tokens into numeric tuples
  3. decodedMappings produces an array entry for every generated line including lines without mappings
  4. decodedMappings returns identical decoded mapping segments when initialized from decoded object or JSON string
  5. decodedMappings decodes empty string mappings to a single line with empty segments and preserves empty array mappings
  6. decodedMappings returns a consistent mapping structure across multiple calls on the same TraceMap instance

ファイル

  • 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/trace-mapping.decodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jridgewell/trace-mapping@0.3.31
Demonstrate these symbols/APIs:
  - @jridgewell/trace-mapping.decodedMappings
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:6666bafb3b3a0ae44070c09599de45d86fb958a09e7702fe4dca0254d5c2441c","constraints":{"executionContext":"node"},"contract":["decodedMappings returns the 2D array of decoded segments from a TraceMap initialized with encoded VLQ string","decodedMappings decodes 1-segment, 4-segment, and 5-segment mapping tokens into numeric tuples","decodedMappings produces an array entry for every generated line including lines without mappings","decodedMappings returns identical decoded mapping segments when initialized from decoded object or JSON string","decodedMappings decodes empty string mappings to a single line with empty segments and preserves empty array mappings","decodedMappings returns a consistent mapping structure across multiple calls on the same TraceMap instance"],"goal":"verify @jridgewell/trace-mapping.decodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31","kind":"HOW","packages":["pkg:npm/%40jridgewell/trace-mapping@0.3.31"],"schemaVersion":1,"symbols":["@jridgewell/trace-mapping.decodedMappings"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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/trace-mapping@0.3.31"],"schemaVersion":1,"subject":"pkg:npm/%40jridgewell/trace-mapping@0.3.31","symbols":["@jridgewell/trace-mapping.decodedMappings"],"verifierAdapter":"node-typescript@1"}
index.js
import { TraceMap, decodedMappings } from '@jridgewell/trace-mapping';

/**
 * Returns the decoded mappings array from a source map input or TraceMap instance.
 * @param {import('@jridgewell/trace-mapping').SourceMapInput | TraceMap} input
 * @returns {Readonly<import('@jridgewell/trace-mapping').DecodedSourceMap['mappings']>}
 */
export function getDecodedMappings(input) {
  const tracer = input instanceof TraceMap ? input : new TraceMap(input);
  return decodedMappings(tracer);
}

export { TraceMap, decodedMappings };
export default getDecodedMappings;
package-lock.json
{
  "name": "sample-trace-mapping-decoded-mappings",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-trace-mapping-decoded-mappings",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jridgewell/trace-mapping": "0.3.31"
      }
    },
    "node_modules/@jridgewell/resolve-uri": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
      "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "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"
    },
    "node_modules/@jridgewell/trace-mapping": {
      "version": "0.3.31",
      "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
      "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/resolve-uri": "^3.1.0",
        "@jridgewell/sourcemap-codec": "^1.4.14"
      }
    }
  }
}
package.json
{
  "name": "sample-trace-mapping-decoded-mappings",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@jridgewell/trace-mapping": "0.3.31"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @jridgewell/trace-mapping.decodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jridgewell/trace-mapping@0.3.31"
  ],
  "symbols": [
    "@jridgewell/trace-mapping.decodedMappings"
  ],
  "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/strict';
import { TraceMap, decodedMappings, getDecodedMappings } from '../index.js';

// 1. decodedMappings returns the 2D array of decoded segments from a TraceMap initialized with encoded VLQ string
{
  const encodedMap = {
    version: 3,
    file: 'bundle.js',
    sources: ['src/app.js'],
    sourcesContent: ['console.log("hello");'],
    names: ['console', 'log'],
    mappings: 'AAAA,SAASA,GAAG',
    sourceRoot: 'http://example.com/'
  };

  const tracer = new TraceMap(encodedMap);
  const mappings = decodedMappings(tracer);

  assert.ok(Array.isArray(mappings));
  assert.equal(mappings.length, 1);
  assert.ok(Array.isArray(mappings[0]));
  assert.ok(mappings[0].length >= 2);
  assert.ok(Array.isArray(mappings[0][0]));
  assert.equal(typeof mappings[0][0][0], 'number');
}

// 2. decodedMappings decodes 1-segment, 4-segment, and 5-segment mapping tokens into numeric tuples
{
  const mapData = {
    version: 3,
    sources: ['orig.js'],
    names: ['myVar'],
    mappings: 'A;AAAA;AAAAA'
  };

  const tracer = new TraceMap(mapData);
  const mappings = decodedMappings(tracer);

  assert.equal(mappings.length, 3);
  assert.deepEqual(mappings[0][0], [0]);
  assert.deepEqual(mappings[1][0], [0, 0, 0, 0]);
  assert.deepEqual(mappings[2][0], [0, 0, 0, 0, 0]);
}

// 3. decodedMappings produces an array entry for every generated line including lines without mappings
{
  const mapData = {
    version: 3,
    sources: ['source.js'],
    names: [],
    mappings: 'AAAA;;AAAA'
  };

  const tracer = new TraceMap(mapData);
  const mappings = decodedMappings(tracer);

  assert.equal(mappings.length, 3);
  assert.equal(mappings[0].length, 1);
  assert.deepEqual(mappings[1], []);
  assert.equal(mappings[2].length, 1);
}

// 4. decodedMappings returns identical decoded mapping segments when initialized from decoded object or JSON string
{
  const rawDecoded = {
    version: 3,
    file: 'test.js',
    sources: ['test.ts'],
    names: ['alpha'],
    mappings: [
      [[0, 0, 0, 0]],
      [[4, 0, 1, 2, 0]]
    ]
  };

  const tracerFromDecoded = new TraceMap(rawDecoded);
  const mappings1 = decodedMappings(tracerFromDecoded);
  assert.deepEqual(mappings1, [
    [[0, 0, 0, 0]],
    [[4, 0, 1, 2, 0]]
  ]);

  const jsonStr = JSON.stringify(rawDecoded);
  const tracerFromJson = new TraceMap(jsonStr);
  const mappings2 = decodedMappings(tracerFromJson);
  assert.deepEqual(mappings2, [
    [[0, 0, 0, 0]],
    [[4, 0, 1, 2, 0]]
  ]);

  const helperMappings = getDecodedMappings(rawDecoded);
  assert.deepEqual(helperMappings, mappings1);
}

// 5. decodedMappings decodes empty string mappings to a single line with empty segments and preserves empty array mappings
{
  const emptyStringMap = {
    version: 3,
    sources: [],
    names: [],
    mappings: ''
  };
  const tracerEmptyStr = new TraceMap(emptyStringMap);
  const mappingsEmptyStr = decodedMappings(tracerEmptyStr);
  assert.equal(mappingsEmptyStr.length, 1);
  assert.deepEqual(mappingsEmptyStr[0], []);

  const emptyArrayMap = {
    version: 3,
    sources: [],
    names: [],
    mappings: []
  };
  const tracerEmptyArr = new TraceMap(emptyArrayMap);
  const mappingsEmptyArr = decodedMappings(tracerEmptyArr);
  assert.equal(mappingsEmptyArr.length, 0);
  assert.deepEqual(mappingsEmptyArr, []);
}

// 6. decodedMappings returns a consistent mapping structure across multiple calls on the same TraceMap instance
{
  const mapData = {
    version: 3,
    sources: ['a.js'],
    names: [],
    mappings: 'AAAA;ACAA'
  };

  const tracer = new TraceMap(mapData);
  const mappingsFirst = decodedMappings(tracer);
  const mappingsSecond = decodedMappings(tracer);

  assert.deepEqual(mappingsFirst, mappingsSecond);
  assert.equal(mappingsFirst.length, mappingsSecond.length);
  assert.deepEqual(mappingsFirst[0], mappingsSecond[0]);
  assert.deepEqual(mappingsFirst[1], mappingsSecond[1]);
}

console.log('Contract tests passed successfully.');

オリジンシーダー

匿名