샘플
esquery 1.7.0: esquery
검증된 샘플 — npm esquery 1.7.0: esquery. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert esquery returns an array of matching AST nodes for a…
sha256:ba95d07a4e0b77ae68081a341836f82cf6d194a154e5064c03fcdb9408177bd5
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-26 |
케이스
HOW- 목표
- verify esquery in pkg:npm/esquery@1.7.0
- 패키지
- 심벌
-
- esquery
- 환경
- node 22.23.2
- 생성일
- 2026-08-26T11:16:11Z
컨트랙트
- assert esquery returns an array of matching AST nodes for a node type selector
- assert esquery returns matching AST nodes for attribute selectors
- assert esquery returns matching AST nodes for child and descendant selectors
- assert esquery.parse parses selector strings into attribute and compound selector ASTs
- assert esquery.match executes a pre-parsed selector AST against an AST
- assert esquery.query performs the same AST query as the main esquery function
- assert esquery returns an empty array when no AST nodes match the selector
파일
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- 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 esquery in pkg:npm/esquery@1.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/esquery@1.7.0
Demonstrate these symbols/APIs:
- esquery
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:a24f53beebf329a04033937986fc658ffade4986d4b88ee8348175dff3aab8fe","contract":["assert esquery returns an array of matching AST nodes for a node type selector","assert esquery returns matching AST nodes for attribute selectors","assert esquery returns matching AST nodes for child and descendant selectors","assert esquery.parse parses selector strings into attribute and compound selector ASTs","assert esquery.match executes a pre-parsed selector AST against an AST","assert esquery.query performs the same AST query as the main esquery function","assert esquery returns an empty array when no AST nodes match the selector"],"goal":"verify esquery in pkg:npm/esquery@1.7.0","kind":"HOW","packages":["pkg:npm/esquery@1.7.0"],"schemaVersion":1,"symbols":["esquery"]},"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/esquery@1.7.0"],"schemaVersion":1,"subject":"pkg:npm/esquery@1.7.0","symbols":["esquery"],"verifierAdapter":"node-typescript@1"}
const esquery = require('esquery');
/**
* Queries an AST using a selector string.
*
* @param {object} ast - The AST node or tree to query.
* @param {string} selector - The esquery selector string.
* @returns {Array<object>} Array of matching AST nodes.
*/
function queryAst(ast, selector) {
return esquery(ast, selector);
}
/**
* Parses an esquery selector into a selector AST and matches it against an AST.
*
* @param {object} ast - The AST node or tree to query.
* @param {string} selector - The esquery selector string.
* @returns {Array<object>} Array of matching AST nodes.
*/
function queryWithParsedSelector(ast, selector) {
const parsed = esquery.parse(selector);
return esquery.match(ast, parsed);
}
module.exports = {
queryAst,
queryWithParsedSelector,
esquery,
};
{
"name": "sample-esquery",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-esquery",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"esquery": "1.7.0"
}
},
"node_modules/esquery": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz",
"integrity": "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==",
"license": "BSD-3-Clause",
"dependencies": {
"estraverse": "^5.1.0"
},
"engines": {
"node": ">=0.10"
}
},
"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-esquery",
"version": "1.0.0",
"description": "Clean-room sample verifying esquery in pkg:npm/esquery@1.7.0",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"esquery": "1.7.0"
}
}
{
"schemaVersion": 1,
"goal": "verify esquery in pkg:npm/esquery@1.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/esquery@1.7.0"
],
"symbols": [
"esquery"
]
}
import assert from 'node:assert';
import esquery from 'esquery';
import { queryAst, queryWithParsedSelector } from '../index.js';
// Setup sample ESTree AST
const ast = {
type: 'Program',
body: [
{
type: 'VariableDeclaration',
kind: 'const',
declarations: [
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'count' },
init: { type: 'Literal', value: 10, raw: '10' }
}
]
},
{
type: 'FunctionDeclaration',
id: { type: 'Identifier', name: 'calculateTotal' },
params: [
{ type: 'Identifier', name: 'price' },
{ type: 'Identifier', name: 'tax' }
],
body: {
type: 'BlockStatement',
body: [
{
type: 'ReturnStatement',
argument: {
type: 'BinaryExpression',
operator: '+',
left: { type: 'Identifier', name: 'price' },
right: { type: 'Identifier', name: 'tax' }
}
}
]
}
}
]
};
// 1. esquery returns an array of matching nodes for a node type selector
const functionNodes = esquery(ast, 'FunctionDeclaration');
assert(Array.isArray(functionNodes), 'esquery must return an array');
assert.strictEqual(functionNodes.length, 1);
assert.strictEqual(functionNodes[0].id.name, 'calculateTotal');
const helperFunctionNodes = queryAst(ast, 'FunctionDeclaration');
assert.strictEqual(helperFunctionNodes.length, 1);
assert.strictEqual(helperFunctionNodes[0].id.name, 'calculateTotal');
// 2. esquery returns matching nodes for attribute selectors
const constDeclarations = esquery(ast, 'VariableDeclaration[kind="const"]');
assert.strictEqual(constDeclarations.length, 1);
assert.strictEqual(constDeclarations[0].kind, 'const');
const binaryPlus = esquery(ast, 'BinaryExpression[operator="+"]');
assert.strictEqual(binaryPlus.length, 1);
assert.strictEqual(binaryPlus[0].operator, '+');
// 3. esquery returns matching nodes for descendant and child selectors
const childIdentifiers = esquery(ast, 'FunctionDeclaration > Identifier');
assert.strictEqual(childIdentifiers.length, 3);
const returnStatements = esquery(ast, 'FunctionDeclaration ReturnStatement');
assert.strictEqual(returnStatements.length, 1);
assert.strictEqual(returnStatements[0].type, 'ReturnStatement');
// 4. esquery.parse parses selector string into a selector AST
const parsedAttributeSelector = esquery.parse('[name="price"]');
assert.strictEqual(typeof parsedAttributeSelector, 'object');
assert.strictEqual(parsedAttributeSelector.type, 'attribute');
assert.strictEqual(parsedAttributeSelector.name, 'name');
assert.strictEqual(parsedAttributeSelector.value.value, 'price');
const parsedCompoundSelector = esquery.parse('Identifier[name="price"]');
assert.strictEqual(parsedCompoundSelector.type, 'compound');
assert.strictEqual(parsedCompoundSelector.selectors.length, 2);
// 5. esquery.match executes a pre-parsed selector AST against an AST
const matchedNodes = esquery.match(ast, parsedCompoundSelector);
assert.strictEqual(matchedNodes.length, 2);
assert.strictEqual(matchedNodes[0].name, 'price');
assert.strictEqual(matchedNodes[1].name, 'price');
const helperMatchedNodes = queryWithParsedSelector(ast, 'Identifier[name="price"]');
assert.strictEqual(helperMatchedNodes.length, 2);
assert.strictEqual(helperMatchedNodes[0].name, 'price');
assert.strictEqual(helperMatchedNodes[1].name, 'price');
// 6. esquery.query performs the same query as the main esquery function
const queriedNodes = esquery.query(ast, 'VariableDeclarator');
assert.strictEqual(queriedNodes.length, 1);
assert.strictEqual(queriedNodes[0].id.name, 'count');
// 7. esquery returns empty array when no AST nodes match selector
const unmatchedNodes = esquery(ast, 'ClassDeclaration');
assert(Array.isArray(unmatchedNodes), 'esquery must return an array when nothing matches');
assert.strictEqual(unmatchedNodes.length, 0);
console.log('All esquery contract assertions passed.');
오리진 시더
익명