CodeSampleX

Exemple

source-map 0.6.1

Échantillon vérifié pour npm source-map 0.6.1. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : SourceMapGenerator generates a…

sha256:1c4f42ef2f518c2bc287edd13722a08be9d3b56d615d7c085477bce00eaf8180

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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
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-07

Cas

HOW
Objectif
verify pkg:npm/source-map@0.6.1
Paquets
Créé
2026-08-23T13:34:46Z

Contrat

  1. SourceMapGenerator generates a v3 source map with mappings between generated and original positions
  2. SourceMapGenerator sets and embeds original source file content in sourcesContent
  3. SourceMapConsumer resolves original source, line, column, and symbol name from generated coordinates
  4. SourceMapConsumer resolves generated line and column coordinates from original positions
  5. SourceMapConsumer returns all generated positions corresponding to an original line
  6. SourceMapConsumer retrieves embedded original source content for a source identifier
  7. SourceMapConsumer iterates over all mappings in generated order
  8. SourceNode constructs composite source trees and produces generated code with an accurate source map

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 pkg:npm/source-map@0.6.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/source-map@0.6.1

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:0330299caadb4577e9648fe47b9603a178a65241de9250b9544ca8ae8cacab60","contract":["SourceMapGenerator generates a v3 source map with mappings between generated and original positions","SourceMapGenerator sets and embeds original source file content in sourcesContent","SourceMapConsumer resolves original source, line, column, and symbol name from generated coordinates","SourceMapConsumer resolves generated line and column coordinates from original positions","SourceMapConsumer returns all generated positions corresponding to an original line","SourceMapConsumer retrieves embedded original source content for a source identifier","SourceMapConsumer iterates over all mappings in generated order","SourceNode constructs composite source trees and produces generated code with an accurate source map"],"goal":"verify pkg:npm/source-map@0.6.1","kind":"HOW","packages":["pkg:npm/source-map@0.6.1"],"schemaVersion":1},"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/source-map@0.6.1"],"schemaVersion":1,"subject":"pkg:npm/source-map@0.6.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-source-map",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map",
      "version": "1.0.0",
      "dependencies": {
        "source-map": "0.6.1"
      }
    },
    "node_modules/source-map": {
      "version": "0.6.1",
      "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
      "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-source-map",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "source-map": "0.6.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/source-map@0.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map@0.6.1"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { SourceMapGenerator, SourceMapConsumer, SourceNode } from 'source-map';

// 1. SourceMapGenerator generates a v3 source map with mappings between generated and original positions
{
  const generator = new SourceMapGenerator({
    file: 'bundle.js',
    sourceRoot: 'http://example.com/src/'
  });

  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 10, column: 4 },
    source: 'input.js',
    name: 'calculateTotal'
  });

  const rawMap = generator.toJSON();
  assert.equal(rawMap.version, 3);
  assert.equal(rawMap.file, 'bundle.js');
  assert.equal(rawMap.sourceRoot, 'http://example.com/src/');
  assert.deepEqual(rawMap.sources, ['input.js']);
  assert.deepEqual(rawMap.names, ['calculateTotal']);
  assert.equal(typeof rawMap.mappings, 'string');
  assert.ok(rawMap.mappings.length > 0);
}

// 2. SourceMapGenerator sets and embeds original source file content in sourcesContent
{
  const generator = new SourceMapGenerator({ file: 'out.js' });
  const sourceCode = 'function hello() { return "world"; }';
  generator.setSourceContent('hello.js', sourceCode);
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'hello.js'
  });

  const rawMap = generator.toJSON();
  assert.deepEqual(rawMap.sources, ['hello.js']);
  assert.deepEqual(rawMap.sourcesContent, [sourceCode]);
}

// 3. SourceMapConsumer resolves original source, line, column, and symbol name from generated coordinates
{
  const generator = new SourceMapGenerator({ file: 'min.js' });
  generator.addMapping({
    generated: { line: 1, column: 5 },
    original: { line: 2, column: 10 },
    source: 'orig.js',
    name: 'myFunction'
  });

  const consumer = new SourceMapConsumer(generator.toJSON());
  const pos = consumer.originalPositionFor({ line: 1, column: 5 });
  assert.equal(pos.source, 'orig.js');
  assert.equal(pos.line, 2);
  assert.equal(pos.column, 10);
  assert.equal(pos.name, 'myFunction');
}

// 4. SourceMapConsumer resolves generated line and column coordinates from original positions
{
  const generator = new SourceMapGenerator({ file: 'min.js' });
  generator.addMapping({
    generated: { line: 1, column: 20 },
    original: { line: 5, column: 8 },
    source: 'orig.js'
  });

  const consumer = new SourceMapConsumer(generator.toJSON());
  const genPos = consumer.generatedPositionFor({
    source: 'orig.js',
    line: 5,
    column: 8
  });
  assert.equal(genPos.line, 1);
  assert.equal(genPos.column, 20);
}

// 5. SourceMapConsumer returns all generated positions corresponding to an original line
{
  const generator = new SourceMapGenerator({ file: 'bundle.js' });
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 3, column: 0 },
    source: 'source.js'
  });
  generator.addMapping({
    generated: { line: 1, column: 15 },
    original: { line: 3, column: 5 },
    source: 'source.js'
  });

  const consumer = new SourceMapConsumer(generator.toJSON());
  const allPositions = consumer.allGeneratedPositionsFor({
    source: 'source.js',
    line: 3
  });
  assert.ok(Array.isArray(allPositions));
  assert.equal(allPositions.length, 2);
  assert.equal(allPositions[0].line, 1);
  assert.equal(allPositions[0].column, 0);
  assert.equal(allPositions[1].line, 1);
  assert.equal(allPositions[1].column, 15);
}

// 6. SourceMapConsumer retrieves embedded original source content for a source identifier
{
  const generator = new SourceMapGenerator({ file: 'out.js' });
  generator.setSourceContent('math.js', 'export const pi = 3.14159;');
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'math.js'
  });

  const consumer = new SourceMapConsumer(generator.toJSON());
  const retrievedContent = consumer.sourceContentFor('math.js');
  assert.equal(retrievedContent, 'export const pi = 3.14159;');
}

// 7. SourceMapConsumer iterates over all mappings in generated order
{
  const generator = new SourceMapGenerator({ file: 'out.js' });
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'a.js'
  });
  generator.addMapping({
    generated: { line: 2, column: 4 },
    original: { line: 10, column: 2 },
    source: 'b.js',
    name: 'ident'
  });

  const consumer = new SourceMapConsumer(generator.toJSON());
  const collected = [];
  consumer.eachMapping((m) => {
    collected.push({
      generatedLine: m.generatedLine,
      generatedColumn: m.generatedColumn,
      originalLine: m.originalLine,
      originalColumn: m.originalColumn,
      source: m.source,
      name: m.name
    });
  });

  assert.equal(collected.length, 2);
  assert.deepEqual(collected[0], {
    generatedLine: 1,
    generatedColumn: 0,
    originalLine: 1,
    originalColumn: 0,
    source: 'a.js',
    name: null
  });
  assert.deepEqual(collected[1], {
    generatedLine: 2,
    generatedColumn: 4,
    originalLine: 10,
    originalColumn: 2,
    source: 'b.js',
    name: 'ident'
  });
}

// 8. SourceNode constructs composite source trees and produces generated code with an accurate source map
{
  const node = new SourceNode(null, null, null, [
    new SourceNode(1, 0, 'part1.js', 'const a = 10;\n'),
    new SourceNode(1, 0, 'part2.js', 'const b = 20;\n'),
    'console.log(a + b);\n'
  ]);

  const output = node.toStringWithSourceMap({ file: 'output.js' });
  assert.equal(output.code, 'const a = 10;\nconst b = 20;\nconsole.log(a + b);\n');

  const consumer = new SourceMapConsumer(output.map.toJSON());
  const posA = consumer.originalPositionFor({ line: 1, column: 0 });
  assert.equal(posA.source, 'part1.js');
  assert.equal(posA.line, 1);

  const posB = consumer.originalPositionFor({ line: 2, column: 0 });
  assert.equal(posB.source, 'part2.js');
  assert.equal(posB.line, 1);
}

Seeder d'origine

anonyme