サンプル
acorn 8.18.0: TokenType
検証済みサンプル — npm acorn 8.18.0: TokenType. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert TokenType instantiates custom token types with…
sha256:93055e5c6eaabc3f18625780fc1f2838b38b38695eea1288cd5d28ca405be97f
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 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 |
| 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 acorn.TokenType in pkg:npm/acorn@8.18.0
- パッケージ
- シンボル
-
- acorn.TokenType
- 環境
- node 22.23.2
- 作成日
- 2026-08-26T11:02:47Z
コントラクト
- assert TokenType instantiates custom token types with configuration flags
- assert tokTypes properties are instances of TokenType with correct metadata
- assert tokenizer emits tokens whose type is an instance of TokenType matching language constructs
- assert TokenType flags distinguish keywords, operators, assignment, and loop constructs
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
ソース
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 acorn.TokenType in pkg:npm/acorn@8.18.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/acorn@8.18.0
Demonstrate these symbols/APIs:
- acorn.TokenType
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:5a8c49c6f486df7256f595bb5a19e23da7f56678de9a6c5be4232d955ad993ca","constraints":{"executionContext":"node"},"contract":["assert TokenType instantiates custom token types with configuration flags","assert tokTypes properties are instances of TokenType with correct metadata","assert tokenizer emits tokens whose type is an instance of TokenType matching language constructs","assert TokenType flags distinguish keywords, operators, assignment, and loop constructs"],"goal":"verify acorn.TokenType in pkg:npm/acorn@8.18.0","kind":"HOW","packages":["pkg:npm/acorn@8.18.0"],"schemaVersion":1,"symbols":["acorn.TokenType"]},"contractCommand":["node","test/contract.js"],"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/acorn@8.18.0"],"schemaVersion":1,"subject":"pkg:npm/acorn@8.18.0","symbols":["acorn.TokenType"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-acorn-tokentype",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-acorn-tokentype",
"version": "1.0.0",
"dependencies": {
"acorn": "8.18.0"
}
},
"node_modules/acorn": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz",
"integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==",
"license": "MIT",
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
}
}
}
{
"name": "sample-acorn-tokentype",
"version": "1.0.0",
"private": true,
"dependencies": {
"acorn": "8.18.0"
}
}
{
"schemaVersion": 1,
"goal": "verify acorn.TokenType in pkg:npm/acorn@8.18.0",
"kind": "HOW",
"packages": [
"pkg:npm/acorn@8.18.0"
],
"symbols": [
"acorn.TokenType"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const acorn = require("acorn");
/**
* Creates a custom TokenType with label and configuration flags.
* @param {string} label
* @param {object} [conf]
* @returns {acorn.TokenType}
*/
function createTokenType(label, conf = {}) {
return new acorn.TokenType(label, conf);
}
/**
* Checks whether an object is an instance of acorn.TokenType.
* @param {any} value
* @returns {boolean}
*/
function isTokenType(value) {
return value instanceof acorn.TokenType;
}
/**
* Tokenizes a string of JavaScript code and extracts token details.
* @param {string} code
* @param {object} [options]
* @returns {Array<{type: acorn.TokenType, label: string, value: any, start: number, end: number}>}
*/
function extractTokens(code, options = { ecmaVersion: 2020 }) {
const tokenizer = acorn.tokenizer(code, options);
const tokens = [];
let token = tokenizer.getToken();
while (token.type !== acorn.tokTypes.eof) {
tokens.push({
type: token.type,
label: token.type.label,
value: token.value,
start: token.start,
end: token.end,
});
token = tokenizer.getToken();
}
return tokens;
}
module.exports = {
createTokenType,
isTokenType,
extractTokens,
TokenType: acorn.TokenType,
tokTypes: acorn.tokTypes,
};
const assert = require("node:assert");
const {
createTokenType,
isTokenType,
extractTokens,
TokenType,
tokTypes,
} = require("../src/index.js");
// 1. Assert TokenType instantiates custom token types with configuration flags
const customType = createTokenType("customOp", {
beforeExpr: true,
startsExpr: false,
isAssign: false,
isLoop: false,
binop: 7,
});
assert(isTokenType(customType), "customType must be an instance of TokenType");
assert(customType instanceof TokenType, "customType must be an instance of acorn.TokenType");
assert.strictEqual(customType.label, "customOp");
assert.strictEqual(customType.beforeExpr, true);
assert.strictEqual(customType.startsExpr, false);
assert.strictEqual(customType.binop, 7);
assert.strictEqual(customType.isAssign, false);
assert.strictEqual(customType.isLoop, false);
// 2. Assert tokTypes properties are instances of TokenType with correct metadata
assert(isTokenType(tokTypes.name), "tokTypes.name must be an instance of TokenType");
assert(isTokenType(tokTypes.num), "tokTypes.num must be an instance of TokenType");
assert(isTokenType(tokTypes.string), "tokTypes.string must be an instance of TokenType");
assert(isTokenType(tokTypes._if), "tokTypes._if must be an instance of TokenType");
assert(isTokenType(tokTypes._while), "tokTypes._while must be an instance of TokenType");
assert(isTokenType(tokTypes.eq), "tokTypes.eq must be an instance of TokenType");
assert(isTokenType(tokTypes.plusMin), "tokTypes.plusMin must be an instance of TokenType");
assert(isTokenType(tokTypes.eof), "tokTypes.eof must be an instance of TokenType");
assert.strictEqual(tokTypes.name.label, "name");
assert.strictEqual(tokTypes.num.label, "num");
assert.strictEqual(tokTypes.string.label, "string");
assert.strictEqual(tokTypes._if.label, "if");
assert.strictEqual(tokTypes._if.keyword, "if");
// 3. Assert tokenizer emits tokens whose type is an instance of TokenType matching language constructs
const code = "const total = 42 + 8;";
const tokens = extractTokens(code, { ecmaVersion: 2020 });
assert(Array.isArray(tokens) && tokens.length === 7, "should extract 7 tokens before EOF");
assert.strictEqual(tokens[0].type, tokTypes._const);
assert(isTokenType(tokens[0].type), "token 0 type must be a TokenType");
assert.strictEqual(tokens[0].label, "const");
assert.strictEqual(tokens[1].type, tokTypes.name);
assert.strictEqual(tokens[1].value, "total");
assert.strictEqual(tokens[2].type, tokTypes.eq);
assert.strictEqual(tokens[2].label, "=");
assert.strictEqual(tokens[3].type, tokTypes.num);
assert.strictEqual(tokens[3].value, 42);
assert.strictEqual(tokens[4].type, tokTypes.plusMin);
assert.strictEqual(tokens[4].label, "+/-");
assert.strictEqual(tokens[4].value, "+");
assert.strictEqual(tokens[5].type, tokTypes.num);
assert.strictEqual(tokens[5].value, 8);
assert.strictEqual(tokens[6].type, tokTypes.semi);
assert.strictEqual(tokens[6].label, ";");
// 4. Assert TokenType flags distinguish keywords, operators, assignment, and loop constructs
assert.strictEqual(tokTypes._while.isLoop, true, "while token type must have isLoop=true");
assert.strictEqual(tokTypes._for.isLoop, true, "for token type must have isLoop=true");
assert.strictEqual(tokTypes._if.isLoop, false, "if token type must have isLoop=false");
assert.strictEqual(tokTypes.eq.isAssign, true, "eq token type must have isAssign=true");
assert.strictEqual(tokTypes.plusMin.isAssign, false, "plusMin token type must have isAssign=false");
assert.strictEqual(typeof tokTypes.plusMin.binop, "number", "plusMin must have a numeric binop precedence");
assert.strictEqual(tokTypes.plusMin.binop, 9, "plusMin binary precedence should be 9");
assert.strictEqual(tokTypes.name.binop, null, "name must have null binop");
assert.strictEqual(tokTypes._return.beforeExpr, true, "return keyword must have beforeExpr=true");
assert.strictEqual(tokTypes.incDec.prefix, true, "incDec must support prefix");
assert.strictEqual(tokTypes.incDec.postfix, true, "incDec must support postfix");
console.log("PASS: acorn.TokenType contract assertions verified");
オリジンシーダー
匿名