Ejemplo
@babel/parser 8.0.4
Muestra verificada para npm @babel/parser 8.0.4. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: parse parses JavaScript source code…
sha256:ee7c5991092e0a45dd458bab157a86ad279c696b6ccef3750655a0723f901b4d
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
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify pkg:npm/%40babel/parser@8.0.4
- Paquetes
- Entorno
- node 22.23.2
- Creado
- 2026-08-20T21:31:20Z
Contrato
- parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType
- parse with sourceType module parses ECMAScript module import and export declarations
- parseExpression parses a single JavaScript expression string directly into an Expression AST node
- parse with jsx plugin parses JSX syntax into JSXElement AST nodes
- parse with tokens option set to true populates the tokens array with lexical tokens
- parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes
- parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax
- tokTypes exposes standard token type descriptors including parenL, parenR, and name
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 pkg:npm/%40babel/parser@8.0.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/parser@8.0.4
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.
{"case":{"caseId":"case:sha256:fe11af1ff1d7d0a09b62c9837c15766e7e936342ba1fce4f09ce9b13891c8f7f","constraints":{"executionContext":"node"},"contract":["parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType","parse with sourceType module parses ECMAScript module import and export declarations","parseExpression parses a single JavaScript expression string directly into an Expression AST node","parse with jsx plugin parses JSX syntax into JSXElement AST nodes","parse with tokens option set to true populates the tokens array with lexical tokens","parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes","parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax","tokTypes exposes standard token type descriptors including parenL, parenR, and name"],"goal":"verify pkg:npm/%40babel/parser@8.0.4","kind":"HOW","packages":["pkg:npm/%40babel/parser@8.0.4"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/parser@8.0.4"],"schemaVersion":1,"subject":"pkg:npm/%40babel/parser@8.0.4","verifierAdapter":"node-typescript@1"}
{
"name": "sample-babel-parser",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-babel-parser",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/parser": "8.0.4"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.0.0.tgz",
"integrity": "sha512-6mJgmFFFIIO82vvoLt9XtRC7/TkzXfts1t/SpRX4IHSzMgqoPYCWesVu1udUPUWioAE/2fcG6WuI8zrkE1gwrg==",
"license": "MIT",
"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/@babel/parser": {
"version": "8.0.4",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.0.4.tgz",
"integrity": "sha512-srpptsAkEbbNIC/q8nT7o+m6CQe8CJUTV/t7MYc9NnWlgYVtHOb7JH6SorxMhN0kuRJjVqXbKClG6xSbPtzz+g==",
"license": "MIT",
"dependencies": {
"@babel/types": "^8.0.4"
},
"bin": {
"parser": "bin/babel-parser.js"
},
"engines": {
"node": "^22.18.0 || >=24.11.0"
}
},
"node_modules/@babel/types": {
"version": "8.0.4",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-8.0.4.tgz",
"integrity": "sha512-eY+Yn3dCqTGmyiq2QRU66lA5FL8lqqqvecHt0fF3uHONIa7ToYsaCiWV8lOKqAs0Rb2SjixiKFROngnulPtt2g==",
"license": "MIT",
"dependencies": {
"@babel/helper-string-parser": "^8.0.0",
"@babel/helper-validator-identifier": "^8.0.4"
},
"engines": {
"node": "^22.18.0 || >=24.11.0"
}
}
}
}
{
"name": "sample-babel-parser",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of @babel/parser",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"@babel/parser": "8.0.4"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40babel/parser@8.0.4",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/parser@8.0.4"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
const { parse, parseExpression, tokTypes } = require('@babel/parser');
/**
* Parses JavaScript source code into an AST File node.
* @param {string} code - The source code to parse.
* @param {object} [options] - Parser configuration options.
* @returns {object} The parsed AST root File node.
*/
function parseSource(code, options = {}) {
return parse(code, options);
}
/**
* Parses a single JavaScript expression into an AST Expression node.
* @param {string} code - The expression code to parse.
* @param {object} [options] - Parser configuration options.
* @returns {object} The parsed AST Expression node.
*/
function parseExpr(code, options = {}) {
return parseExpression(code, options);
}
/**
* Retrieves the token type object by name.
* @param {string} name - Name of the token type.
* @returns {object|undefined} The token type descriptor.
*/
function getTokenType(name) {
return tokTypes[name];
}
module.exports = {
parseSource,
parseExpr,
getTokenType,
tokTypes,
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
parseSource,
parseExpr,
getTokenType,
tokTypes,
} = require('../src/index.js');
async function runContract() {
// 1. parse parses JavaScript source code into a File AST node containing a Program body with default script sourceType
const ast1 = parseSource('const a = 1;');
assert.strictEqual(ast1.type, 'File', 'root node should be File');
assert.strictEqual(ast1.program.type, 'Program', 'ast.program should be Program');
assert.strictEqual(ast1.program.sourceType, 'script', 'default sourceType should be script');
assert.strictEqual(ast1.program.body.length, 1, 'body should contain one statement');
assert.strictEqual(ast1.program.body[0].type, 'VariableDeclaration', 'statement should be VariableDeclaration');
// 2. parse with sourceType module parses ECMAScript module import and export declarations
const ast2 = parseSource('import { x } from "y"; export const z = 2;', { sourceType: 'module' });
assert.strictEqual(ast2.program.sourceType, 'module', 'sourceType should be module');
assert.strictEqual(ast2.program.body[0].type, 'ImportDeclaration', 'first statement should be ImportDeclaration');
assert.strictEqual(ast2.program.body[1].type, 'ExportNamedDeclaration', 'second statement should be ExportNamedDeclaration');
// 3. parseExpression parses a single JavaScript expression string directly into an Expression AST node
const expr = parseExpr('x + y * 2');
assert.strictEqual(expr.type, 'BinaryExpression', 'expression type should be BinaryExpression');
assert.strictEqual(expr.left.name, 'x', 'left operand should be x');
assert.strictEqual(expr.operator, '+', 'operator should be +');
assert.strictEqual(expr.right.type, 'BinaryExpression', 'right operand should be BinaryExpression');
// 4. parse with jsx plugin parses JSX syntax into JSXElement AST nodes
const ast4 = parseSource('<Button onClick={handleClick}>Click</Button>', { plugins: ['jsx'] });
const jsxStmt = ast4.program.body[0];
assert.strictEqual(jsxStmt.type, 'ExpressionStatement', 'statement should be ExpressionStatement');
assert.strictEqual(jsxStmt.expression.type, 'JSXElement', 'expression should be JSXElement');
assert.strictEqual(jsxStmt.expression.openingElement.name.name, 'Button', 'element tag should be Button');
// 5. parse with tokens option set to true populates the tokens array with lexical tokens
const ast5 = parseSource('let x = 10;', { tokens: true });
assert.strictEqual(Array.isArray(ast5.tokens), true, 'ast.tokens should be an array');
assert.strictEqual(ast5.tokens.length > 0, true, 'ast.tokens should not be empty');
assert.strictEqual(ast5.tokens[0].type.label, 'name', 'first token label should be name');
// 6. parse with ranges option set to true attaches numeric [start, end] ranges to AST nodes
const ast6 = parseSource('const foo = "bar";', { ranges: true });
assert.deepStrictEqual(ast6.program.range, [0, 18], 'program node should have [start, end] range');
assert.deepStrictEqual(ast6.program.body[0].range, [0, 18], 'body node should have [start, end] range');
// 7. parse throws a SyntaxError with code BABEL_PARSER_SYNTAX_ERROR when parsing invalid JavaScript syntax
assert.throws(
() => parseSource('const = 1;'),
(err) => {
return err instanceof SyntaxError && err.code === 'BABEL_PARSER_SYNTAX_ERROR';
},
'invalid syntax should throw SyntaxError with BABEL_PARSER_SYNTAX_ERROR'
);
// 8. tokTypes exposes standard token type descriptors including parenL, parenR, and name
assert.strictEqual(typeof tokTypes, 'object', 'tokTypes should be an object');
assert.strictEqual(getTokenType('parenL').label, '(', 'parenL token type should have label (');
assert.strictEqual(getTokenType('parenR').label, ')', 'parenR token type should have label )');
assert.strictEqual(getTokenType('name').label, 'name', 'name token type should have label name');
console.log('All contract assertions passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Seeder de origen
anónimo