示例
estraverse 5.3.0: Syntax
已验证示例 — npm estraverse 5.3.0: Syntax. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: estraverse.Syntax is exported as an object mapping AST node type…
sha256:84e59534797ec511bf4e7172c83bc1be568a206b8e25e1c3fe9b3450cdba2332
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
源代码
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);
});
原始种子者
匿名