CodeSampleX

サンプル

source-map-js 1.2.1: SourceMapGenerator

検証済みサンプル — npm source-map-js 1.2.1: SourceMapGenerator. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: assert SourceMapGenerator initializes…

sha256:607151d61b5428653adff162b742aa696c39f2836a3e25ce49ddb6b52d5735ea

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-06

ケース

HOW
ゴール
verify source-map-js.SourceMapGenerator in pkg:npm/source-map-js@1.2.1
パッケージ
シンボル
  • source-map-js.SourceMapGenerator
環境
node 22.23.2
作成日
2026-09-06T01:50:17Z

コントラクト

  1. assert SourceMapGenerator initializes with file and sourceRoot options and produces v3 source map JSON
  2. assert SourceMapGenerator.prototype.addMapping records generated to original line and column mappings with optional symbol names
  3. assert SourceMapGenerator.prototype.setSourceContent embeds original file source contents into sourcesContent array
  4. assert SourceMapGenerator.prototype.toString serializes identical output to JSON.stringify of toJSON
  5. assert SourceMapGenerator.fromSourceMap clones mappings from an existing SourceMapConsumer
  6. assert SourceMapGenerator.prototype.applySourceMap composes multi-step source transforms into a unified map
  7. assert SourceMapGenerator.prototype.addMapping rejects invalid mappings with generated line less than 1

ファイル

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

Use EXACTLY these public packages and versions:
  - pkg:npm/source-map-js@1.2.1
Demonstrate these symbols/APIs:
  - source-map-js.SourceMapGenerator
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:b7dacebd7ab71256600936453bf0e1db4b094be48b612006b035660d74f0122d","constraints":{"executionContext":"node"},"contract":["assert SourceMapGenerator initializes with file and sourceRoot options and produces v3 source map JSON","assert SourceMapGenerator.prototype.addMapping records generated to original line and column mappings with optional symbol names","assert SourceMapGenerator.prototype.setSourceContent embeds original file source contents into sourcesContent array","assert SourceMapGenerator.prototype.toString serializes identical output to JSON.stringify of toJSON","assert SourceMapGenerator.fromSourceMap clones mappings from an existing SourceMapConsumer","assert SourceMapGenerator.prototype.applySourceMap composes multi-step source transforms into a unified map","assert SourceMapGenerator.prototype.addMapping rejects invalid mappings with generated line less than 1"],"goal":"verify source-map-js.SourceMapGenerator in pkg:npm/source-map-js@1.2.1","kind":"HOW","packages":["pkg:npm/source-map-js@1.2.1"],"schemaVersion":1,"symbols":["source-map-js.SourceMapGenerator"]},"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/source-map-js@1.2.1"],"schemaVersion":1,"subject":"pkg:npm/source-map-js@1.2.1","symbols":["source-map-js.SourceMapGenerator"],"verifierAdapter":"node-typescript@1"}
index.js
const { SourceMapGenerator, SourceMapConsumer } = require('source-map-js');

/**
 * Creates a new SourceMapGenerator instance with the specified options.
 *
 * @param {Object} [options] - Configuration options for the source map (file, sourceRoot, skipValidation).
 * @returns {SourceMapGenerator} A new SourceMapGenerator instance.
 */
function createGenerator(options) {
  return new SourceMapGenerator(options);
}

/**
 * Adds a single mapping from generated position to original position.
 *
 * @param {SourceMapGenerator} generator - The generator to add mapping to.
 * @param {Object} mapping - Mapping object containing generated and optional original/source/name fields.
 */
function addMapping(generator, mapping) {
  generator.addMapping(mapping);
}

/**
 * Sets the original source code content for a source file.
 *
 * @param {SourceMapGenerator} generator - The generator instance.
 * @param {string} sourceFile - Name or URL of the source file.
 * @param {string} sourceContent - Content of the source file.
 */
function setSourceContent(generator, sourceFile, sourceContent) {
  generator.setSourceContent(sourceFile, sourceContent);
}

module.exports = {
  SourceMapGenerator,
  SourceMapConsumer,
  createGenerator,
  addMapping,
  setSourceContent,
};
package-lock.json
{
  "name": "sample-source-map-js",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-js",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "source-map-js": "1.2.1"
      }
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-source-map-js",
  "version": "1.0.0",
  "description": "Clean-room verification sample for source-map-js.SourceMapGenerator",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "source-map-js": "1.2.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify source-map-js.SourceMapGenerator in pkg:npm/source-map-js@1.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map-js@1.2.1"
  ],
  "symbols": [
    "source-map-js.SourceMapGenerator"
  ],
  "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 {
  SourceMapGenerator,
  SourceMapConsumer,
  createGenerator,
  addMapping,
  setSourceContent
} from '../index.js';

// 1. assert SourceMapGenerator initializes with file and sourceRoot options and produces v3 source map JSON
{
  const gen = createGenerator({
    file: 'bundle.js',
    sourceRoot: 'https://example.com/src/'
  });
  const json = gen.toJSON();
  assert.equal(json.version, 3);
  assert.equal(json.file, 'bundle.js');
  assert.equal(json.sourceRoot, 'https://example.com/src/');
  assert.deepEqual(json.sources, []);
  assert.deepEqual(json.names, []);
}

// 2. assert SourceMapGenerator.prototype.addMapping records generated to original line and column mappings with optional symbol names
{
  const gen = createGenerator({ file: 'out.js' });
  addMapping(gen, {
    generated: { line: 1, column: 0 },
    original: { line: 10, column: 4 },
    source: 'input.js',
    name: 'myVar'
  });
  const json = gen.toJSON();
  assert.deepEqual(json.sources, ['input.js']);
  assert.deepEqual(json.names, ['myVar']);
  assert.ok(typeof json.mappings === 'string' && json.mappings.length > 0);

  const consumer = new SourceMapConsumer(json);
  const orig = consumer.originalPositionFor({ line: 1, column: 0 });
  assert.equal(orig.source, 'input.js');
  assert.equal(orig.line, 10);
  assert.equal(orig.column, 4);
  assert.equal(orig.name, 'myVar');
}

// 3. assert SourceMapGenerator.prototype.setSourceContent embeds original file source contents into sourcesContent array
{
  const gen = createGenerator({ file: 'out.js' });
  const content = 'const x = 42;\nexport default x;';
  setSourceContent(gen, 'input.js', content);
  addMapping(gen, {
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'input.js'
  });
  const json = gen.toJSON();
  assert.deepEqual(json.sourcesContent, [content]);
}

// 4. assert SourceMapGenerator.prototype.toString serializes identical output to JSON.stringify of toJSON
{
  const gen = createGenerator({ file: 'out.js' });
  addMapping(gen, {
    generated: { line: 1, column: 5 },
    original: { line: 2, column: 10 },
    source: 'src.js'
  });
  const json = gen.toJSON();
  const str = gen.toString();
  assert.equal(str, JSON.stringify(json));
}

// 5. assert SourceMapGenerator.fromSourceMap clones mappings from an existing SourceMapConsumer
{
  const gen1 = createGenerator({ file: 'initial.js' });
  addMapping(gen1, {
    generated: { line: 1, column: 0 },
    original: { line: 5, column: 2 },
    source: 'orig.js',
    name: 'sym'
  });
  const consumer = new SourceMapConsumer(gen1.toJSON());
  const gen2 = SourceMapGenerator.fromSourceMap(consumer);
  assert.deepEqual(gen2.toJSON(), gen1.toJSON());
}

// 6. assert SourceMapGenerator.prototype.applySourceMap composes multi-step source transforms into a unified map
{
  // Step 1: orig.ts -> trans.js
  const map1 = createGenerator({ file: 'trans.js' });
  addMapping(map1, {
    generated: { line: 1, column: 0 },
    original: { line: 10, column: 5 },
    source: 'orig.ts'
  });
  const consumer1 = new SourceMapConsumer(map1.toJSON());

  // Step 2: trans.js -> min.js
  const map2 = createGenerator({ file: 'min.js' });
  addMapping(map2, {
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'trans.js'
  });
  map2.applySourceMap(consumer1, 'trans.js');

  const finalJson = map2.toJSON();
  assert.deepEqual(finalJson.sources, ['orig.ts']);
  const finalConsumer = new SourceMapConsumer(finalJson);
  const pos = finalConsumer.originalPositionFor({ line: 1, column: 0 });
  assert.equal(pos.source, 'orig.ts');
  assert.equal(pos.line, 10);
  assert.equal(pos.column, 5);
}

// 7. assert SourceMapGenerator.prototype.addMapping rejects invalid mappings with generated line less than 1
{
  const gen = createGenerator();
  assert.throws(
    () => {
      addMapping(gen, { generated: { line: 0, column: 0 } });
    },
    /Invalid mapping/,
    'Must throw Error for generated line < 1'
  );
}

console.log('All source-map-js.SourceMapGenerator contract assertions passed.');

オリジンシーダー

匿名