Ejemplo
estraverse 5.3.0: Syntax
Muestra verificada para npm estraverse 5.3.0: Syntax. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: estraverse.Syntax is exported as…
sha256:84e59534797ec511bf4e7172c83bc1be568a206b8e25e1c3fe9b3450cdba2332
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
- 2
- 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 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 |
Caso
HOW- Objetivo
- verify estraverse.Syntax in pkg:npm/estraverse@5.3.0
- Paquetes
- Símbolos
-
- estraverse.Syntax
- Creado
- 2026-08-23T14:17:40Z
Contrato
- estraverse.Syntax is exported as an object mapping AST node type names to identical string constants
- Syntax defines core ESTree declarations and statements including Program, FunctionDeclaration, and VariableDeclaration
- Syntax defines core ESTree expressions and literals including BinaryExpression, CallExpression, MemberExpression, Identifier, and Literal
- Syntax defines modern ES6+ node types including ArrowFunctionExpression, ClassDeclaration, TemplateLiteral, and AwaitExpression
- Syntax constants match node.type values when traversing an AST with estraverse.traverse
- Syntax constants enable filtering and selective transformation of AST nodes with estraverse.replace
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 estraverse.Syntax in pkg:npm/estraverse@5.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/estraverse@5.3.0
Demonstrate these symbols/APIs:
- estraverse.Syntax
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:76067f4842cef786642ceef39785534d6b8804de46865c3e9b1abd49617a22fb","contract":["estraverse.Syntax is exported as an object mapping AST node type names to identical string constants","Syntax defines core ESTree declarations and statements including Program, FunctionDeclaration, and VariableDeclaration","Syntax defines core ESTree expressions and literals including BinaryExpression, CallExpression, MemberExpression, Identifier, and Literal","Syntax defines modern ES6+ node types including ArrowFunctionExpression, ClassDeclaration, TemplateLiteral, and AwaitExpression","Syntax constants match node.type values when traversing an AST with estraverse.traverse","Syntax constants enable filtering and selective transformation of AST nodes with estraverse.replace"],"goal":"verify estraverse.Syntax in pkg:npm/estraverse@5.3.0","kind":"HOW","packages":["pkg:npm/estraverse@5.3.0"],"schemaVersion":1,"symbols":["estraverse.Syntax"]},"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/estraverse@5.3.0"],"schemaVersion":1,"subject":"pkg:npm/estraverse@5.3.0","symbols":["estraverse.Syntax"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-estraverse-syntax",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-estraverse-syntax",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"estraverse": "5.3.0"
}
},
"node_modules/estraverse": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",
"integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=4.0"
}
}
}
}
{
"name": "sample-estraverse-syntax",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for estraverse.Syntax in estraverse@5.3.0",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"estraverse": "5.3.0"
}
}
{
"schemaVersion": 1,
"goal": "verify estraverse.Syntax in pkg:npm/estraverse@5.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/estraverse@5.3.0"
],
"symbols": [
"estraverse.Syntax"
]
}
const estraverse = require('estraverse');
const {
Syntax,
traverse,
replace,
VisitorOption,
VisitorKeys,
Controller
} = estraverse;
/**
* Checks if a given AST node matches a specific Syntax type.
*
* @param {object} node - AST node to check.
* @param {string} syntaxType - Expected Syntax constant (e.g. Syntax.Identifier).
* @returns {boolean} True if node.type matches syntaxType.
*/
function isNodeType(node, syntaxType) {
if (!node || typeof node !== 'object') {
return false;
}
return node.type === syntaxType;
}
/**
* Collects all nodes matching the specified Syntax type from an AST.
*
* @param {object} ast - AST root node.
* @param {string} syntaxType - Syntax constant to filter by.
* @returns {object[]} Array of matching AST nodes.
*/
function findNodesByType(ast, syntaxType) {
const matches = [];
traverse(ast, {
enter(node) {
if (node.type === syntaxType) {
matches.push(node);
}
}
});
return matches;
}
/**
* Counts occurrences of each Syntax type present in an AST.
*
* @param {object} ast - AST root node.
* @returns {Record<string, number>} Map of Syntax type to count.
*/
function countSyntaxOccurrences(ast) {
const counts = {};
traverse(ast, {
enter(node) {
const type = node.type;
if (type && typeof type === 'string') {
counts[type] = (counts[type] || 0) + 1;
}
}
});
return counts;
}
/**
* Renames all Identifier nodes matching an old name to a new name.
*
* @param {object} ast - AST root node.
* @param {string} oldName - Name to replace.
* @param {string} newName - Replacement name.
* @returns {object} Transformed AST root node.
*/
function renameIdentifiers(ast, oldName, newName) {
return replace(ast, {
enter(node) {
if (node.type === Syntax.Identifier && node.name === oldName) {
return {
...node,
name: newName
};
}
}
});
}
module.exports = {
estraverse,
Syntax,
traverse,
replace,
VisitorOption,
VisitorKeys,
Controller,
isNodeType,
findNodesByType,
countSyntaxOccurrences,
renameIdentifiers
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
estraverse,
Syntax,
traverse,
replace,
isNodeType,
findNodesByType,
countSyntaxOccurrences,
renameIdentifiers
} = require('../src/index.js');
async function runTests() {
// 1. estraverse.Syntax is exported as an object mapping AST node type names to identical string constants
assert.equal(typeof Syntax, 'object', 'Syntax must be exported as an object');
assert.ok(Syntax !== null, 'Syntax must not be null');
assert.strictEqual(estraverse.Syntax, Syntax, 'estraverse.Syntax must match exported Syntax');
// Verify self-mapping property for all keys in Syntax
const syntaxKeys = Object.keys(Syntax);
assert.ok(syntaxKeys.length > 50, 'Syntax should contain comprehensive ESTree node types');
for (const key of syntaxKeys) {
assert.strictEqual(Syntax[key], key, `Syntax.${key} must map to "${key}"`);
}
// 2. Syntax defines core ESTree declarations and statements including Program, FunctionDeclaration, and VariableDeclaration
assert.strictEqual(Syntax.Program, 'Program');
assert.strictEqual(Syntax.FunctionDeclaration, 'FunctionDeclaration');
assert.strictEqual(Syntax.FunctionExpression, 'FunctionExpression');
assert.strictEqual(Syntax.VariableDeclaration, 'VariableDeclaration');
assert.strictEqual(Syntax.VariableDeclarator, 'VariableDeclarator');
assert.strictEqual(Syntax.BlockStatement, 'BlockStatement');
assert.strictEqual(Syntax.IfStatement, 'IfStatement');
assert.strictEqual(Syntax.ReturnStatement, 'ReturnStatement');
assert.strictEqual(Syntax.ForStatement, 'ForStatement');
assert.strictEqual(Syntax.ForInStatement, 'ForInStatement');
assert.strictEqual(Syntax.ForOfStatement, 'ForOfStatement');
assert.strictEqual(Syntax.WhileStatement, 'WhileStatement');
assert.strictEqual(Syntax.DoWhileStatement, 'DoWhileStatement');
assert.strictEqual(Syntax.SwitchStatement, 'SwitchStatement');
assert.strictEqual(Syntax.SwitchCase, 'SwitchCase');
assert.strictEqual(Syntax.TryStatement, 'TryStatement');
assert.strictEqual(Syntax.CatchClause, 'CatchClause');
assert.strictEqual(Syntax.ThrowStatement, 'ThrowStatement');
assert.strictEqual(Syntax.ExpressionStatement, 'ExpressionStatement');
// 3. Syntax defines core ESTree expressions and literals including BinaryExpression, CallExpression, MemberExpression, Identifier, and Literal
assert.strictEqual(Syntax.Identifier, 'Identifier');
assert.strictEqual(Syntax.Literal, 'Literal');
assert.strictEqual(Syntax.BinaryExpression, 'BinaryExpression');
assert.strictEqual(Syntax.CallExpression, 'CallExpression');
assert.strictEqual(Syntax.MemberExpression, 'MemberExpression');
assert.strictEqual(Syntax.AssignmentExpression, 'AssignmentExpression');
assert.strictEqual(Syntax.LogicalExpression, 'LogicalExpression');
assert.strictEqual(Syntax.UnaryExpression, 'UnaryExpression');
assert.strictEqual(Syntax.UpdateExpression, 'UpdateExpression');
assert.strictEqual(Syntax.ArrayExpression, 'ArrayExpression');
assert.strictEqual(Syntax.ObjectExpression, 'ObjectExpression');
assert.strictEqual(Syntax.Property, 'Property');
assert.strictEqual(Syntax.ThisExpression, 'ThisExpression');
assert.strictEqual(Syntax.NewExpression, 'NewExpression');
assert.strictEqual(Syntax.ConditionalExpression, 'ConditionalExpression');
// 4. Syntax defines modern ES6+ node types including ArrowFunctionExpression, ClassDeclaration, TemplateLiteral, and AwaitExpression
assert.strictEqual(Syntax.ArrowFunctionExpression, 'ArrowFunctionExpression');
assert.strictEqual(Syntax.ClassDeclaration, 'ClassDeclaration');
assert.strictEqual(Syntax.ClassExpression, 'ClassExpression');
assert.strictEqual(Syntax.ClassBody, 'ClassBody');
assert.strictEqual(Syntax.MethodDefinition, 'MethodDefinition');
assert.strictEqual(Syntax.PropertyDefinition, 'PropertyDefinition');
assert.strictEqual(Syntax.PrivateIdentifier, 'PrivateIdentifier');
assert.strictEqual(Syntax.TemplateLiteral, 'TemplateLiteral');
assert.strictEqual(Syntax.TemplateElement, 'TemplateElement');
assert.strictEqual(Syntax.TaggedTemplateExpression, 'TaggedTemplateExpression');
assert.strictEqual(Syntax.SpreadElement, 'SpreadElement');
assert.strictEqual(Syntax.RestElement, 'RestElement');
assert.strictEqual(Syntax.AwaitExpression, 'AwaitExpression');
assert.strictEqual(Syntax.YieldExpression, 'YieldExpression');
assert.strictEqual(Syntax.ImportDeclaration, 'ImportDeclaration');
assert.strictEqual(Syntax.ExportNamedDeclaration, 'ExportNamedDeclaration');
assert.strictEqual(Syntax.ExportDefaultDeclaration, 'ExportDefaultDeclaration');
assert.strictEqual(Syntax.ChainExpression, 'ChainExpression');
assert.strictEqual(Syntax.ImportExpression, 'ImportExpression');
// 5. Syntax constants match node.type values when traversing an AST with estraverse.traverse
const ast = {
type: Syntax.Program,
body: [
{
type: Syntax.VariableDeclaration,
kind: 'const',
declarations: [
{
type: Syntax.VariableDeclarator,
id: { type: Syntax.Identifier, name: 'greeting' },
init: { type: Syntax.Literal, value: 'hello' }
}
]
},
{
type: Syntax.FunctionDeclaration,
id: { type: Syntax.Identifier, name: 'greet' },
params: [{ type: Syntax.Identifier, name: 'user' }],
body: {
type: Syntax.BlockStatement,
body: [
{
type: Syntax.ReturnStatement,
argument: {
type: Syntax.BinaryExpression,
operator: '+',
left: { type: Syntax.Identifier, name: 'greeting' },
right: { type: Syntax.Identifier, name: 'user' }
}
}
]
}
}
]
};
const identifiers = findNodesByType(ast, Syntax.Identifier);
assert.equal(identifiers.length, 5, 'Should find 5 identifier nodes in the AST');
assert.deepStrictEqual(
identifiers.map((n) => n.name),
['greeting', 'greet', 'user', 'greeting', 'user'],
'Should match expected identifier names in traversal order'
);
const occurrences = countSyntaxOccurrences(ast);
assert.strictEqual(occurrences[Syntax.Program], 1);
assert.strictEqual(occurrences[Syntax.VariableDeclaration], 1);
assert.strictEqual(occurrences[Syntax.VariableDeclarator], 1);
assert.strictEqual(occurrences[Syntax.FunctionDeclaration], 1);
assert.strictEqual(occurrences[Syntax.BlockStatement], 1);
assert.strictEqual(occurrences[Syntax.ReturnStatement], 1);
assert.strictEqual(occurrences[Syntax.BinaryExpression], 1);
assert.strictEqual(occurrences[Syntax.Literal], 1);
assert.strictEqual(occurrences[Syntax.Identifier], 5);
assert.ok(isNodeType(ast, Syntax.Program));
assert.ok(isNodeType(ast.body[0], Syntax.VariableDeclaration));
assert.ok(!isNodeType(ast.body[0], Syntax.FunctionDeclaration));
// 6. Syntax constants enable filtering and selective transformation of AST nodes with estraverse.replace
const transformedAst = renameIdentifiers(ast, 'user', 'recipient');
const transformedIdentifiers = findNodesByType(transformedAst, Syntax.Identifier);
assert.deepStrictEqual(
transformedIdentifiers.map((n) => n.name),
['greeting', 'greet', 'recipient', 'greeting', 'recipient'],
'renameIdentifiers using Syntax.Identifier should transform targeted identifiers'
);
// Verify deletion using replace with Syntax constant
const prunedAst = replace(transformedAst, {
enter(node) {
if (node.type === Syntax.VariableDeclaration) {
this.remove();
}
}
});
assert.strictEqual(prunedAst.body.length, 1, 'VariableDeclaration should be removed');
assert.strictEqual(prunedAst.body[0].type, Syntax.FunctionDeclaration);
console.log('All contract assertions for estraverse.Syntax passed successfully.');
}
runTests().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Seeder de origen
anónimo