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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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');

オリジンシーダー

匿名