CodeSampleX

샘플

estraverse 5.3.0: Syntax

검증된 샘플 — npm estraverse 5.3.0: Syntax. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: estraverse.Syntax is exported as an object mapping AST…

sha256:84e59534797ec511bf4e7172c83bc1be568a206b8e25e1c3fe9b3450cdba2332

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify estraverse.Syntax in pkg:npm/estraverse@5.3.0
패키지
심벌
  • estraverse.Syntax
생성일
2026-08-23T14:17:40Z

컨트랙트

  1. estraverse.Syntax is exported as an object mapping AST node type names to identical string constants
  2. Syntax defines core ESTree declarations and statements including Program, FunctionDeclaration, and VariableDeclaration
  3. Syntax defines core ESTree expressions and literals including BinaryExpression, CallExpression, MemberExpression, Identifier, and Literal
  4. Syntax defines modern ES6+ node types including ArrowFunctionExpression, ClassDeclaration, TemplateLiteral, and AwaitExpression
  5. Syntax constants match node.type values when traversing an AST with estraverse.traverse
  6. Syntax constants enable filtering and selective transformation of AST nodes with estraverse.replace

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 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.
csx.json
{"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"}
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
src/index.js
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
};
test/contract.mjs
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);
});

오리진 시더

익명