Exemple
@babel/traverse 7.29.7: default
Échantillon vérifié pour npm @babel/traverse 7.29.7: default. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:5b3d60ba7aa2c0165aed00a3a0ceece5b33ac42c173ae3894b1e69316101d463
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify @babel/traverse.default in pkg:npm/%40babel/traverse@7.29.7
- Paquets
- Symboles
-
- @babel/traverse.default
- Environnement
- node 22.23.2
- Créé
- 2026-09-05T17:28:02Z
Contrat
- traverse.default is exported as a callable function from @babel/traverse
- traverse traverses AST nodes and invokes visitor methods on matching node types
- traverse mutates AST node properties in place when updated through path.node
- path.replaceWith substitutes matching AST node with the replacement node
- path.remove removes AST node from its parent list container
- path.stop immediately halts all subsequent AST traversal
- path.skip bypasses traversal of descendants of the current AST node
- traverse passes custom state object across visitor handlers
- traverse gracefully handles null or undefined AST root without throwing
- path.scope resolves bindings and renames identifiers across scope hierarchy
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Code source
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/traverse.default in pkg:npm/%40babel/traverse@7.29.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40babel/traverse@7.29.7
Demonstrate these symbols/APIs:
- @babel/traverse.default
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:aa8b1338f1e98ad71e6a5ddc01bbca0e1e7a703734d1befc57d33bd7158b4896","contract":["traverse.default is exported as a callable function from @babel/traverse","traverse traverses AST nodes and invokes visitor methods on matching node types","traverse mutates AST node properties in place when updated through path.node","path.replaceWith substitutes matching AST node with the replacement node","path.remove removes AST node from its parent list container","path.stop immediately halts all subsequent AST traversal","path.skip bypasses traversal of descendants of the current AST node","traverse passes custom state object across visitor handlers","traverse gracefully handles null or undefined AST root without throwing","path.scope resolves bindings and renames identifiers across scope hierarchy"],"goal":"verify @babel/traverse.default in pkg:npm/%40babel/traverse@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/traverse@7.29.7"],"schemaVersion":1,"symbols":["@babel/traverse.default"]},"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","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40babel/traverse@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/traverse@7.29.7","symbols":["@babel/traverse.default"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-babel-traverse-default",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-babel-traverse-default",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/traverse": "7.29.7"
}
},
"node_modules/@babel/code-frame": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz",
"integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==",
"license": "MIT",
"dependencies": {
"@babel/helper-validator-identifier": "^7.29.7",
"js-tokens": "^4.0.0",
"picocolors": "^1.1.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/generator": {
"version": "7.29.8",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.8.tgz",
"integrity": "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg==",
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.29.8",
"@babel/types": "^7.29.8",
"@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-globals": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz",
"integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==",
"license": "MIT",
"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/template": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz",
"integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==",
"license": "MIT",
"dependencies": {
"@babel/code-frame": "^7.29.7",
"@babel/parser": "^7.29.7",
"@babel/types": "^7.29.7"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/traverse": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.7.tgz",
"integrity": "sha512-EhlfNQtZ+NK22w5BM61ciuiq1m58ed33Wr1Xan//ZRTy6hgjnwyCffRYwzsGXdASJSUJ1guZILsErh1eQcl+zw==",
"license": "MIT",
"dependencies": {
"@babel/code-frame": "^7.29.7",
"@babel/generator": "^7.29.7",
"@babel/helper-globals": "^7.29.7",
"@babel/parser": "^7.29.7",
"@babel/template": "^7.29.7",
"@babel/types": "^7.29.7",
"debug": "^4.3.1"
},
"engines": {
"node": ">=6.9.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/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"license": "MIT"
},
"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"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
"license": "ISC"
}
}
}
{
"name": "sample-babel-traverse-default",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@babel/traverse": "7.29.7"
}
}
{
"schemaVersion": 1,
"goal": "verify @babel/traverse.default in pkg:npm/%40babel/traverse@7.29.7",
"kind": "HOW",
"packages": [
"pkg:npm/%40babel/traverse@7.29.7"
],
"symbols": [
"@babel/traverse.default"
]
}
'use strict';
const traverseModule = require('@babel/traverse');
const traverse = traverseModule.default;
/**
* Traverses an AST using @babel/traverse.default.
*
* @param {object} ast - The AST root node.
* @param {object} visitor - Visitor object with node handlers.
* @param {object} [scope] - Scope object.
* @param {object} [state] - State object passed to visitor handlers.
* @param {object} [parentPath] - Parent NodePath.
*/
function traverseAst(ast, visitor, scope, state, parentPath) {
return traverse(ast, visitor, scope, state, parentPath);
}
/**
* Renames all occurrences of an identifier in the given AST.
*
* @param {object} ast - The AST root node.
* @param {string} oldName - The identifier name to replace.
* @param {string} newName - The replacement identifier name.
* @returns {object} The mutated AST.
*/
function renameIdentifier(ast, oldName, newName) {
traverse(ast, {
Identifier(path) {
if (path.node.name === oldName) {
path.node.name = newName;
}
}
});
return ast;
}
/**
* Collects all visited AST node types in traversal order.
*
* @param {object} ast - The AST root node.
* @returns {string[]} Array of node type names.
*/
function collectNodeTypes(ast) {
const types = [];
traverse(ast, {
enter(path) {
types.push(path.node.type);
}
});
return types;
}
/**
* Replaces matching AST nodes with a replacement node.
*
* @param {object} ast - The AST root node.
* @param {string} targetType - Target node type to replace.
* @param {Function} predicate - Predicate receiving path, returns boolean.
* @param {object} replacementNode - Node to replace with.
* @returns {object} The mutated AST.
*/
function replaceNodes(ast, targetType, predicate, replacementNode) {
traverse(ast, {
[targetType](path) {
if (predicate(path)) {
path.replaceWith(replacementNode);
}
}
});
return ast;
}
module.exports = {
traverseModule,
traverse,
traverseAst,
renameIdentifier,
collectNodeTypes,
replaceNodes
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
traverseModule,
traverse,
traverseAst,
renameIdentifier,
collectNodeTypes,
replaceNodes
} = require('../src/index.js');
function createFileAst(body) {
return {
type: 'File',
program: {
type: 'Program',
sourceType: 'module',
body: body,
directives: []
},
comments: []
};
}
async function main() {
// 1. traverse.default is exported as a callable function from @babel/traverse
assert.strictEqual(typeof traverseModule, 'object');
assert.strictEqual(typeof traverseModule.default, 'function');
assert.strictEqual(typeof traverse, 'function');
// 2. traverse traverses AST nodes and invokes visitor methods on matching node types
const ast2 = createFileAst([
{
type: 'VariableDeclaration',
kind: 'const',
declarations: [
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'alpha' },
init: { type: 'NumericLiteral', value: 100 }
}
]
}
]);
const nodeTypes = collectNodeTypes(ast2);
assert(nodeTypes.includes('VariableDeclaration'));
assert(nodeTypes.includes('VariableDeclarator'));
assert(nodeTypes.includes('Identifier'));
assert(nodeTypes.includes('NumericLiteral'));
// 3. traverse mutates AST node properties in place when updated through path.node
const ast3 = createFileAst([
{
type: 'VariableDeclaration',
kind: 'let',
declarations: [
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'originalName' },
init: { type: 'StringLiteral', value: 'hello' }
}
]
}
]);
renameIdentifier(ast3, 'originalName', 'updatedName');
assert.strictEqual(ast3.program.body[0].declarations[0].id.name, 'updatedName');
// 4. path.replaceWith substitutes matching AST node with the replacement node
const ast4 = createFileAst([
{
type: 'ExpressionStatement',
expression: { type: 'Identifier', name: 'toBeReplaced' }
}
]);
replaceNodes(
ast4,
'Identifier',
(p) => p.node.name === 'toBeReplaced',
{ type: 'StringLiteral', value: 'replacedString' }
);
assert.strictEqual(ast4.program.body[0].expression.type, 'StringLiteral');
assert.strictEqual(ast4.program.body[0].expression.value, 'replacedString');
// 5. path.remove removes AST node from its parent list container
const ast5 = createFileAst([
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'itemToDelete' } },
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'itemToKeep' } }
]);
traverseAst(ast5, {
Identifier(p) {
if (p.node.name === 'itemToDelete') {
p.parentPath.remove();
}
}
});
assert.strictEqual(ast5.program.body.length, 1);
assert.strictEqual(ast5.program.body[0].expression.name, 'itemToKeep');
// 6. path.stop immediately halts all subsequent AST traversal
const ast6 = createFileAst([
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'stopFirst' } },
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'stopSecond' } },
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'stopThird' } }
]);
const visitedAfterStop = [];
traverseAst(ast6, {
Identifier(p) {
visitedAfterStop.push(p.node.name);
p.stop();
}
});
assert.deepStrictEqual(visitedAfterStop, ['stopFirst']);
// 7. path.skip bypasses traversal of descendants of the current AST node
const ast7 = createFileAst([
{
type: 'FunctionDeclaration',
id: { type: 'Identifier', name: 'skippedFunc' },
params: [{ type: 'Identifier', name: 'innerArg' }],
body: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: { type: 'Identifier', name: 'nestedVar' }
}
]
}
},
{
type: 'ExpressionStatement',
expression: { type: 'Identifier', name: 'outsideIdent' }
}
]);
const visitedIdents = [];
traverseAst(ast7, {
FunctionDeclaration(p) {
p.skip();
},
Identifier(p) {
visitedIdents.push(p.node.name);
}
});
assert.deepStrictEqual(visitedIdents, ['outsideIdent']);
// 8. traverse passes custom state object across visitor handlers
const ast8 = createFileAst([
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'itemA' } },
{ type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'itemB' } }
]);
const customState = { records: [] };
traverseAst(
ast8,
{
Identifier(p, s) {
s.records.push(p.node.name);
}
},
undefined,
customState
);
assert.deepStrictEqual(customState.records, ['itemA', 'itemB']);
// 9. traverse gracefully handles null or undefined AST root without throwing
assert.strictEqual(traverseAst(null, {}), undefined);
assert.strictEqual(traverseAst(undefined, {}), undefined);
// 10. path.scope resolves bindings and renames identifiers across scope hierarchy
const ast10 = createFileAst([
{
type: 'VariableDeclaration',
kind: 'let',
declarations: [
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'counter' },
init: { type: 'Identifier', name: 'counter' }
}
]
}
]);
let scopeHasBinding = false;
traverseAst(ast10, {
Program(p) {
scopeHasBinding = p.scope.hasBinding('counter');
p.scope.rename('counter', 'tally');
}
});
assert.strictEqual(scopeHasBinding, true);
assert.strictEqual(ast10.program.body[0].declarations[0].id.name, 'tally');
assert.strictEqual(ast10.program.body[0].declarations[0].init.name, 'tally');
console.log('All contract assertions passed successfully.');
}
main().catch((err) => {
console.error('Contract failed:', err);
process.exit(1);
});
Seeder d'origine
anonyme