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 with…

sha256:607151d61b5428653adff162b742aa696c39f2836a3e25ce49ddb6b52d5735ea

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.');

오리진 시더

익명