CodeSampleX

Beispiel

@jridgewell/trace-mapping 0.3.31: encodedMappings

Verifiziertes Beispiel für npm @jridgewell/trace-mapping 0.3.31: encodedMappings. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:b1366149c9f5884309b77ef0c2125e866b544adaf2f1d4773682808c2bc12936

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify @jridgewell/trace-mapping.encodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31
Pakete
Symbole
  • @jridgewell/trace-mapping.encodedMappings
Umgebung
node 22.23.2
Erstellt
2026-09-05T13:55:59Z

Contract

  1. encodedMappings returns the VLQ-encoded string from a TraceMap initialized with an encoded mappings string
  2. encodedMappings encodes a 2D array of decoded mapping segments into a standard VLQ mappings string
  3. encodedMappings preserves empty line semicolons when encoding multi-line mappings
  4. encodedMappings returns an empty string when initialized with empty string mappings or an empty array
  5. encodedMappings returns identical cached string across multiple calls on the same TraceMap instance
  6. getEncodedMappings helper function accepts either a TraceMap instance or raw source map input

Dateien

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

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.encodedMappings 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.encodedMappings

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:2b77f0f9cefe2e13b6948dc32c66568cd50400883267a283fc0586ab1b9fff88","contract":["encodedMappings returns the VLQ-encoded string from a TraceMap initialized with an encoded mappings string","encodedMappings encodes a 2D array of decoded mapping segments into a standard VLQ mappings string","encodedMappings preserves empty line semicolons when encoding multi-line mappings","encodedMappings returns an empty string when initialized with empty string mappings or an empty array","encodedMappings returns identical cached string across multiple calls on the same TraceMap instance","getEncodedMappings helper function accepts either a TraceMap instance or raw source map input"],"goal":"verify @jridgewell/trace-mapping.encodedMappings 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.encodedMappings"]},"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.encodedMappings"],"verifierAdapter":"node-typescript@1"}
index.js
import { TraceMap, encodedMappings } from '@jridgewell/trace-mapping';

/**
 * Returns the VLQ-encoded mappings string from a source map input or TraceMap instance.
 * @param {import('@jridgewell/trace-mapping').SourceMapInput | TraceMap} input
 * @returns {string}
 */
export function getEncodedMappings(input) {
  const tracer = input instanceof TraceMap ? input : new TraceMap(input);
  return encodedMappings(tracer);
}

export { TraceMap, encodedMappings };
export default getEncodedMappings;
package-lock.json
{
  "name": "sample-trace-mapping-encoded-mappings",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-trace-mapping-encoded-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-encoded-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.encodedMappings in pkg:npm/%40jridgewell/trace-mapping@0.3.31",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jridgewell/trace-mapping@0.3.31"
  ],
  "symbols": [
    "@jridgewell/trace-mapping.encodedMappings"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { TraceMap, encodedMappings, getEncodedMappings } from '../index.js';

// 1. encodedMappings returns the VLQ-encoded string from a TraceMap initialized with an encoded mappings string
{
  const encodedMapInput = {
    version: 3,
    file: 'bundle.js',
    sources: ['src/main.js'],
    sourcesContent: ['console.log("hello");'],
    names: ['console', 'log'],
    mappings: 'AAAA,SAASA,GAAG'
  };
  const tracer = new TraceMap(encodedMapInput);
  const result = encodedMappings(tracer);

  assert.equal(typeof result, 'string');
  assert.equal(result, 'AAAA,SAASA,GAAG');
}

// 2. encodedMappings encodes a 2D array of decoded mapping segments into a standard VLQ mappings string
{
  const decodedMapInput = {
    version: 3,
    file: 'bundle.js',
    sources: ['foo.js'],
    sourcesContent: ['function foo() { return 1; }'],
    names: ['foo'],
    mappings: [
      [[0, 0, 0, 0, 0], [10, 0, 0, 9]],
      [[0, 0, 0, 16]]
    ]
  };
  const tracer = new TraceMap(decodedMapInput);
  const result = encodedMappings(tracer);

  assert.equal(typeof result, 'string');
  assert.equal(result, 'AAAAA,UAAS;AAAO');
}

// 3. encodedMappings preserves empty line semicolons when encoding multi-line mappings
{
  const multiLineMap = {
    version: 3,
    sources: ['source.js'],
    names: [],
    mappings: 'AAAA;;AAAA'
  };
  const tracerFromEncoded = new TraceMap(multiLineMap);
  assert.equal(encodedMappings(tracerFromEncoded), 'AAAA;;AAAA');

  const multiLineDecoded = {
    version: 3,
    sources: ['source.js'],
    names: [],
    mappings: [
      [[0, 0, 0, 0]],
      [],
      [[0, 0, 0, 0]]
    ]
  };
  const tracerFromDecoded = new TraceMap(multiLineDecoded);
  assert.equal(encodedMappings(tracerFromDecoded), 'AAAA;;AAAA');
}

// 4. encodedMappings returns an empty string when initialized with empty string mappings or an empty array
{
  const emptyStrMap = {
    version: 3,
    sources: [],
    names: [],
    mappings: ''
  };
  const tracerEmptyStr = new TraceMap(emptyStrMap);
  assert.equal(encodedMappings(tracerEmptyStr), '');

  const emptyArrMap = {
    version: 3,
    sources: [],
    names: [],
    mappings: []
  };
  const tracerEmptyArr = new TraceMap(emptyArrMap);
  assert.equal(encodedMappings(tracerEmptyArr), '');
}

// 5. encodedMappings returns identical cached string across multiple calls on the same TraceMap instance
{
  const mapData = {
    version: 3,
    sources: ['app.js'],
    names: ['greet'],
    mappings: 'AAAA;ACAA'
  };
  const tracer = new TraceMap(mapData);
  const first = encodedMappings(tracer);
  const second = encodedMappings(tracer);

  assert.equal(first, 'AAAA;ACAA');
  assert.equal(first, second);
}

// 6. getEncodedMappings helper function accepts either a TraceMap instance or raw source map input
{
  const rawMap = {
    version: 3,
    sources: ['helper.js'],
    names: [],
    mappings: 'AAAA'
  };
  const fromRaw = getEncodedMappings(rawMap);
  const tracer = new TraceMap(rawMap);
  const fromTracer = getEncodedMappings(tracer);

  assert.equal(fromRaw, 'AAAA');
  assert.equal(fromTracer, 'AAAA');
  assert.equal(fromRaw, fromTracer);
}

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

Ursprungs-Seeder

anonym