CodeSampleX

Sample

acorn 8.14.0

Verified sample for npm acorn 8.14.0. The contract ran on node 22 · linux debian/x64 · docker and passed: acorn.tokenizer returns an iterable token stream…

sha256:499571eeb96d172dc2130845ec892d057ae403b8c521af1b9183506d82ca351d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:npm/acorn@8.14.0
Packages
Environment
node 22.23.2
Created
2026-09-05T10:36:56Z

Contract

  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

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

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.');

Origin Seeder

anonymous