CodeSampleX

Exemplo

@jridgewell/trace-mapping 0.3.31: sourceContentFor

Amostra verificada para npm @jridgewell/trace-mapping 0.3.31: sourceContentFor. O contrato rodou em node 22 · linux alpine/x64 · docker e passou.

sha256:216fec617f1f2888b99b8085d43febeee3a7a8dc43be50394199ae5632fb0f20

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-27

Caso

HOW
Objetivo
verify @jridgewell/trace-mapping.sourceContentFor in pkg:npm/%40jridgewell/trace-mapping@0.3.31
Pacotes
Símbolos
  • @jridgewell/trace-mapping.sourceContentFor
Ambiente
node 22.23.2
Criado
2026-08-27T11:50:49Z

Contrato

  1. sourceContentFor returns the embedded source content for a source file present in sourcesContent
  2. sourceContentFor returns null for a source file without content or when sourcesContent is not provided
  3. sourceContentFor returns null for an unknown or unmapped source file path
  4. sourceContentFor resolves sources correctly when sourceRoot is configured in the source map

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 @jridgewell/trace-mapping.sourceContentFor in pkg:npm/%40jridgewell/trace-mapping@0.3.31
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jridgewell/trace-mapping@0.3.31
Demonstrate these symbols/APIs:
  - @jridgewell/trace-mapping.sourceContentFor

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:5237a04d316955944c34148c3fef8e3da3f402c81153920709e659199306ffd6","contract":["sourceContentFor returns the embedded source content for a source file present in sourcesContent","sourceContentFor returns null for a source file without content or when sourcesContent is not provided","sourceContentFor returns null for an unknown or unmapped source file path","sourceContentFor resolves sources correctly when sourceRoot is configured in the source map"],"goal":"verify @jridgewell/trace-mapping.sourceContentFor in pkg:npm/%40jridgewell/trace-mapping@0.3.31","kind":"HOW","packages":["pkg:npm/%40jridgewell/trace-mapping@0.3.31"],"schemaVersion":1,"symbols":["@jridgewell/trace-mapping.sourceContentFor"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40jridgewell/trace-mapping@0.3.31"],"schemaVersion":1,"subject":"pkg:npm/%40jridgewell/trace-mapping@0.3.31","symbols":["@jridgewell/trace-mapping.sourceContentFor"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-trace-mapping-source-content-for",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-trace-mapping-source-content-for",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jridgewell/trace-mapping": "0.3.31"
      }
    },
    "node_modules/@jridgewell/resolve-uri": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
      "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@jridgewell/trace-mapping": {
      "version": "0.3.31",
      "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
      "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/resolve-uri": "^3.1.0",
        "@jridgewell/sourcemap-codec": "^1.4.14"
      }
    }
  }
}
package.json
{
  "name": "sample-trace-mapping-source-content-for",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@jridgewell/trace-mapping": "0.3.31"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @jridgewell/trace-mapping.sourceContentFor in pkg:npm/%40jridgewell/trace-mapping@0.3.31",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jridgewell/trace-mapping@0.3.31"
  ],
  "symbols": [
    "@jridgewell/trace-mapping.sourceContentFor"
  ]
}
src/index.mjs
import { TraceMap, sourceContentFor } from "@jridgewell/trace-mapping";

export function createTraceMap(map) {
  return new TraceMap(map);
}

export function getSourceContent(tracer, source) {
  return sourceContentFor(tracer, source);
}
test/contract.mjs
import assert from "node:assert/strict";
import { TraceMap, sourceContentFor } from "@jridgewell/trace-mapping";
import { createTraceMap, getSourceContent } from "../src/index.mjs";

// Test 1: sourceContentFor returns the embedded source content for a source file present in sourcesContent
{
  const map = {
    version: 3,
    sources: ["input.js", "utils.js"],
    sourcesContent: ["export const x = 42;", "export function add(a, b) { return a + b; }"],
    mappings: "AAAA;"
  };
  const tracer = createTraceMap(map);
  assert.equal(getSourceContent(tracer, "input.js"), "export const x = 42;");
  assert.equal(getSourceContent(tracer, "utils.js"), "export function add(a, b) { return a + b; }");
  assert.equal(sourceContentFor(tracer, "input.js"), "export const x = 42;");
}

// Test 2: sourceContentFor returns null for a source file without content or when sourcesContent is not provided
{
  const mapWithNull = {
    version: 3,
    sources: ["has-content.js", "no-content.js"],
    sourcesContent: ["const a = 1;", null],
    mappings: "AAAA;"
  };
  const tracer1 = createTraceMap(mapWithNull);
  assert.equal(getSourceContent(tracer1, "has-content.js"), "const a = 1;");
  assert.equal(getSourceContent(tracer1, "no-content.js"), null);

  const mapWithoutSourcesContent = {
    version: 3,
    sources: ["input.js"],
    mappings: "AAAA;"
  };
  const tracer2 = createTraceMap(mapWithoutSourcesContent);
  assert.equal(getSourceContent(tracer2, "input.js"), null);
}

// Test 3: sourceContentFor returns null for an unknown or unmapped source file path
{
  const map = {
    version: 3,
    sources: ["file1.js"],
    sourcesContent: ["const ok = true;"],
    mappings: "AAAA;"
  };
  const tracer = createTraceMap(map);
  assert.equal(getSourceContent(tracer, "unknown.js"), null);
  assert.equal(getSourceContent(tracer, ""), null);
  assert.equal(getSourceContent(tracer, null), null);
  assert.equal(getSourceContent(tracer, undefined), null);
}

// Test 4: sourceContentFor resolves sources correctly when sourceRoot is configured in the source map
{
  const mapWithRoot = {
    version: 3,
    sourceRoot: "https://example.com/src/",
    sources: ["app.js"],
    sourcesContent: ["console.log('root app');"],
    mappings: "AAAA;"
  };
  const tracer = createTraceMap(mapWithRoot);
  assert.equal(getSourceContent(tracer, "https://example.com/src/app.js"), "console.log('root app');");
  assert.equal(getSourceContent(tracer, "app.js"), "console.log('root app');");
}

console.log("All @jridgewell/trace-mapping.sourceContentFor contract tests passed successfully.");

Seeder de origem

anônimo