CodeSampleX

샘플

ts-api-utils 2.5.0

검증된 샘플 — npm ts-api-utils 2.5.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: forEachToken iterates through all AST tokens of a TypeScript…

sha256:d3fa43248180460dc5624f8192e3fd3c5c730f7c726ee4547f4194b27fe879d2

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
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@1
2026-08-21

케이스

HOW
목표
verify pkg:npm/ts-api-utils@2.5.0
패키지
생성일
2026-08-21T07:20:43Z

컨트랙트

  1. forEachToken iterates through all AST tokens of a TypeScript source file
  2. forEachComment extracts leading and trailing comments from AST nodes
  3. collectVariableUsage analyzes identifiers, declarations, and usages across scopes
  4. isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/ts-api-utils@2.5.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ts-api-utils@2.5.0

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:ce718eea4691a5dfaab43c2d46da5498e31266e0a3ea41423f84d3b811659a11","contract":["forEachToken iterates through all AST tokens of a TypeScript source file","forEachComment extracts leading and trailing comments from AST nodes","collectVariableUsage analyzes identifiers, declarations, and usages across scopes","isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags"],"goal":"verify pkg:npm/ts-api-utils@2.5.0","kind":"HOW","packages":["pkg:npm/ts-api-utils@2.5.0"],"schemaVersion":1},"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/ts-api-utils@2.5.0"],"schemaVersion":1,"subject":"pkg:npm/ts-api-utils@2.5.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ts-api-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ts-api-utils",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ts-api-utils": "2.5.0",
        "typescript": "5.7.3"
      }
    },
    "node_modules/ts-api-utils": {
      "version": "2.5.0",
      "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz",
      "integrity": "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA==",
      "license": "MIT",
      "engines": {
        "node": ">=18.12"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4"
      }
    },
    "node_modules/typescript": {
      "version": "5.7.3",
      "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
      "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
      "license": "Apache-2.0",
      "bin": {
        "tsc": "bin/tsc",
        "tsserver": "bin/tsserver"
      },
      "engines": {
        "node": ">=14.17"
      }
    }
  }
}
package.json
{
  "name": "sample-ts-api-utils",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "ts-api-utils": "2.5.0",
    "typescript": "5.7.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ts-api-utils@2.5.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ts-api-utils@2.5.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as tsutils from 'ts-api-utils';
import ts from 'typescript';

// 1. forEachToken iterates through all AST tokens of a TypeScript source file
const sourceCode1 = 'const x: number = 42;';
const sourceFile1 = ts.createSourceFile('example.ts', sourceCode1, ts.ScriptTarget.Latest, true);
const tokens = [];
tsutils.forEachToken(sourceFile1, (token) => {
  tokens.push(ts.tokenToString(token.kind) || token.getText(sourceFile1));
});
assert.ok(tokens.includes('const'), 'tokens should contain const');
assert.ok(tokens.includes('x'), 'tokens should contain x');
assert.ok(tokens.includes('number'), 'tokens should contain number');
assert.ok(tokens.includes('42'), 'tokens should contain 42');

// 2. forEachComment extracts leading and trailing comments from AST nodes
const sourceCode2 = '// leading comment\nconst a = 1; /* trailing block */';
const sourceFile2 = ts.createSourceFile('comment.ts', sourceCode2, ts.ScriptTarget.Latest, true);
const comments = [];
tsutils.forEachComment(sourceFile2, (fullText, comment) => {
  comments.push(fullText.slice(comment.pos, comment.end));
});
assert.equal(comments.length, 2, 'should find exactly two comments');
assert.equal(comments[0], '// leading comment');
assert.equal(comments[1], '/* trailing block */');

// 3. collectVariableUsage analyzes identifiers, declarations, and usages across scopes
const sourceCode3 = 'const val = 10; function compute() { return val + 5; }';
const sourceFile3 = ts.createSourceFile('usage.ts', sourceCode3, ts.ScriptTarget.Latest, true);
const usageMap = tsutils.collectVariableUsage(sourceFile3);
const valEntry = Array.from(usageMap.entries()).find(([ident]) => ident.text === 'val');
assert.ok(valEntry, 'val should be tracked in variable usage map');
assert.equal(valEntry[1].declarations.length, 1, 'val should have 1 declaration');
assert.equal(valEntry[1].uses.length, 1, 'val should have 1 use');

// 4. isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags
const stmtConst = sourceFile3.statements[0];
const stmtFn = sourceFile3.statements[1];
assert.equal(tsutils.isNodeFlagSet(stmtConst.declarationList, ts.NodeFlags.Const), true, 'stmtConst should have Const flag');
assert.equal(tsutils.isFunctionLikeDeclaration(stmtFn), true, 'stmtFn should be function-like declaration');
assert.equal(tsutils.isFunctionLikeDeclaration(stmtConst), false, 'stmtConst should not be function-like declaration');

오리진 시더

익명