CodeSampleX

Sample

estraverse 5.3.0: replace

Verified sample for npm estraverse 5.3.0: replace. The contract ran on node 22 · linux alpine/x64 · docker and passed: replace substitutes matching AST node…

sha256:4f704c1a34129b95712d08eb2d9548b446eeb06002768297bafcbcff8ab7112d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify estraverse.replace in pkg:npm/estraverse@5.3.0
Packages
Symbols
  • estraverse.replace
Environment
node 22.23.2
Created
2026-08-23T14:23:38Z

Contract

  1. replace substitutes matching AST node with new node returned from enter callback
  2. replace substitutes matching AST node with new node returned from leave callback
  3. replace removes node from AST array when VisitorOption.Remove is returned from enter
  4. replace removes node from AST array when VisitorOption.Remove is returned from leave
  5. replace skips descending into children of replaced node when VisitorOption.Skip is returned
  6. replace aborts full traversal immediately when VisitorOption.Break is returned
  7. replace passes current node and parent node to enter and leave callbacks
  8. replace transforms nested AST expressions and returns updated root AST structure

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

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 estraverse.replace 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.replace
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:7cc829a2c12eca35bd0fd985d3b13f16691ee8241a955e0e5b8802192e6066f7","constraints":{"executionContext":"node"},"contract":["replace substitutes matching AST node with new node returned from enter callback","replace substitutes matching AST node with new node returned from leave callback","replace removes node from AST array when VisitorOption.Remove is returned from enter","replace removes node from AST array when VisitorOption.Remove is returned from leave","replace skips descending into children of replaced node when VisitorOption.Skip is returned","replace aborts full traversal immediately when VisitorOption.Break is returned","replace passes current node and parent node to enter and leave callbacks","replace transforms nested AST expressions and returns updated root AST structure"],"goal":"verify estraverse.replace in pkg:npm/estraverse@5.3.0","kind":"HOW","packages":["pkg:npm/estraverse@5.3.0"],"schemaVersion":1,"symbols":["estraverse.replace"]},"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/estraverse@5.3.0"],"schemaVersion":1,"subject":"pkg:npm/estraverse@5.3.0","symbols":["estraverse.replace"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-estraverse-replace",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-estraverse-replace",
      "version": "1.0.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"
      }
    }
  }
}
package.json
{
  "name": "sample-estraverse-replace",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "estraverse": "5.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify estraverse.replace in pkg:npm/estraverse@5.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/estraverse@5.3.0"
  ],
  "symbols": [
    "estraverse.replace"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import estraverse from 'estraverse';

// 1. replace substitutes matching AST node with new node returned from enter callback
{
  const ast = {
    type: 'Program',
    body: [
      {
        type: 'ExpressionStatement',
        expression: {
          type: 'Identifier',
          name: 'foo'
        }
      }
    ]
  };

  const result = estraverse.replace(ast, {
    enter(node) {
      if (node.type === 'Identifier' && node.name === 'foo') {
        return { type: 'Identifier', name: 'bar' };
      }
    }
  });

  assert.equal(result.body[0].expression.name, 'bar');
  assert.equal(ast.body[0].expression.name, 'bar');
}

// 2. replace substitutes matching AST node with new node returned from leave callback
{
  const ast = {
    type: 'Program',
    body: [
      {
        type: 'ExpressionStatement',
        expression: {
          type: 'Literal',
          value: 42,
          raw: '42'
        }
      }
    ]
  };

  const result = estraverse.replace(ast, {
    leave(node) {
      if (node.type === 'Literal' && node.value === 42) {
        return { type: 'Literal', value: 100, raw: '100' };
      }
    }
  });

  assert.equal(result.body[0].expression.value, 100);
}

// 3. replace removes node from AST array when VisitorOption.Remove is returned from enter
{
  const ast = {
    type: 'Program',
    body: [
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'keep1' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'removeMe' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'keep2' } }
    ]
  };

  estraverse.replace(ast, {
    enter(node) {
      if (node.type === 'ExpressionStatement' && node.expression.name === 'removeMe') {
        return estraverse.VisitorOption.Remove;
      }
    }
  });

  assert.equal(ast.body.length, 2);
  assert.equal(ast.body[0].expression.name, 'keep1');
  assert.equal(ast.body[1].expression.name, 'keep2');
}

// 4. replace removes node from AST array when VisitorOption.Remove is returned from leave
{
  const ast = {
    type: 'Program',
    body: [
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'first' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'drop' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'second' } }
    ]
  };

  estraverse.replace(ast, {
    leave(node) {
      if (node.type === 'ExpressionStatement' && node.expression.name === 'drop') {
        return estraverse.VisitorOption.Remove;
      }
    }
  });

  assert.equal(ast.body.length, 2);
  assert.equal(ast.body[0].expression.name, 'first');
  assert.equal(ast.body[1].expression.name, 'second');
}

// 5. replace skips descending into children of replaced node when VisitorOption.Skip is returned
{
  const ast = {
    type: 'Program',
    body: [
      {
        type: 'BinaryExpression',
        operator: '+',
        left: { type: 'Identifier', name: 'a' },
        right: { type: 'Identifier', name: 'b' }
      }
    ]
  };

  const visitedTypes = [];
  estraverse.replace(ast, {
    enter(node) {
      visitedTypes.push(node.type);
      if (node.type === 'BinaryExpression') {
        return estraverse.VisitorOption.Skip;
      }
    }
  });

  assert.deepEqual(visitedTypes, ['Program', 'BinaryExpression']);
}

// 6. replace aborts full traversal immediately when VisitorOption.Break is returned
{
  const ast = {
    type: 'Program',
    body: [
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'one' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'stop' } },
      { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'three' } }
    ]
  };

  const visitedNames = [];
  estraverse.replace(ast, {
    enter(node) {
      if (node.type === 'Identifier') {
        visitedNames.push(node.name);
        if (node.name === 'stop') {
          return estraverse.VisitorOption.Break;
        }
      }
    }
  });

  assert.deepEqual(visitedNames, ['one', 'stop']);
}

// 7. replace passes current node and parent node to enter and leave callbacks
{
  const ast = {
    type: 'Program',
    body: [
      {
        type: 'ExpressionStatement',
        expression: {
          type: 'Identifier',
          name: 'target'
        }
      }
    ]
  };

  let enterParentType = null;
  let leaveParentType = null;

  estraverse.replace(ast, {
    enter(node, parent) {
      if (node.type === 'Identifier' && node.name === 'target') {
        enterParentType = parent ? parent.type : null;
      }
    },
    leave(node, parent) {
      if (node.type === 'Identifier' && node.name === 'target') {
        leaveParentType = parent ? parent.type : null;
      }
    }
  });

  assert.equal(enterParentType, 'ExpressionStatement');
  assert.equal(leaveParentType, 'ExpressionStatement');
}

// 8. replace transforms nested AST expressions and returns updated root AST structure
{
  const ast = {
    type: 'Program',
    body: [
      {
        type: 'ExpressionStatement',
        expression: {
          type: 'BinaryExpression',
          operator: '+',
          left: {
            type: 'BinaryExpression',
            operator: '*',
            left: { type: 'Literal', value: 2, raw: '2' },
            right: { type: 'Literal', value: 3, raw: '3' }
          },
          right: { type: 'Literal', value: 4, raw: '4' }
        }
      }
    ]
  };

  const result = estraverse.replace(ast, {
    leave(node) {
      if (
        node.type === 'BinaryExpression' &&
        node.operator === '*' &&
        node.left.type === 'Literal' &&
        node.right.type === 'Literal'
      ) {
        const val = node.left.value * node.right.value;
        return {
          type: 'Literal',
          value: val,
          raw: String(val)
        };
      }
    }
  });

  assert.equal(result.type, 'Program');
  const expr = result.body[0].expression;
  assert.equal(expr.type, 'BinaryExpression');
  assert.equal(expr.operator, '+');
  assert.equal(expr.left.type, 'Literal');
  assert.equal(expr.left.value, 6);
  assert.equal(expr.right.value, 4);
}

Origin Seeder

anonymous