Ejemplo
@babel/generator 7.29.7: CodeGenerator
Muestra verificada para npm @babel/generator 7.29.7: CodeGenerator. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.
sha256:517fda2785fc4650c53e5a2e728502bbd6c825dd73a6cb7c5e333999f01b7235
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-05 |
Caso
HOW- Objetivo
- verify @babel/generator.CodeGenerator in pkg:npm/%40babel/generator@7.29.7
- Paquetes
- Símbolos
-
- @babel/generator.CodeGenerator
- Creado
- 2026-09-05T17:41:12Z
Contrato
- CodeGenerator constructor initializes instance with provided AST and default formatting configuration
- CodeGenerator.prototype.generate compiles AST VariableDeclaration into valid JavaScript code string
- CodeGenerator formats FunctionDeclaration with parameters and binary return expression
- CodeGenerator produces minified code without superfluous whitespace when minified option is set
- CodeGenerator emits version 3 source maps with correct sources when sourceMaps option is enabled
- CodeGenerator injects auxiliaryCommentBefore and auxiliaryCommentAfter around emitted code
- CodeGenerator filters emitted comments according to shouldPrintComment predicate
- CodeGenerator emits single quote string literals when jsescOption quotes is configured to single
- CodeGenerator throws validation Error when experimental_preserveFormat is used without original code
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Código fuente
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/generator.CodeGenerator in pkg:npm/%40babel/generator@7.29.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/generator@7.29.7
Demonstrate these symbols/APIs:
- @babel/generator.CodeGenerator
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.
{"case":{"caseId":"case:sha256:c916f9a0db6148523ba389346e19d629cb0af2995e0c17ca78b1defe1e451446","contract":["CodeGenerator constructor initializes instance with provided AST and default formatting configuration","CodeGenerator.prototype.generate compiles AST VariableDeclaration into valid JavaScript code string","CodeGenerator formats FunctionDeclaration with parameters and binary return expression","CodeGenerator produces minified code without superfluous whitespace when minified option is set","CodeGenerator emits version 3 source maps with correct sources when sourceMaps option is enabled","CodeGenerator injects auxiliaryCommentBefore and auxiliaryCommentAfter around emitted code","CodeGenerator filters emitted comments according to shouldPrintComment predicate","CodeGenerator emits single quote string literals when jsescOption quotes is configured to single","CodeGenerator throws validation Error when experimental_preserveFormat is used without original code"],"goal":"verify @babel/generator.CodeGenerator in pkg:npm/%40babel/generator@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/generator@7.29.7"],"schemaVersion":1,"symbols":["@babel/generator.CodeGenerator"]},"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/%40babel/generator@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/generator@7.29.7","symbols":["@babel/generator.CodeGenerator"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-babel-generator-codegenerator",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-babel-generator-codegenerator",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/generator": "7.29.7"
}
},
"node_modules/@babel/generator": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.7.tgz",
"integrity": "sha512-DkXD5OJQaAQIdZ1bt3UZdEnHAn9Imd3IVBdX03UFe+ony9Ojw5pzr9YVKGDY1jt+Gcn/FnGkNf8r+Vj5NOJWtQ==",
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.29.7",
"@babel/types": "^7.29.7",
"@jridgewell/gen-mapping": "^0.3.12",
"@jridgewell/trace-mapping": "^0.3.28",
"jsesc": "^3.0.2"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",
"integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
"integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/parser": {
"version": "7.29.8",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.8.tgz",
"integrity": "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==",
"license": "MIT",
"dependencies": {
"@babel/types": "^7.29.8"
},
"bin": {
"parser": "bin/babel-parser.js"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@babel/types": {
"version": "7.29.8",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz",
"integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==",
"license": "MIT",
"dependencies": {
"@babel/helper-string-parser": "^7.29.7",
"@babel/helper-validator-identifier": "^7.29.7"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.13",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
"integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
"license": "MIT",
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.5.0",
"@jridgewell/trace-mapping": "^0.3.24"
}
},
"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.6.0",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz",
"integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==",
"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"
}
},
"node_modules/jsesc": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
"integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==",
"license": "MIT",
"bin": {
"jsesc": "bin/jsesc"
},
"engines": {
"node": ">=6"
}
}
}
}
{
"name": "sample-babel-generator-codegenerator",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"@babel/generator": "7.29.7"
}
}
{
"schemaVersion": 1,
"goal": "verify @babel/generator.CodeGenerator in pkg:npm/%40babel/generator@7.29.7",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/generator@7.29.7"
],
"symbols": [
"@babel/generator.CodeGenerator"
]
}
import generatorPkg from "@babel/generator";
export const CodeGenerator = generatorPkg.CodeGenerator || generatorPkg.default?.CodeGenerator;
export function createCodeGenerator(ast, opts = {}, code) {
return new CodeGenerator(ast, opts, code);
}
export function generateCodeWithGenerator(ast, opts = {}, code) {
const generator = new CodeGenerator(ast, opts, code);
return generator.generate();
}
export function generateMinifiedCode(ast) {
const generator = new CodeGenerator(ast, { minified: true });
return generator.generate();
}
export function generateWithSourceMap(ast, sourceFileName, originalCode) {
const generator = new CodeGenerator(
ast,
{ sourceMaps: true, sourceFileName },
originalCode
);
return generator.generate();
}
export function generateWithAuxiliaryComments(ast, before, after) {
const generator = new CodeGenerator(ast, {
auxiliaryCommentBefore: before,
auxiliaryCommentAfter: after
});
return generator.generate();
}
export function generateWithCustomCommentFilter(ast, predicate) {
const generator = new CodeGenerator(ast, {
comments: true,
shouldPrintComment: predicate
});
return generator.generate();
}
export function generateWithSingleQuotes(ast) {
const generator = new CodeGenerator(ast, {
jsescOption: { quotes: "single" }
});
return generator.generate();
}
import assert from "node:assert/strict";
import {
CodeGenerator,
createCodeGenerator,
generateCodeWithGenerator,
generateMinifiedCode,
generateWithSourceMap,
generateWithAuxiliaryComments,
generateWithCustomCommentFilter,
generateWithSingleQuotes
} from "../src/index.mjs";
// 1. CodeGenerator constructor initializes instance with provided AST and default formatting configuration
{
const ast = {
type: "Program",
body: []
};
const generator = createCodeGenerator(ast);
assert.ok(generator instanceof CodeGenerator, "Must be an instance of CodeGenerator");
assert.equal(generator._ast, ast, "Must retain reference to provided AST");
assert.equal(typeof generator._format, "object", "Must initialize internal _format options");
assert.equal(generator._map, null, "Default map must be null when sourceMaps is not enabled");
}
// 2. CodeGenerator.prototype.generate compiles AST VariableDeclaration into valid JavaScript code string
{
const ast = {
type: "Program",
body: [
{
type: "VariableDeclaration",
kind: "const",
declarations: [
{
type: "VariableDeclarator",
id: { type: "Identifier", name: "answer" },
init: { type: "NumericLiteral", value: 42 }
}
]
}
]
};
const result = generateCodeWithGenerator(ast);
assert.equal(typeof result.code, "string");
assert.equal(result.code, "const answer = 42;");
}
// 3. CodeGenerator formats FunctionDeclaration with parameters and binary return expression
{
const ast = {
type: "FunctionDeclaration",
id: { type: "Identifier", name: "multiply" },
params: [
{ type: "Identifier", name: "a" },
{ type: "Identifier", name: "b" }
],
body: {
type: "BlockStatement",
body: [
{
type: "ReturnStatement",
argument: {
type: "BinaryExpression",
operator: "*",
left: { type: "Identifier", name: "a" },
right: { type: "Identifier", name: "b" }
}
}
]
}
};
const result = generateCodeWithGenerator(ast);
assert.match(result.code, /function multiply\(a, b\)/);
assert.match(result.code, /return a \* b;/);
}
// 4. CodeGenerator produces minified code without superfluous whitespace when minified option is set
{
const ast = {
type: "FunctionDeclaration",
id: { type: "Identifier", name: "calc" },
params: [],
body: {
type: "BlockStatement",
body: [
{
type: "ReturnStatement",
argument: { type: "NumericLiteral", value: 100 }
}
]
}
};
const result = generateMinifiedCode(ast);
assert.equal(result.code, "function calc(){return 100}");
}
// 5. CodeGenerator emits version 3 source maps with correct sources when sourceMaps option is enabled
{
const ast = {
type: "Identifier",
name: "mappedVariable",
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 14 },
filename: "source.js"
}
};
const result = generateWithSourceMap(ast, "source.js", "mappedVariable");
assert.ok(result.map, "Expected sourcemap object to be present");
assert.equal(result.map.version, 3);
assert.ok(result.map.sources.includes("source.js"));
}
// 6. CodeGenerator injects auxiliaryCommentBefore and auxiliaryCommentAfter around emitted code
{
const ast = {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: { type: "Identifier", name: "entryPoint" }
}
]
};
const result = generateWithAuxiliaryComments(ast, "preamble", "postamble");
assert.match(result.code, /\/\*preamble\*\//);
assert.match(result.code, /\/\*postamble\*\//);
}
// 7. CodeGenerator filters emitted comments according to shouldPrintComment predicate
{
const ast = {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: { type: "Identifier", name: "value" },
leadingComments: [
{ type: "CommentLine", value: " keep-me" },
{ type: "CommentLine", value: " discard-me" }
]
}
]
};
const result = generateWithCustomCommentFilter(ast, (comment) =>
comment.includes("keep-me")
);
assert.match(result.code, /\/\/ keep-me/);
assert.equal(result.code.includes("discard-me"), false);
}
// 8. CodeGenerator emits single quote string literals when jsescOption quotes is configured to single
{
const ast = {
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: { type: "StringLiteral", value: "single-quoted-content" }
}
]
};
const result = generateWithSingleQuotes(ast);
assert.equal(result.code, "'single-quoted-content';");
}
// 9. CodeGenerator throws validation Error when experimental_preserveFormat is used without original code
{
const ast = {
type: "Program",
body: []
};
assert.throws(
() => {
new CodeGenerator(ast, { experimental_preserveFormat: true });
},
(err) => {
return (
err instanceof Error &&
err.message.includes("`experimental_preserveFormat` requires the original `code` to be passed")
);
}
);
}
console.log("All @babel/generator.CodeGenerator contract tests passed successfully.");
Seeder de origen
anónimo