CodeSampleX

Ejemplo

@typescript-eslint/types 8.69.0: AST_TOKEN_TYPES

Muestra verificada para npm @typescript-eslint/types 8.69.0: AST_TOKEN_TYPES. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:385662e542f26a1bbf4004bfad7acdf834d34cf546c118a8d0999a247b04881a

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-10-11

Caso

HOW
Objetivo
verify @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.69.0
Paquetes
Símbolos
  • @typescript-eslint/types.AST_TOKEN_TYPES
Entorno
node 22.23.2
Creado
2026-10-11T17:29:27Z

Contrato

  1. AST_TOKEN_TYPES provides canonical string enum mappings for tokenizer token types including Boolean, Identifier, JSXIdentifier, JSXText, Keyword, Null, Numeric, Punctuator, RegularExpression, String, Template, Block, Line, and PrivateIdentifier
  2. isCommentToken utility identifies comment tokens using AST_TOKEN_TYPES Block and Line definitions
  3. isLiteralToken utility classifies literal values using AST_TOKEN_TYPES Boolean, Null, Numeric, String, and RegularExpression
  4. isIdentifierToken utility categorizes identifier tokens using AST_TOKEN_TYPES Identifier, JSXIdentifier, and PrivateIdentifier
  5. classifyToken categorizes tokens into structural groups based on AST_TOKEN_TYPES
  6. isValidTokenType and getTokenTypeName validate known token type strings against AST_TOKEN_TYPES
  7. TSESTree namespace exports AST_TOKEN_TYPES with identical references to the top-level AST_TOKEN_TYPES export

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.69.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/types@8.69.0
Demonstrate these symbols/APIs:
  - @typescript-eslint/types.AST_TOKEN_TYPES

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:48fea730b19770f663f9eff614eabc73908f4a9e784d02e2708f4b10f34c6531","contract":["AST_TOKEN_TYPES provides canonical string enum mappings for tokenizer token types including Boolean, Identifier, JSXIdentifier, JSXText, Keyword, Null, Numeric, Punctuator, RegularExpression, String, Template, Block, Line, and PrivateIdentifier","isCommentToken utility identifies comment tokens using AST_TOKEN_TYPES Block and Line definitions","isLiteralToken utility classifies literal values using AST_TOKEN_TYPES Boolean, Null, Numeric, String, and RegularExpression","isIdentifierToken utility categorizes identifier tokens using AST_TOKEN_TYPES Identifier, JSXIdentifier, and PrivateIdentifier","classifyToken categorizes tokens into structural groups based on AST_TOKEN_TYPES","isValidTokenType and getTokenTypeName validate known token type strings against AST_TOKEN_TYPES","TSESTree namespace exports AST_TOKEN_TYPES with identical references to the top-level AST_TOKEN_TYPES export"],"goal":"verify @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.69.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/types@8.69.0"],"schemaVersion":1,"symbols":["@typescript-eslint/types.AST_TOKEN_TYPES"]},"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/%40typescript-eslint/types@8.69.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/types@8.69.0","symbols":["@typescript-eslint/types.AST_TOKEN_TYPES"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-typescript-eslint-types",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-typescript-eslint-types",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@typescript-eslint/types": "8.69.0"
      }
    },
    "node_modules/@typescript-eslint/types": {
      "version": "8.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.69.0.tgz",
      "integrity": "sha512-K3VrubUPhlo9VDBS6QdI8YB5j7ClpqLRdefcz6PFrhnwicehBweqQ9Evhl4l+FYz0HdDmMqIiSX0aldGRYtDCA==",
      "license": "MIT",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    }
  }
}
package.json
{
  "name": "sample-typescript-eslint-types",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @typescript-eslint/types AST_TOKEN_TYPES",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@typescript-eslint/types": "8.69.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.69.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/types@8.69.0"
  ],
  "symbols": [
    "@typescript-eslint/types.AST_TOKEN_TYPES"
  ]
}
src/index.js
const { AST_TOKEN_TYPES, TSESTree } = require('@typescript-eslint/types');

/**
 * All valid AST_TOKEN_TYPES string values.
 */
const VALID_TOKEN_TYPES = new Set(Object.values(AST_TOKEN_TYPES));

/**
 * Checks whether a value is a valid AST_TOKEN_TYPES token type string.
 *
 * @param {unknown} type - The token type candidate.
 * @returns {boolean} True if the type is a recognized AST_TOKEN_TYPES value.
 */
function isValidTokenType(type) {
  return typeof type === 'string' && VALID_TOKEN_TYPES.has(type);
}

/**
 * Resolves the canonical token type name for a given type name or value.
 *
 * @param {string} tokenType - The name or value of the token type.
 * @returns {string|null} The canonical token type or null if not found.
 */
function getTokenTypeName(tokenType) {
  if (typeof tokenType === 'string' && Object.prototype.hasOwnProperty.call(AST_TOKEN_TYPES, tokenType)) {
    return AST_TOKEN_TYPES[tokenType];
  }
  return null;
}

/**
 * Checks whether a token represents a comment (Block or Line).
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is a Block or Line comment.
 */
function isCommentToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return token.type === AST_TOKEN_TYPES.Block || token.type === AST_TOKEN_TYPES.Line;
}

/**
 * Checks whether a token represents a literal (Boolean, Null, Numeric, String, RegularExpression).
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is a literal.
 */
function isLiteralToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return (
    token.type === AST_TOKEN_TYPES.Boolean ||
    token.type === AST_TOKEN_TYPES.Null ||
    token.type === AST_TOKEN_TYPES.Numeric ||
    token.type === AST_TOKEN_TYPES.String ||
    token.type === AST_TOKEN_TYPES.RegularExpression
  );
}

/**
 * Checks whether a token represents an identifier (Identifier, JSXIdentifier, PrivateIdentifier).
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is an identifier token.
 */
function isIdentifierToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return (
    token.type === AST_TOKEN_TYPES.Identifier ||
    token.type === AST_TOKEN_TYPES.JSXIdentifier ||
    token.type === AST_TOKEN_TYPES.PrivateIdentifier
  );
}

/**
 * Checks whether a token represents a punctuator.
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is a punctuator token.
 */
function isPunctuatorToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return token.type === AST_TOKEN_TYPES.Punctuator;
}

/**
 * Checks whether a token represents a keyword.
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is a keyword token.
 */
function isKeywordToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return token.type === AST_TOKEN_TYPES.Keyword;
}

/**
 * Checks whether a token represents a template token.
 *
 * @param {object} token - The token object to inspect.
 * @returns {boolean} True if the token is a template token.
 */
function isTemplateToken(token) {
  if (!token || typeof token.type !== 'string') {
    return false;
  }
  return token.type === AST_TOKEN_TYPES.Template;
}

/**
 * Categorizes an AST token into high-level token families.
 *
 * @param {object} token - The token to categorize.
 * @returns {string} The category name.
 */
function classifyToken(token) {
  if (!token || typeof token.type !== 'string') {
    return 'unknown';
  }
  if (isCommentToken(token)) {
    return 'comment';
  }
  if (isLiteralToken(token)) {
    return 'literal';
  }
  if (isIdentifierToken(token)) {
    return 'identifier';
  }
  if (token.type === AST_TOKEN_TYPES.Punctuator) {
    return 'punctuator';
  }
  if (token.type === AST_TOKEN_TYPES.Keyword) {
    return 'keyword';
  }
  if (token.type === AST_TOKEN_TYPES.Template) {
    return 'template';
  }
  if (token.type === AST_TOKEN_TYPES.JSXText) {
    return 'jsx-text';
  }
  return 'unknown';
}

module.exports = {
  AST_TOKEN_TYPES,
  TSESTree,
  isValidTokenType,
  getTokenTypeName,
  isCommentToken,
  isLiteralToken,
  isIdentifierToken,
  isPunctuatorToken,
  isKeywordToken,
  isTemplateToken,
  classifyToken,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  AST_TOKEN_TYPES,
  TSESTree,
  isValidTokenType,
  getTokenTypeName,
  isCommentToken,
  isLiteralToken,
  isIdentifierToken,
  isPunctuatorToken,
  isKeywordToken,
  isTemplateToken,
  classifyToken,
} = require('../src/index.js');

async function runContract() {
  // 1. AST_TOKEN_TYPES provides canonical string enum mappings for tokenizer token types including Boolean, Identifier, JSXIdentifier, JSXText, Keyword, Null, Numeric, Punctuator, RegularExpression, String, Template, Block, Line, and PrivateIdentifier
  assert.strictEqual(typeof AST_TOKEN_TYPES, 'object');
  assert.strictEqual(AST_TOKEN_TYPES.Boolean, 'Boolean');
  assert.strictEqual(AST_TOKEN_TYPES.Identifier, 'Identifier');
  assert.strictEqual(AST_TOKEN_TYPES.JSXIdentifier, 'JSXIdentifier');
  assert.strictEqual(AST_TOKEN_TYPES.JSXText, 'JSXText');
  assert.strictEqual(AST_TOKEN_TYPES.Keyword, 'Keyword');
  assert.strictEqual(AST_TOKEN_TYPES.Null, 'Null');
  assert.strictEqual(AST_TOKEN_TYPES.Numeric, 'Numeric');
  assert.strictEqual(AST_TOKEN_TYPES.Punctuator, 'Punctuator');
  assert.strictEqual(AST_TOKEN_TYPES.RegularExpression, 'RegularExpression');
  assert.strictEqual(AST_TOKEN_TYPES.String, 'String');
  assert.strictEqual(AST_TOKEN_TYPES.Template, 'Template');
  assert.strictEqual(AST_TOKEN_TYPES.Block, 'Block');
  assert.strictEqual(AST_TOKEN_TYPES.Line, 'Line');
  assert.strictEqual(AST_TOKEN_TYPES.PrivateIdentifier, 'PrivateIdentifier');

  // Verify full set of known enum keys
  const expectedKeys = [
    'Block',
    'Boolean',
    'Identifier',
    'JSXIdentifier',
    'JSXText',
    'Keyword',
    'Line',
    'Null',
    'Numeric',
    'PrivateIdentifier',
    'Punctuator',
    'RegularExpression',
    'String',
    'Template',
  ];
  assert.deepStrictEqual(Object.keys(AST_TOKEN_TYPES).sort(), expectedKeys.sort());

  // 2. isCommentToken utility identifies comment tokens using AST_TOKEN_TYPES Block and Line definitions
  assert.strictEqual(isCommentToken({ type: AST_TOKEN_TYPES.Block, value: '/* comment */' }), true);
  assert.strictEqual(isCommentToken({ type: AST_TOKEN_TYPES.Line, value: '// line' }), true);
  assert.strictEqual(isCommentToken({ type: AST_TOKEN_TYPES.Keyword, value: 'function' }), false);
  assert.strictEqual(isCommentToken(null), false);
  assert.strictEqual(isCommentToken({}), false);

  // 3. isLiteralToken utility classifies literal values using AST_TOKEN_TYPES Boolean, Null, Numeric, String, and RegularExpression
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.Boolean, value: 'true' }), true);
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.Null, value: 'null' }), true);
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.Numeric, value: '123' }), true);
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.String, value: '"hello"' }), true);
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.RegularExpression, value: '/abc/' }), true);
  assert.strictEqual(isLiteralToken({ type: AST_TOKEN_TYPES.Identifier, value: 'foo' }), false);
  assert.strictEqual(isLiteralToken(null), false);

  // 4. isIdentifierToken utility categorizes identifier tokens using AST_TOKEN_TYPES Identifier, JSXIdentifier, and PrivateIdentifier
  assert.strictEqual(isIdentifierToken({ type: AST_TOKEN_TYPES.Identifier, value: 'myVar' }), true);
  assert.strictEqual(isIdentifierToken({ type: AST_TOKEN_TYPES.JSXIdentifier, value: 'Component' }), true);
  assert.strictEqual(isIdentifierToken({ type: AST_TOKEN_TYPES.PrivateIdentifier, value: '#field' }), true);
  assert.strictEqual(isIdentifierToken({ type: AST_TOKEN_TYPES.Punctuator, value: '.' }), false);

  // 5. classifyToken categorizes tokens into structural groups based on AST_TOKEN_TYPES
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Line, value: '//' }), 'comment');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Numeric, value: '42' }), 'literal');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Identifier, value: 'name' }), 'identifier');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Punctuator, value: ';' }), 'punctuator');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Keyword, value: 'const' }), 'keyword');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.Template, value: '`text`' }), 'template');
  assert.strictEqual(classifyToken({ type: AST_TOKEN_TYPES.JSXText, value: 'hello' }), 'jsx-text');
  assert.strictEqual(classifyToken({ type: 'UnknownType' }), 'unknown');
  assert.strictEqual(classifyToken(null), 'unknown');

  // 6. isValidTokenType and getTokenTypeName validate known token type strings against AST_TOKEN_TYPES
  assert.strictEqual(isValidTokenType(AST_TOKEN_TYPES.Keyword), true);
  assert.strictEqual(isValidTokenType(AST_TOKEN_TYPES.PrivateIdentifier), true);
  assert.strictEqual(isValidTokenType('InvalidTokenType'), false);
  assert.strictEqual(isValidTokenType(123), false);
  assert.strictEqual(getTokenTypeName('Keyword'), 'Keyword');
  assert.strictEqual(getTokenTypeName('PrivateIdentifier'), 'PrivateIdentifier');
  assert.strictEqual(getTokenTypeName('NonExistent'), null);

  // 7. TSESTree namespace exports AST_TOKEN_TYPES with identical references to the top-level AST_TOKEN_TYPES export
  assert.strictEqual(typeof TSESTree, 'object');
  assert.strictEqual(TSESTree.AST_TOKEN_TYPES, AST_TOKEN_TYPES);
  assert.strictEqual(TSESTree.AST_TOKEN_TYPES.Punctuator, 'Punctuator');

  console.log('AST_TOKEN_TYPES contract assertions passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder de origen

anónimo