CodeSampleX

Exemplo

@typescript-eslint/types 8.65.0: AST_NODE_TYPES

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

sha256:11c8e57b47a402fbcd02dde9335da639c935cfe5cf46b2639130529b8b3504d0

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_NODE_TYPES in pkg:npm/%40typescript-eslint/types@8.65.0
Pacotes
Símbolos
  • @typescript-eslint/types.AST_NODE_TYPES
Ambiente
node 22.23.2
Criado
2026-09-05T14:20:24Z

Contrato

  1. AST_NODE_TYPES provides canonical string enum mappings for standard ECMAScript AST node types including Identifier, Literal, Program, FunctionDeclaration, and ReturnStatement
  2. AST_NODE_TYPES provides canonical string enum mappings for TypeScript-specific AST node types including TSInterfaceDeclaration, TSTypeAliasDeclaration, TSTypeAnnotation, and TSTypeReference
  3. AST_NODE_TYPES provides canonical string enum mappings for JSX AST node types including JSXElement, JSXAttribute, and JSXOpeningElement
  4. isValidNodeType validates arbitrary strings against known AST_NODE_TYPES enum members
  5. getNodeTypeCategory categorizes AST_NODE_TYPES members into typescript, jsx, declaration, statement, and expression categories
  6. isTypeDeclarationNode identifies TypeScript type and interface declarations using AST_NODE_TYPES

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_NODE_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_NODE_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:0e5e37976175e14a6d20e7c54b978f2445eb9a2b03ebd5253b62a5bb83359539","contract":["AST_NODE_TYPES provides canonical string enum mappings for standard ECMAScript AST node types including Identifier, Literal, Program, FunctionDeclaration, and ReturnStatement","AST_NODE_TYPES provides canonical string enum mappings for TypeScript-specific AST node types including TSInterfaceDeclaration, TSTypeAliasDeclaration, TSTypeAnnotation, and TSTypeReference","AST_NODE_TYPES provides canonical string enum mappings for JSX AST node types including JSXElement, JSXAttribute, and JSXOpeningElement","isValidNodeType validates arbitrary strings against known AST_NODE_TYPES enum members","getNodeTypeCategory categorizes AST_NODE_TYPES members into typescript, jsx, declaration, statement, and expression categories","isTypeDeclarationNode identifies TypeScript type and interface declarations using AST_NODE_TYPES"],"goal":"verify @typescript-eslint/types.AST_NODE_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_NODE_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_NODE_TYPES"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-typescript-eslint-types-ast-node-types",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-typescript-eslint-types-ast-node-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-ast-node-types",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @typescript-eslint/types AST_NODE_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_NODE_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_NODE_TYPES"
  ]
}
src/index.js
const { AST_NODE_TYPES } = require('@typescript-eslint/types');

/**
 * Validates whether the given string is a known member of AST_NODE_TYPES.
 *
 * @param {string} typeName - The candidate node type name.
 * @returns {boolean} True if typeName exists in AST_NODE_TYPES.
 */
function isValidNodeType(typeName) {
  if (typeof typeName !== 'string') {
    return false;
  }
  return Object.prototype.hasOwnProperty.call(AST_NODE_TYPES, typeName);
}

/**
 * Categorizes an AST node type into a major syntactic group.
 *
 * @param {string} nodeType - The AST node type string to categorize.
 * @returns {string} One of 'statement', 'expression', 'declaration', 'typescript', 'jsx', 'other', or 'unknown'.
 */
function getNodeTypeCategory(nodeType) {
  if (typeof nodeType !== 'string' || !isValidNodeType(nodeType)) {
    return 'unknown';
  }

  if (nodeType.startsWith('TS')) {
    return 'typescript';
  }

  if (nodeType.startsWith('JSX')) {
    return 'jsx';
  }

  if (nodeType.endsWith('Declaration')) {
    return 'declaration';
  }

  if (nodeType.endsWith('Statement')) {
    return 'statement';
  }

  if (nodeType.endsWith('Expression') || nodeType.endsWith('Literal') || nodeType === AST_NODE_TYPES.Identifier) {
    return 'expression';
  }

  return 'other';
}

/**
 * Checks if a given AST node is a TypeScript type declaration node.
 *
 * @param {object} node - The AST node to check.
 * @returns {boolean} True if the node represents a TypeScript interface or type alias declaration.
 */
function isTypeDeclarationNode(node) {
  if (!node || typeof node.type !== 'string') {
    return false;
  }
  return (
    node.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
    node.type === AST_NODE_TYPES.TSTypeAliasDeclaration ||
    node.type === AST_NODE_TYPES.TSEnumDeclaration ||
    node.type === AST_NODE_TYPES.TSModuleDeclaration
  );
}

module.exports = {
  AST_NODE_TYPES,
  getNodeTypeCategory,
  isTypeDeclarationNode,
  isValidNodeType,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  AST_NODE_TYPES,
  getNodeTypeCategory,
  isTypeDeclarationNode,
  isValidNodeType,
} = require('../src/index.js');

async function runContract() {
  // 1. AST_NODE_TYPES provides canonical string enum mappings for standard ECMAScript AST node types
  assert.strictEqual(typeof AST_NODE_TYPES, 'object');
  assert.strictEqual(AST_NODE_TYPES.Identifier, 'Identifier');
  assert.strictEqual(AST_NODE_TYPES.Literal, 'Literal');
  assert.strictEqual(AST_NODE_TYPES.Program, 'Program');
  assert.strictEqual(AST_NODE_TYPES.FunctionDeclaration, 'FunctionDeclaration');
  assert.strictEqual(AST_NODE_TYPES.VariableDeclaration, 'VariableDeclaration');
  assert.strictEqual(AST_NODE_TYPES.BinaryExpression, 'BinaryExpression');
  assert.strictEqual(AST_NODE_TYPES.ReturnStatement, 'ReturnStatement');

  // 2. AST_NODE_TYPES provides canonical string enum mappings for TypeScript-specific AST node types
  assert.strictEqual(AST_NODE_TYPES.TSInterfaceDeclaration, 'TSInterfaceDeclaration');
  assert.strictEqual(AST_NODE_TYPES.TSTypeAliasDeclaration, 'TSTypeAliasDeclaration');
  assert.strictEqual(AST_NODE_TYPES.TSTypeAnnotation, 'TSTypeAnnotation');
  assert.strictEqual(AST_NODE_TYPES.TSTypeReference, 'TSTypeReference');
  assert.strictEqual(AST_NODE_TYPES.TSUnionType, 'TSUnionType');
  assert.strictEqual(AST_NODE_TYPES.TSIntersectionType, 'TSIntersectionType');
  assert.strictEqual(AST_NODE_TYPES.TSAsExpression, 'TSAsExpression');

  // 3. AST_NODE_TYPES provides canonical string enum mappings for JSX AST node types
  assert.strictEqual(AST_NODE_TYPES.JSXElement, 'JSXElement');
  assert.strictEqual(AST_NODE_TYPES.JSXAttribute, 'JSXAttribute');
  assert.strictEqual(AST_NODE_TYPES.JSXOpeningElement, 'JSXOpeningElement');
  assert.strictEqual(AST_NODE_TYPES.JSXClosingElement, 'JSXClosingElement');
  assert.strictEqual(AST_NODE_TYPES.JSXIdentifier, 'JSXIdentifier');

  // 4. isValidNodeType validates arbitrary strings against known AST_NODE_TYPES enum members
  assert.strictEqual(isValidNodeType('Identifier'), true);
  assert.strictEqual(isValidNodeType('TSInterfaceDeclaration'), true);
  assert.strictEqual(isValidNodeType('JSXElement'), true);
  assert.strictEqual(isValidNodeType('NonExistentNodeType'), false);
  assert.strictEqual(isValidNodeType(''), false);
  assert.strictEqual(isValidNodeType(null), false);
  assert.strictEqual(isValidNodeType(undefined), false);

  // 5. getNodeTypeCategory categorizes AST_NODE_TYPES into typescript, jsx, declaration, statement, expression, and other
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.TSInterfaceDeclaration), 'typescript');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.TSTypeReference), 'typescript');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.JSXElement), 'jsx');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.JSXAttribute), 'jsx');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.FunctionDeclaration), 'declaration');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.VariableDeclaration), 'declaration');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.ReturnStatement), 'statement');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.IfStatement), 'statement');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.BinaryExpression), 'expression');
  assert.strictEqual(getNodeTypeCategory(AST_NODE_TYPES.Identifier), 'expression');
  assert.strictEqual(getNodeTypeCategory('UnknownNode'), 'unknown');

  // 6. isTypeDeclarationNode identifies TypeScript type and interface declarations using AST_NODE_TYPES
  const interfaceNode = { type: AST_NODE_TYPES.TSInterfaceDeclaration, id: { type: AST_NODE_TYPES.Identifier, name: 'Config' } };
  const typeAliasNode = { type: AST_NODE_TYPES.TSTypeAliasDeclaration, id: { type: AST_NODE_TYPES.Identifier, name: 'Id' } };
  const enumNode = { type: AST_NODE_TYPES.TSEnumDeclaration, id: { type: AST_NODE_TYPES.Identifier, name: 'Direction' } };
  const functionNode = { type: AST_NODE_TYPES.FunctionDeclaration, id: { type: AST_NODE_TYPES.Identifier, name: 'run' } };
  const varNode = { type: AST_NODE_TYPES.VariableDeclaration, kind: 'const', declarations: [] };

  assert.strictEqual(isTypeDeclarationNode(interfaceNode), true);
  assert.strictEqual(isTypeDeclarationNode(typeAliasNode), true);
  assert.strictEqual(isTypeDeclarationNode(enumNode), true);
  assert.strictEqual(isTypeDeclarationNode(functionNode), false);
  assert.strictEqual(isTypeDeclarationNode(varNode), false);
  assert.strictEqual(isTypeDeclarationNode(null), false);
  assert.strictEqual(isTypeDeclarationNode({}), false);

  console.log('Contract assertions passed successfully.');
}

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

Seeder de origem

anônimo