CodeSampleX

샘플

estree-walker 3.0.3: asyncWalk

검증된 샘플 — npm estree-walker 3.0.3: asyncWalk. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: asyncWalk exports an async function that traverses…

sha256:f3c45c2a4cd8b9817dc96b3c95faa1dd2036044fd466a15d3bf0bdc826efe6b4

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node linux 24 · ubuntu · glibc 2.39 x64 node node npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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-06

케이스

HOW
목표
verify estree-walker.asyncWalk in pkg:npm/estree-walker@3.0.3
패키지
심벌
  • estree-walker.asyncWalk
환경
node
생성일
2026-09-06T21:33:24Z

컨트랙트

  1. asyncWalk exports an async function that traverses an ESTree AST asynchronously
  2. asyncWalk visits AST nodes in enter and leave order asynchronously
  3. asyncWalk passes node, parent, prop, and index to visitor handlers
  4. asyncWalk this.skip skips descending into child nodes of current AST node
  5. asyncWalk this.replace substitutes matched AST node in parent structure asynchronously
  6. asyncWalk this.remove deletes matched AST node from parent array asynchronously
  7. filterNodesAsync and transformNodesAsync helper utilities query and mutate AST nodes using asyncWalk

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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 estree-walker.asyncWalk in pkg:npm/estree-walker@3.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/estree-walker@3.0.3
Demonstrate these symbols/APIs:
  - estree-walker.asyncWalk

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:b5753bcda1c213933c6216c5a5d601544830363f092718ca7170b76d3948ee0b","contract":["asyncWalk exports an async function that traverses an ESTree AST asynchronously","asyncWalk visits AST nodes in enter and leave order asynchronously","asyncWalk passes node, parent, prop, and index to visitor handlers","asyncWalk this.skip skips descending into child nodes of current AST node","asyncWalk this.replace substitutes matched AST node in parent structure asynchronously","asyncWalk this.remove deletes matched AST node from parent array asynchronously","filterNodesAsync and transformNodesAsync helper utilities query and mutate AST nodes using asyncWalk"],"goal":"verify estree-walker.asyncWalk in pkg:npm/estree-walker@3.0.3","kind":"HOW","packages":["pkg:npm/estree-walker@3.0.3"],"schemaVersion":1,"symbols":["estree-walker.asyncWalk"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"node","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/estree-walker@3.0.3"],"schemaVersion":1,"subject":"pkg:npm/estree-walker@3.0.3","symbols":["estree-walker.asyncWalk"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-sample-estree-walker",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-sample-estree-walker",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "estree-walker": "3.0.3"
      }
    },
    "node_modules/@types/estree": {
      "version": "1.0.9",
      "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",
      "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==",
      "license": "MIT"
    },
    "node_modules/estree-walker": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
      "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
      "license": "MIT",
      "dependencies": {
        "@types/estree": "^1.0.0"
      }
    }
  }
}
package.json
{
  "name": "csx-sample-estree-walker",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "estree-walker": "3.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify estree-walker.asyncWalk in pkg:npm/estree-walker@3.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/estree-walker@3.0.3"
  ],
  "symbols": [
    "estree-walker.asyncWalk"
  ]
}
src/index.mjs
import { asyncWalk } from 'estree-walker';

export { asyncWalk };

/**
 * Traverses an ESTree AST asynchronously and collects nodes matching an async predicate.
 *
 * @param {object} ast - The AST root node.
 * @param {(node: object, parent: object | null) => Promise<boolean>} predicate - Async test function.
 * @returns {Promise<object[]>} Matching AST nodes.
 */
export async function filterNodesAsync(ast, predicate) {
  const matches = [];
  await asyncWalk(ast, {
    async enter(node, parent) {
      if (await predicate(node, parent)) {
        matches.push(node);
      }
    },
  });
  return matches;
}

/**
 * Transforms an ESTree AST asynchronously by applying an async replacer function.
 *
 * @param {object} ast - The AST root node.
 * @param {(node: object) => Promise<object | null | undefined>} transform - Async transformer returning replacement node, or null to remove.
 * @returns {Promise<object | null>} The transformed AST.
 */
export async function transformNodesAsync(ast, transform) {
  return await asyncWalk(ast, {
    async enter(node) {
      const result = await transform(node);
      if (result === null) {
        this.remove();
      } else if (result !== undefined && result !== node) {
        this.replace(result);
      }
    },
  });
}
test/contract.mjs
import { strict as assert } from 'node:assert';
import { asyncWalk, filterNodesAsync, transformNodesAsync } from '../src/index.mjs';

// 1. Verify asyncWalk is exported as a function
assert.equal(typeof asyncWalk, 'function');

// 2. Verify asyncWalk visits AST nodes in enter and leave order asynchronously
const sampleAst = {
  type: 'Program',
  body: [
    {
      type: 'VariableDeclaration',
      declarations: [
        {
          type: 'VariableDeclarator',
          id: { type: 'Identifier', name: 'count' },
          init: { type: 'Literal', value: 10 },
        },
      ],
      kind: 'const',
    },
  ],
};

const enterSequence = [];
const leaveSequence = [];
await asyncWalk(sampleAst, {
  async enter(node) {
    await new Promise((resolve) => setTimeout(resolve, 1));
    enterSequence.push(node.type);
  },
  async leave(node) {
    await new Promise((resolve) => setTimeout(resolve, 1));
    leaveSequence.push(node.type);
  },
});

assert.deepEqual(enterSequence, [
  'Program',
  'VariableDeclaration',
  'VariableDeclarator',
  'Identifier',
  'Literal',
]);
assert.deepEqual(leaveSequence, [
  'Identifier',
  'Literal',
  'VariableDeclarator',
  'VariableDeclaration',
  'Program',
]);

// 3. Verify enter handler receives node, parent, prop, and index
let identifierParentType = null;
let identifierProp = null;
let identifierIndex = null;

await asyncWalk(sampleAst, {
  async enter(node, parent, prop, index) {
    if (node.type === 'Identifier') {
      identifierParentType = parent?.type;
      identifierProp = prop;
      identifierIndex = index;
    }
  },
});

assert.equal(identifierParentType, 'VariableDeclarator');
assert.equal(identifierProp, 'id');
assert.equal(identifierIndex, null);

// 4. Verify this.skip skips descending into child nodes during asyncWalk
const skipAst = {
  type: 'Program',
  body: [
    {
      type: 'FunctionDeclaration',
      id: { type: 'Identifier', name: 'calculate' },
      body: {
        type: 'BlockStatement',
        body: [
          { type: 'ReturnStatement', argument: { type: 'Literal', value: 1 } },
        ],
      },
    },
  ],
};

const visitedInSkip = [];
await asyncWalk(skipAst, {
  async enter(node) {
    visitedInSkip.push(node.type);
    if (node.type === 'BlockStatement') {
      this.skip();
    }
  },
});

assert.deepEqual(visitedInSkip, [
  'Program',
  'FunctionDeclaration',
  'Identifier',
  'BlockStatement',
]);

// 5. Verify this.replace substitutes matched node asynchronously
const replaceAst = {
  type: 'Program',
  body: [
    {
      type: 'ExpressionStatement',
      expression: { type: 'Identifier', name: 'beforeReplace' },
    },
  ],
};

await asyncWalk(replaceAst, {
  async enter(node) {
    if (node.type === 'Identifier' && node.name === 'beforeReplace') {
      await new Promise((resolve) => setTimeout(resolve, 1));
      this.replace({ type: 'Identifier', name: 'afterReplace' });
    }
  },
});

assert.equal(replaceAst.body[0].expression.name, 'afterReplace');

// 6. Verify this.remove deletes matched node from parent array asynchronously
const removeAst = {
  type: 'Program',
  body: [
    { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'a' } },
    { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'b' } },
    { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'c' } },
  ],
};

await asyncWalk(removeAst, {
  async enter(node) {
    if (node.type === 'ExpressionStatement' && node.expression?.name === 'b') {
      await new Promise((resolve) => setTimeout(resolve, 1));
      this.remove();
    }
  },
});

assert.equal(removeAst.body.length, 2);
assert.equal(removeAst.body[0].expression.name, 'a');
assert.equal(removeAst.body[1].expression.name, 'c');

// 7. Verify helper functions filterNodesAsync and transformNodesAsync
const foundIdentifiers = await filterNodesAsync(sampleAst, async (n) => n.type === 'Identifier');
assert.equal(foundIdentifiers.length, 1);
assert.equal(foundIdentifiers[0].name, 'count');

const astToTransform = {
  type: 'Program',
  body: [
    { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'target' } },
    { type: 'ExpressionStatement', expression: { type: 'Identifier', name: 'obsolete' } },
  ],
};

await transformNodesAsync(astToTransform, async (node) => {
  if (node.type === 'Identifier' && node.name === 'target') {
    return { type: 'Identifier', name: 'transformed' };
  }
  if (node.type === 'ExpressionStatement' && node.expression?.name === 'obsolete') {
    return null;
  }
});

assert.equal(astToTransform.body.length, 1);
assert.equal(astToTransform.body[0].expression.name, 'transformed');

console.log('CONTRACT PASS: estree-walker.asyncWalk verified');

오리진 시더

익명