CodeSampleX

Sample

source-map 0.6.1: SourceMapGenerator

Verified sample for npm source-map 0.6.1: SourceMapGenerator. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:67dc4f809fcde2a0e6bdb76e782cca73df9b62095408462ac24d37b7df940974

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1
Packages
Symbols
  • source-map.SourceMapGenerator
Environment
node 22.23.2
Created
2026-08-23T13:40:32Z

Contract

  1. SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot
  2. addMapping adds line and column mappings between generated code and original source positions
  3. setSourceContent embeds raw source file contents directly into the source map
  4. toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent
  5. toString serializes the source map object to a valid JSON string
  6. fromSourceMap static method creates a new SourceMapGenerator initialized from an existing SourceMapConsumer

Files

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

Download the source artifact (tar.gz)

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

Use EXACTLY these public packages and versions:
  - pkg:npm/source-map@0.6.1
Demonstrate these symbols/APIs:
  - source-map.SourceMapGenerator

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:75b652c08e35671e7e7ba274c632276bcf82a86e0b5ca076cbc11446b2bbbf95","constraints":{"executionContext":"node"},"contract":["SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot","addMapping adds line and column mappings between generated code and original source positions","setSourceContent embeds raw source file contents directly into the source map","toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent","toString serializes the source map object to a valid JSON string","fromSourceMap static method creates a new SourceMapGenerator initialized from an existing SourceMapConsumer"],"goal":"verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1","kind":"HOW","packages":["pkg:npm/source-map@0.6.1"],"schemaVersion":1,"symbols":["source-map.SourceMapGenerator"]},"contractCommand":["node","test/contract.cjs"],"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/source-map@0.6.1"],"schemaVersion":1,"subject":"pkg:npm/source-map@0.6.1","symbols":["source-map.SourceMapGenerator"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { SourceMapGenerator, SourceMapConsumer } = require('source-map');

/**
 * Creates a source map for generated code given mappings and source contents.
 *
 * @param {Object} options
 * @param {string} [options.file] - The generated file name.
 * @param {string} [options.sourceRoot] - The root URL/path for sources.
 * @param {Array<Object>} mappings - List of mapping objects.
 * @param {Object<string, string>} [sourcesContent] - Map of source filename to source text.
 * @returns {SourceMapGenerator} The populated SourceMapGenerator instance.
 */
function createSourceMap(options, mappings, sourcesContent) {
  const generator = new SourceMapGenerator(options);

  if (Array.isArray(mappings)) {
    for (const mapping of mappings) {
      generator.addMapping(mapping);
    }
  }

  if (sourcesContent && typeof sourcesContent === 'object') {
    for (const [sourceFile, content] of Object.entries(sourcesContent)) {
      generator.setSourceContent(sourceFile, content);
    }
  }

  return generator;
}

/**
 * Clones a source map using SourceMapGenerator.fromSourceMap.
 *
 * @param {SourceMapGenerator|Object} mapOrConsumer
 * @returns {SourceMapGenerator}
 */
function cloneSourceMap(mapOrConsumer) {
  if (typeof mapOrConsumer.toJSON === 'function') {
    const consumer = new SourceMapConsumer(mapOrConsumer.toJSON());
    return SourceMapGenerator.fromSourceMap(consumer);
  }
  return SourceMapGenerator.fromSourceMap(mapOrConsumer);
}

module.exports = {
  SourceMapGenerator,
  createSourceMap,
  cloneSourceMap
};
package-lock.json
{
  "name": "sample-source-map-generator",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-generator",
      "version": "1.0.0",
      "license": "MIT-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-generator",
  "version": "1.0.0",
  "private": true,
  "description": "verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "source-map": "0.6.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map@0.6.1"
  ],
  "symbols": [
    "source-map.SourceMapGenerator"
  ]
}
test/contract.cjs
'use strict';

const assert = require('assert');
const { SourceMapGenerator, SourceMapConsumer } = require('source-map');
const { createSourceMap, cloneSourceMap } = require('../index.js');

async function runContractTests() {
  // 1. SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot
  const generator = new SourceMapGenerator({
    file: 'bundle.js',
    sourceRoot: 'http://example.com/src/'
  });
  assert.ok(generator instanceof SourceMapGenerator, 'Must create an instance of SourceMapGenerator');

  // 2. addMapping adds line and column mappings between generated code and original source positions
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 10, column: 4 },
    source: 'foo.js',
    name: 'bar'
  });

  generator.addMapping({
    generated: { line: 2, column: 0 },
    original: { line: 20, column: 8 },
    source: 'baz.js'
  });

  // 3. setSourceContent embeds raw source file contents directly into the source map
  const fooContent = 'function bar() { return true; }';
  const bazContent = 'const val = 123;';
  generator.setSourceContent('foo.js', fooContent);
  generator.setSourceContent('baz.js', bazContent);

  // 4. toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent
  const jsonMap = generator.toJSON();
  assert.strictEqual(jsonMap.version, 3, 'Source map version must be 3');
  assert.strictEqual(jsonMap.file, 'bundle.js', 'File name must match option');
  assert.strictEqual(jsonMap.sourceRoot, 'http://example.com/src/', 'sourceRoot must match option');
  assert.deepStrictEqual(jsonMap.sources, ['foo.js', 'baz.js'], 'sources list must contain added sources');
  assert.deepStrictEqual(jsonMap.names, ['bar'], 'names list must contain added names');
  assert.deepStrictEqual(jsonMap.sourcesContent, [fooContent, bazContent], 'sourcesContent must contain embedded contents');
  assert.ok(typeof jsonMap.mappings === 'string' && jsonMap.mappings.length > 0, 'mappings string must not be empty');

  // 5. toString serializes the source map object to a valid JSON string
  const stringified = generator.toString();
  assert.strictEqual(typeof stringified, 'string', 'toString must return a string');
  const parsed = JSON.parse(stringified);
  assert.deepStrictEqual(parsed, jsonMap, 'Parsed toString output must match toJSON output');

  // 6. Verify mapping resolution with SourceMapConsumer
  const consumer = new SourceMapConsumer(jsonMap);
  const pos1 = consumer.originalPositionFor({ line: 1, column: 0 });
  assert.strictEqual(pos1.line, 10);
  assert.strictEqual(pos1.column, 4);
  assert.strictEqual(pos1.source, 'http://example.com/src/foo.js');
  assert.strictEqual(pos1.name, 'bar');

  const pos2 = consumer.originalPositionFor({ line: 2, column: 0 });
  assert.strictEqual(pos2.line, 20);
  assert.strictEqual(pos2.column, 8);
  assert.strictEqual(pos2.source, 'http://example.com/src/baz.js');
  assert.strictEqual(pos2.name, null);

  // 7. fromSourceMap static method creates a new SourceMapGenerator initialized from an existing consumer
  const clonedGen = SourceMapGenerator.fromSourceMap(consumer);
  assert.ok(clonedGen instanceof SourceMapGenerator, 'fromSourceMap must return a SourceMapGenerator instance');
  const clonedJson = clonedGen.toJSON();
  assert.strictEqual(clonedJson.version, 3);
  assert.strictEqual(clonedJson.file, 'bundle.js');
  assert.deepStrictEqual(clonedJson.sources, ['foo.js', 'baz.js']);
  assert.deepStrictEqual(clonedJson.names, ['bar']);

  // 8. Test helper functions from index.js
  const helperMap = createSourceMap(
    { file: 'app.min.js' },
    [
      {
        generated: { line: 1, column: 0 },
        original: { line: 1, column: 0 },
        source: 'app.js'
      }
    ],
    {
      'app.js': 'console.log("hello");'
    }
  );
  assert.ok(helperMap instanceof SourceMapGenerator);
  const helperJson = helperMap.toJSON();
  assert.strictEqual(helperJson.file, 'app.min.js');
  assert.deepStrictEqual(helperJson.sources, ['app.js']);
  assert.deepStrictEqual(helperJson.sourcesContent, ['console.log("hello");']);

  const clonedViaHelper = cloneSourceMap(helperMap);
  assert.ok(clonedViaHelper instanceof SourceMapGenerator);
  assert.strictEqual(clonedViaHelper.toJSON().file, 'app.min.js');

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

runContractTests().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Origin Seeder

anonymous