CodeSampleX

Exemplo

@typescript-eslint/types 8.65.0: AST_TOKEN_TYPES

Amostra verificada para npm @typescript-eslint/types 8.65.0: AST_TOKEN_TYPES. O contrato rodou em node 22 · linux debian/x64 · docker e passou.

sha256:ebeedc5366b39b2b64c26f544275257c827db05250443866a93d05d651bf83bf

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.65.0
Pacotes
Símbolos
  • @typescript-eslint/types.AST_TOKEN_TYPES
Ambiente
node 22.23.2
Criado
2026-09-05T15:48:21Z

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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.65.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/types@8.65.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:44b5439b6e42ca2c7542fabc342aa084197e5d2ec1a65253219bbe6b48f8154c","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.65.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/types@8.65.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.65.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/types@8.65.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.65.0"
      }
    },
    "node_modules/@typescript-eslint/types": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz",
      "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==",
      "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.65.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/types.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/types@8.65.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/types@8.65.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 origem

anônimo