CodeSampleX

샘플

acorn 8.14.0

검증된 샘플 — npm acorn 8.14.0. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: acorn.tokenizer returns an iterable token stream for valid JavaScript…

sha256:499571eeb96d172dc2130845ec892d057ae403b8c521af1b9183506d82ca351d

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-05

케이스

HOW
목표
verify pkg:npm/acorn@8.14.0
패키지
환경
node 22.23.2
생성일
2026-09-05T10:36:56Z

컨트랙트

  1. acorn.tokenizer returns an iterable token stream for valid JavaScript source code
  2. acorn.tokenizer yields Token objects with type, value, start, and end offsets
  3. acorn.tokenizer attaches source locations and ranges when locations and ranges options are enabled
  4. acorn.tokenizer getToken returns an eof token when the input stream is exhausted
  5. acorn.tokenizer supports onToken and onComment callbacks during tokenization
  6. acorn.tokenizer throws SyntaxError with position and location metadata on invalid syntax

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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/acorn@8.14.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/acorn@8.14.0
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.
csx.json
{"case":{"caseId":"case:sha256:61c775b3f77b7e532be2a2fa710174ba22a6571f2037c643b257ef5dd27e52b3","constraints":{"executionContext":"node"},"contract":["acorn.tokenizer returns an iterable token stream for valid JavaScript source code","acorn.tokenizer yields Token objects with type, value, start, and end offsets","acorn.tokenizer attaches source locations and ranges when locations and ranges options are enabled","acorn.tokenizer getToken returns an eof token when the input stream is exhausted","acorn.tokenizer supports onToken and onComment callbacks during tokenization","acorn.tokenizer throws SyntaxError with position and location metadata on invalid syntax"],"goal":"verify pkg:npm/acorn@8.14.0","kind":"HOW","packages":["pkg:npm/acorn@8.14.0"],"schemaVersion":1},"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/acorn@8.14.0"],"schemaVersion":1,"subject":"pkg:npm/acorn@8.14.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-acorn",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-acorn",
      "version": "1.0.0",
      "dependencies": {
        "acorn": "8.14.0"
      }
    },
    "node_modules/acorn": {
      "version": "8.14.0",
      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
      "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
      "license": "MIT",
      "bin": {
        "acorn": "bin/acorn"
      },
      "engines": {
        "node": ">=0.4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-acorn",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of acorn tokenizer",
  "main": "src/index.js",
  "dependencies": {
    "acorn": "8.14.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/acorn@8.14.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/acorn@8.14.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const acorn = require('acorn');

/**
 * Create a tokenizer instance for JavaScript source code.
 * @param {string} code - JavaScript source code
 * @param {object} [options] - Acorn tokenizer options
 * @returns {object} Acorn tokenizer instance
 */
function createTokenizer(code, options = {}) {
  const defaultOptions = {
    ecmaVersion: 2020
  };
  return acorn.tokenizer(code, { ...defaultOptions, ...options });
}

/**
 * Tokenize JavaScript source code into an array of tokens.
 * @param {string} code - JavaScript source code
 * @param {object} [options] - Acorn tokenizer options
 * @returns {Array<object>} Array of tokens
 */
function tokenize(code, options = {}) {
  const tokenizer = createTokenizer(code, options);
  const tokens = [];
  for (const token of tokenizer) {
    tokens.push(token);
  }
  return tokens;
}

module.exports = {
  acorn,
  createTokenizer,
  tokenize
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { acorn, createTokenizer, tokenize } = require('../src/index.js');

// 1. Export verification
assert.strictEqual(typeof acorn.tokenizer, 'function', 'acorn.tokenizer should be a function');
assert.strictEqual(typeof acorn.tokTypes, 'object', 'acorn.tokTypes should be an object');
assert.strictEqual(typeof createTokenizer, 'function', 'createTokenizer should be a function');
assert.strictEqual(typeof tokenize, 'function', 'tokenize should be a function');

// 2. acorn.tokenizer returns an iterable token stream for valid JavaScript source code
const code = 'const answer = 42;';
const tokenizer = createTokenizer(code);
assert.strictEqual(typeof tokenizer[Symbol.iterator], 'function', 'tokenizer should be iterable');

// 3. acorn.tokenizer yields Token objects with type, value, start, and end offsets
const tokens = tokenize(code);
assert.strictEqual(tokens.length, 5, 'Should yield 5 tokens including semicolon');
assert.strictEqual(tokens[0].type.label, 'const');
assert.strictEqual(tokens[0].start, 0);
assert.strictEqual(tokens[0].end, 5);

assert.strictEqual(tokens[1].type.label, 'name');
assert.strictEqual(tokens[1].value, 'answer');
assert.strictEqual(tokens[1].start, 6);
assert.strictEqual(tokens[1].end, 12);

assert.strictEqual(tokens[2].type.label, '=');
assert.strictEqual(tokens[2].start, 13);
assert.strictEqual(tokens[2].end, 14);

assert.strictEqual(tokens[3].type.label, 'num');
assert.strictEqual(tokens[3].value, 42);
assert.strictEqual(tokens[3].start, 15);
assert.strictEqual(tokens[3].end, 17);

assert.strictEqual(tokens[4].type.label, ';');
assert.strictEqual(tokens[4].start, 17);
assert.strictEqual(tokens[4].end, 18);

// 4. acorn.tokenizer attaches source locations and ranges when locations and ranges options are enabled
const codeLoc = 'const x = 1;\nconst y = 2;';
const locTokens = tokenize(codeLoc, { locations: true, ranges: true });
assert(locTokens[0].loc !== undefined, 'Token should contain line/column location metadata');
assert.strictEqual(locTokens[0].loc.start.line, 1);
assert.strictEqual(locTokens[0].loc.start.column, 0);
assert.deepStrictEqual(locTokens[0].range, [0, 5]);

const secondLineToken = locTokens[5];
assert.strictEqual(secondLineToken.type.label, 'const');
assert.strictEqual(secondLineToken.loc.start.line, 2);
assert.strictEqual(secondLineToken.loc.start.column, 0);

// 5. acorn.tokenizer getToken returns an eof token when the input stream is exhausted
const manualTokenizer = createTokenizer('var z = 1;');
let t = manualTokenizer.getToken();
assert.strictEqual(t.type.label, 'var');
t = manualTokenizer.getToken();
assert.strictEqual(t.type.label, 'name');
t = manualTokenizer.getToken();
assert.strictEqual(t.type.label, '=');
t = manualTokenizer.getToken();
assert.strictEqual(t.type.label, 'num');
t = manualTokenizer.getToken();
assert.strictEqual(t.type.label, ';');
const eofToken = manualTokenizer.getToken();
assert.strictEqual(eofToken.type, acorn.tokTypes.eof, 'getToken after stream end should return eof token');
assert.strictEqual(eofToken.type.label, 'eof');

// 6. acorn.tokenizer supports onToken and onComment callbacks during tokenization
const tokensList = [];
const commentsList = [];
const callbackCode = 'const val = 10; // trailing comment';
tokenize(callbackCode, {
  onToken: tokensList,
  onComment: commentsList
});
assert(tokensList.length >= 5, 'onToken should record extracted tokens');
assert.strictEqual(commentsList.length, 1, 'onComment should record parsed comments');
assert.strictEqual(commentsList[0].type, 'Line');
assert.strictEqual(commentsList[0].value.trim(), 'trailing comment');

// 7. acorn.tokenizer throws SyntaxError with position and location metadata on invalid syntax
let errorThrown = false;
try {
  tokenize('const #invalid = 1;');
} catch (err) {
  errorThrown = true;
  assert(err instanceof SyntaxError, 'Should throw SyntaxError on invalid syntax');
  assert.strictEqual(err.pos, 6, 'SyntaxError should contain pos offset');
  assert.strictEqual(err.loc.line, 1, 'SyntaxError should contain loc line');
  assert.strictEqual(err.loc.column, 6, 'SyntaxError should contain loc column');
}
assert.strictEqual(errorThrown, true, 'Invalid syntax must throw SyntaxError');

console.log('Acorn tokenizer contract tests passed successfully.');

오리진 시더

익명