CodeSampleX

示例

source-map 0.6.1: SourceMapConsumer

已验证示例 — npm source-map 0.6.1: SourceMapConsumer. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: SourceMapConsumer parses raw source map and resolves…

sha256:6e34f2d9dd46d525a4d8a8c458a7c0addf85cf2e4d302dfbc5ccb524f5263256

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify source-map.SourceMapConsumer in pkg:npm/source-map@0.6.1
包
符号
  • source-map.SourceMapConsumer
创建时间
2026-08-23T13:37:59Z

契约

  1. SourceMapConsumer parses raw source map and resolves original position for a generated coordinate
  2. SourceMapConsumer resolves original position with GREATEST_LOWER_BOUND and LEAST_UPPER_BOUND bias options
  3. SourceMapConsumer resolves generated position for an original source line and column
  4. SourceMapConsumer returns all generated positions matching an original source line
  5. SourceMapConsumer retrieves embedded source content by file name
  6. SourceMapConsumer iterates over mappings in GENERATED_ORDER and ORIGINAL_ORDER
  7. SourceMapConsumer checks whether contents are embedded for all source files

文件

  • PROMPT.md
  • csx.json
  • 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.SourceMapConsumer 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.SourceMapConsumer

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:f6f7a4f31aee60da6579456ccac44df06465bcb249b1fa5e17fe3f23a971c08d","contract":["SourceMapConsumer parses raw source map and resolves original position for a generated coordinate","SourceMapConsumer resolves original position with GREATEST_LOWER_BOUND and LEAST_UPPER_BOUND bias options","SourceMapConsumer resolves generated position for an original source line and column","SourceMapConsumer returns all generated positions matching an original source line","SourceMapConsumer retrieves embedded source content by file name","SourceMapConsumer iterates over mappings in GENERATED_ORDER and ORIGINAL_ORDER","SourceMapConsumer checks whether contents are embedded for all source files"],"goal":"verify source-map.SourceMapConsumer in pkg:npm/source-map@0.6.1","kind":"HOW","packages":["pkg:npm/source-map@0.6.1"],"schemaVersion":1,"symbols":["source-map.SourceMapConsumer"]},"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","symbols":["source-map.SourceMapConsumer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-source-map-consumer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-consumer",
      "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-consumer",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "source-map": "0.6.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify source-map.SourceMapConsumer in pkg:npm/source-map@0.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map@0.6.1"
  ],
  "symbols": [
    "source-map.SourceMapConsumer"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';

function createFixtureSourceMap() {
  const generator = new SourceMapGenerator({
    file: 'bundle.min.js'
  });

  generator.setSourceContent('util.js', 'export function add(a, b) {\n  return a + b;\n}\n');
  generator.setSourceContent('main.js', 'import { add } from "./util";\nconst sum = add(1, 2);\n');

  // Mapping 1: util.js add function definition
  generator.addMapping({
    generated: { line: 1, column: 0 },
    original: { line: 1, column: 0 },
    source: 'util.js',
    name: 'add'
  });

  // Mapping 2: util.js return statement
  generator.addMapping({
    generated: { line: 1, column: 20 },
    original: { line: 2, column: 2 },
    source: 'util.js'
  });

  // Mapping 3: main.js import
  generator.addMapping({
    generated: { line: 2, column: 0 },
    original: { line: 1, column: 0 },
    source: 'main.js'
  });

  // Mapping 4: main.js sum assignment
  generator.addMapping({
    generated: { line: 2, column: 15 },
    original: { line: 2, column: 6 },
    source: 'main.js',
    name: 'sum'
  });

  // Mapping 5: main.js call to add on same line
  generator.addMapping({
    generated: { line: 2, column: 25 },
    original: { line: 2, column: 12 },
    source: 'main.js',
    name: 'add'
  });

  return generator.toJSON();
}

const rawMap = createFixtureSourceMap();

// 1. SourceMapConsumer parses raw source map and resolves original position for a generated coordinate
{
  const consumer = new SourceMapConsumer(rawMap);
  const pos = consumer.originalPositionFor({ line: 2, column: 15 });
  assert.equal(pos.source, 'main.js');
  assert.equal(pos.line, 2);
  assert.equal(pos.column, 6);
  assert.equal(pos.name, 'sum');
}

// 2. SourceMapConsumer resolves original position with GREATEST_LOWER_BOUND and LEAST_UPPER_BOUND bias options
{
  const consumer = new SourceMapConsumer(rawMap);
  // Column 18 is between mapping at col 15 and col 25 on line 2
  const lowerPos = consumer.originalPositionFor({
    line: 2,
    column: 18,
    bias: SourceMapConsumer.GREATEST_LOWER_BOUND
  });
  assert.equal(lowerPos.line, 2);
  assert.equal(lowerPos.column, 6);
  assert.equal(lowerPos.name, 'sum');

  const upperPos = consumer.originalPositionFor({
    line: 2,
    column: 18,
    bias: SourceMapConsumer.LEAST_UPPER_BOUND
  });
  assert.equal(upperPos.line, 2);
  assert.equal(upperPos.column, 12);
  assert.equal(upperPos.name, 'add');
}

// 3. SourceMapConsumer resolves generated position for an original source line and column
{
  const consumer = new SourceMapConsumer(rawMap);
  const genPos = consumer.generatedPositionFor({
    source: 'util.js',
    line: 2,
    column: 2
  });
  assert.equal(genPos.line, 1);
  assert.equal(genPos.column, 20);
}

// 4. SourceMapConsumer returns all generated positions matching an original source line
{
  const consumer = new SourceMapConsumer(rawMap);
  const allPositions = consumer.allGeneratedPositionsFor({
    source: 'main.js',
    line: 2
  });
  assert.ok(Array.isArray(allPositions));
  assert.equal(allPositions.length, 2);
  assert.equal(allPositions[0].line, 2);
  assert.equal(allPositions[0].column, 15);
  assert.equal(allPositions[1].line, 2);
  assert.equal(allPositions[1].column, 25);
}

// 5. SourceMapConsumer retrieves embedded source content by file name
{
  const consumer = new SourceMapConsumer(rawMap);
  const utilContent = consumer.sourceContentFor('util.js');
  assert.equal(utilContent, 'export function add(a, b) {\n  return a + b;\n}\n');

  const mainContent = consumer.sourceContentFor('main.js');
  assert.equal(mainContent, 'import { add } from "./util";\nconst sum = add(1, 2);\n');

  const missingContent = consumer.sourceContentFor('nonexistent.js', true);
  assert.equal(missingContent, null);
}

// 6. SourceMapConsumer iterates over mappings in GENERATED_ORDER and ORIGINAL_ORDER
{
  const consumer = new SourceMapConsumer(rawMap);
  const genOrderMappings = [];
  consumer.eachMapping((m) => {
    genOrderMappings.push({ genLine: m.generatedLine, genCol: m.generatedColumn });
  }, null, SourceMapConsumer.GENERATED_ORDER);

  assert.equal(genOrderMappings.length, 5);
  assert.deepEqual(genOrderMappings[0], { genLine: 1, genCol: 0 });
  assert.deepEqual(genOrderMappings[1], { genLine: 1, genCol: 20 });
  assert.deepEqual(genOrderMappings[2], { genLine: 2, genCol: 0 });

  const origOrderMappings = [];
  consumer.eachMapping((m) => {
    origOrderMappings.push({ source: m.source, origLine: m.originalLine, origCol: m.originalColumn });
  }, null, SourceMapConsumer.ORIGINAL_ORDER);

  assert.equal(origOrderMappings.length, 5);
  assert.equal(origOrderMappings[0].source, 'util.js');
  assert.equal(origOrderMappings[0].origLine, 1);
  assert.equal(origOrderMappings[0].origCol, 0);
}

// 7. SourceMapConsumer checks whether contents are embedded for all source files
{
  const consumer = new SourceMapConsumer(rawMap);
  assert.equal(consumer.hasContentsOfAllSources(), true);

  const partialMap = {
    version: 3,
    file: 'out.js',
    sources: ['a.js', 'b.js'],
    sourcesContent: ['content a', null],
    names: [],
    mappings: 'AAAA;'
  };
  const partialConsumer = new SourceMapConsumer(partialMap);
  assert.equal(partialConsumer.hasContentsOfAllSources(), false);
}

原始种子者

匿名