CodeSampleX

Beispiel

@babel/code-frame 8.0.0: highlight

Verifiziertes Beispiel für npm @babel/code-frame 8.0.0: highlight. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:ef05de32bf21663da156edab42e53eae497e790e8e79ab77582175039119bf2f

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Fall

HOW
Ziel
verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0
Pakete
Symbole
  • @babel/code-frame.highlight
Umgebung
node 22.23.2
Erstellt
2026-08-20T21:01:37Z

Contract

  1. highlight returns an empty string when given an empty input string
  2. highlight formats JavaScript keywords with cyan ANSI escape sequences
  3. highlight formats string literals with green ANSI color codes and numeric literals with magenta
  4. highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow
  5. highlight colors JSX element tags and capitalized component identifiers
  6. stripAnsiEscapeCodes restores the original source code text from highlighted output

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/code-frame@8.0.0
Demonstrate these symbols/APIs:
  - @babel/code-frame.highlight
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:04529d4a687cd068e3eab1ea81f467a541dfee39c203666821eb6390eb5e75fc","constraints":{"executionContext":"node"},"contract":["highlight returns an empty string when given an empty input string","highlight formats JavaScript keywords with cyan ANSI escape sequences","highlight formats string literals with green ANSI color codes and numeric literals with magenta","highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow","highlight colors JSX element tags and capitalized component identifiers","stripAnsiEscapeCodes restores the original source code text from highlighted output"],"goal":"verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0","kind":"HOW","packages":["pkg:npm/%40babel/code-frame@8.0.0"],"schemaVersion":1,"symbols":["@babel/code-frame.highlight"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/code-frame@8.0.0"],"schemaVersion":1,"subject":"pkg:npm/%40babel/code-frame@8.0.0","symbols":["@babel/code-frame.highlight"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-code-frame-highlight",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-code-frame-highlight",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/code-frame": "8.0.0"
      }
    },
    "node_modules/@babel/code-frame": {
      "version": "8.0.0",
      "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-8.0.0.tgz",
      "integrity": "sha512-dYYg153EyN2Ekbqw2zAsbd6/JR+9N2SEoC7YV2GyyqMM7x9bLDTjBD6XBhSMLH0wtIVyJj03jWNriQhaN+eoCw==",
      "license": "MIT",
      "dependencies": {
        "@babel/helper-validator-identifier": "^8.0.0",
        "js-tokens": "^10.0.0"
      },
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    },
    "node_modules/@babel/helper-validator-identifier": {
      "version": "8.0.4",
      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.4.tgz",
      "integrity": "sha512-4wFaiLd0bVo4cIoTXI3zKI038NIWE/cr3jvBjejOVYVxV/m8Ltav1USiGzG1fmS5J2RhgEOgXNNK46cRPnRsrg==",
      "license": "MIT",
      "engines": {
        "node": "^22.18.0 || >=24.11.0"
      }
    },
    "node_modules/js-tokens": {
      "version": "10.0.0",
      "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz",
      "integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-babel-code-frame-highlight",
  "version": "1.0.0",
  "description": "verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@babel/code-frame": "8.0.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @babel/code-frame.highlight in pkg:npm/%40babel/code-frame@8.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/code-frame@8.0.0"
  ],
  "symbols": [
    "@babel/code-frame.highlight"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { highlight } = require('@babel/code-frame');

/**
 * Highlights a given source code string using Babel code-frame syntax highlighting.
 *
 * @param {string} source - The source code string to highlight.
 * @returns {string} The ANSI highlighted source string.
 */
function highlightSource(source) {
  return highlight(source);
}

/**
 * Checks if the highlighted output contains ANSI escape sequences.
 *
 * @param {string} text - The text to check.
 * @returns {boolean} True if ANSI escape sequences are present.
 */
function hasAnsiEscapeCodes(text) {
  const ansiPattern = /\u001b\[\d+(?:;\d+)*m/;
  return ansiPattern.test(text);
}

/**
 * Strips ANSI escape sequences from a string to recover the original plain text.
 *
 * @param {string} text - The ANSI styled text.
 * @returns {string} The raw plain text without styling.
 */
function stripAnsiEscapeCodes(text) {
  return text.replace(/\u001b\[\d+(?:;\d+)*m/g, '');
}

module.exports = {
  highlightSource,
  hasAnsiEscapeCodes,
  stripAnsiEscapeCodes
};
test/contract.js
const assert = require('assert');
const { highlight } = require('@babel/code-frame');
const {
  highlightSource,
  hasAnsiEscapeCodes,
  stripAnsiEscapeCodes
} = require('../src/index');

// 1. highlight returns an empty string when given an empty input string
{
  const result = highlightSource('');
  assert.strictEqual(result, '', 'Empty input string must return empty string');
  assert.strictEqual(hasAnsiEscapeCodes(result), false, 'Empty result must not have ANSI codes');
}

// 2. highlight formats JavaScript keywords with cyan ANSI escape sequences
{
  const code = 'const count = function() { return 42; };';
  const highlighted = highlightSource(code);
  assert(hasAnsiEscapeCodes(highlighted), 'Highlighted code must contain ANSI escape codes');
  assert(highlighted.includes('\u001b[36mconst\u001b[39m'), 'const keyword must be highlighted in cyan');
  assert(highlighted.includes('\u001b[36mfunction\u001b[39m'), 'function keyword must be highlighted in cyan');
  assert(highlighted.includes('\u001b[36mreturn\u001b[39m'), 'return keyword must be highlighted in cyan');
}

// 3. highlight formats string literals with green ANSI color codes and numeric literals with magenta
{
  const code = 'const greeting = "hello world"; const val = 12345;';
  const highlighted = highlightSource(code);
  assert(highlighted.includes('\u001b[32m"hello world"\u001b[39m'), 'String literal must be highlighted in green');
  assert(highlighted.includes('\u001b[35m12345\u001b[39m'), 'Numeric literal must be highlighted in magenta');
}

// 4. highlight formats single-line comments with gray ANSI escape codes and punctuators with yellow
{
  const code = '// calculate value\nlet x = 10;';
  const highlighted = highlightSource(code);
  assert(highlighted.includes('\u001b[90m// calculate value\u001b[39m'), 'Comments must be highlighted in gray');
  assert(highlighted.includes('\u001b[33m=\u001b[39m'), 'Assignment operator must be highlighted in yellow');
  assert(highlighted.includes('\u001b[33m;\u001b[39m'), 'Semicolon must be highlighted in yellow');
}

// 5. highlight colors JSX element tags and capitalized component identifiers
{
  const code = '<MyComponent active={true} />';
  const highlighted = highlightSource(code);
  assert(highlighted.includes('\u001b[33mMyComponent\u001b[39m'), 'Capitalized component name must be highlighted');
  assert(highlighted.includes('\u001b[33m<\u001b[39m'), 'Opening JSX bracket must be highlighted');
  assert(highlighted.includes('\u001b[33m>\u001b[39m'), 'Closing JSX bracket must be highlighted');
}

// 6. stripAnsiEscapeCodes restores the original source code text from highlighted output
{
  const originalCode = 'function add(a, b) {\n  // sum two numbers\n  return a + b;\n}';
  const highlighted = highlightSource(originalCode);
  const restored = stripAnsiEscapeCodes(highlighted);
  assert.strictEqual(restored, originalCode, 'Stripping ANSI codes must restore the exact original source code');
}

console.log('All contract assertions passed successfully.');

Ursprungs-Seeder

anonym