CodeSampleX

Exemplo

espree 10.4.0: Syntax

Amostra verificada para npm espree 10.4.0: Syntax. O contrato rodou em node 22 · linux debian/x64 · docker e passou: Syntax is an immutable dictionary with…

sha256:24063d673009112986ca7707382531395dce490a80d551433c9dc10ebfce661e

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-07

Caso

HOW
Objetivo
verify espree.Syntax in pkg:npm/espree@10.4.0
Pacotes
Símbolos
  • espree.Syntax
Ambiente
node 22.23.2
Criado
2026-09-07T03:24:55Z

Contrato

  1. Syntax is an immutable dictionary with null prototype mapping ESTree node types to identical string constants
  2. Syntax enumerates standard ECMAScript statement and declaration node types
  3. Syntax enumerates standard ECMAScript expression and pattern node types
  4. Syntax enumerates JSX AST node types for JSX syntax trees
  5. Syntax constants match the node types produced by espree.parse during script and module parsing
  6. Syntax constants enable filtering and visitor dispatch across ESTree syntax trees

Arquivos

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 espree.Syntax in pkg:npm/espree@10.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/espree@10.4.0
Demonstrate these symbols/APIs:
  - espree.Syntax

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:6eb0da9f4498ea6ddc81cf655d44862d9fd3d7ea3359762aa4e741ce61b7daa4","contract":["Syntax is an immutable dictionary with null prototype mapping ESTree node types to identical string constants","Syntax enumerates standard ECMAScript statement and declaration node types","Syntax enumerates standard ECMAScript expression and pattern node types","Syntax enumerates JSX AST node types for JSX syntax trees","Syntax constants match the node types produced by espree.parse during script and module parsing","Syntax constants enable filtering and visitor dispatch across ESTree syntax trees"],"goal":"verify espree.Syntax in pkg:npm/espree@10.4.0","kind":"HOW","packages":["pkg:npm/espree@10.4.0"],"schemaVersion":1,"symbols":["espree.Syntax"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/espree@10.4.0"],"schemaVersion":1,"subject":"pkg:npm/espree@10.4.0","symbols":["espree.Syntax"],"verifierAdapter":"node-typescript@1"}
index.js
import * as espree from 'espree';

/**
 * Re-export Syntax dictionary from espree.
 * Frozen map of ESTree node types (null prototype).
 */
export const Syntax = espree.Syntax;

/**
 * Check whether a string is a recognized ESTree node type in espree.Syntax.
 * @param {string} typeName
 * @returns {boolean}
 */
export function hasSyntaxType(typeName) {
  return typeof typeName === 'string' && Object.hasOwn(Syntax, typeName);
}

/**
 * Check whether an AST node matches an expected Syntax node type.
 * @param {object} node - AST node to check
 * @param {string} expectedType - Expected node type from Syntax
 * @returns {boolean}
 */
export function isNodeType(node, expectedType) {
  return Boolean(node && typeof node === 'object' && node.type === expectedType);
}

/**
 * Traverse an ESTree AST and collect all nodes matching the target Syntax type.
 * @param {object} rootNode - Root AST node (e.g., Program)
 * @param {string} targetType - Syntax constant to filter by
 * @returns {Array<object>}
 */
export function filterNodesByType(rootNode, targetType) {
  const matches = [];

  function traverse(node) {
    if (!node || typeof node !== 'object') {
      return;
    }

    if (node.type === targetType) {
      matches.push(node);
    }

    for (const key of Object.keys(node)) {
      if (key === 'loc' || key === 'range') {
        continue;
      }
      const child = node[key];
      if (Array.isArray(child)) {
        for (const item of child) {
          if (item && typeof item === 'object' && typeof item.type === 'string') {
            traverse(item);
          }
        }
      } else if (child && typeof child === 'object' && typeof child.type === 'string') {
        traverse(child);
      }
    }
  }

  traverse(rootNode);
  return matches;
}

/**
 * Create a simple visitor dispatch runner over an ESTree AST.
 * Handlers are keyed by Syntax node type strings.
 * @param {Record<string, Function>} handlers
 * @returns {(rootNode: object) => void}
 */
export function createVisitor(handlers) {
  return function visit(rootNode) {
    function traverse(node, parent) {
      if (!node || typeof node !== 'object') {
        return;
      }

      if (typeof node.type === 'string' && typeof handlers[node.type] === 'function') {
        handlers[node.type](node, parent);
      }

      for (const key of Object.keys(node)) {
        if (key === 'loc' || key === 'range') {
          continue;
        }
        const child = node[key];
        if (Array.isArray(child)) {
          for (const item of child) {
            if (item && typeof item === 'object' && typeof item.type === 'string') {
              traverse(item, node);
            }
          }
        } else if (child && typeof child === 'object' && typeof child.type === 'string') {
          traverse(child, node);
        }
      }
    }

    traverse(rootNode, null);
  };
}

export { espree };
package-lock.json
{
  "name": "sample-espree-syntax",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-espree-syntax",
      "version": "1.0.0",
      "dependencies": {
        "espree": "10.4.0"
      }
    },
    "node_modules/acorn": {
      "version": "8.18.0",
      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz",
      "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==",
      "license": "MIT",
      "bin": {
        "acorn": "bin/acorn"
      },
      "engines": {
        "node": ">=0.4.0"
      }
    },
    "node_modules/acorn-jsx": {
      "version": "5.3.2",
      "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
      "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
      "license": "MIT",
      "peerDependencies": {
        "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
      }
    },
    "node_modules/eslint-visitor-keys": {
      "version": "4.2.1",
      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz",
      "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    },
    "node_modules/espree": {
      "version": "10.4.0",
      "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz",
      "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "acorn": "^8.15.0",
        "acorn-jsx": "^5.3.2",
        "eslint-visitor-keys": "^4.2.1"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "sample-espree-syntax",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "espree": "10.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify espree.Syntax in pkg:npm/espree@10.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/espree@10.4.0"
  ],
  "symbols": [
    "espree.Syntax"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Syntax,
  hasSyntaxType,
  isNodeType,
  filterNodesByType,
  createVisitor,
  espree,
} from '../index.js';

// 1. Syntax is an immutable dictionary with null prototype mapping ESTree node types to identical string constants
assert.strictEqual(typeof Syntax, 'object', 'Syntax must be an object');
assert.strictEqual(Object.getPrototypeOf(Syntax), null, 'Syntax must have null prototype');
assert.strictEqual(Object.isFrozen(Syntax), true, 'Syntax object must be frozen');
assert.ok(Object.keys(Syntax).length > 80, 'Syntax must define all core ESTree node types');
for (const [key, value] of Object.entries(Syntax)) {
  assert.strictEqual(key, value, `Syntax property ${key} must map to its own key name`);
}
assert.strictEqual(hasSyntaxType('Program'), true, 'Program must be recognized');
assert.strictEqual(hasSyntaxType('NonExistentType'), false, 'NonExistentType must not be recognized');

// 2. Syntax enumerates standard ECMAScript statement and declaration node types
assert.strictEqual(Syntax.Program, 'Program');
assert.strictEqual(Syntax.VariableDeclaration, 'VariableDeclaration');
assert.strictEqual(Syntax.FunctionDeclaration, 'FunctionDeclaration');
assert.strictEqual(Syntax.ClassDeclaration, 'ClassDeclaration');
assert.strictEqual(Syntax.ImportDeclaration, 'ImportDeclaration');
assert.strictEqual(Syntax.ExportNamedDeclaration, 'ExportNamedDeclaration');
assert.strictEqual(Syntax.ExportDefaultDeclaration, 'ExportDefaultDeclaration');
assert.strictEqual(Syntax.IfStatement, 'IfStatement');
assert.strictEqual(Syntax.ReturnStatement, 'ReturnStatement');
assert.strictEqual(Syntax.BlockStatement, 'BlockStatement');
assert.strictEqual(Syntax.ExpressionStatement, 'ExpressionStatement');
assert.strictEqual(Syntax.WhileStatement, 'WhileStatement');
assert.strictEqual(Syntax.ForStatement, 'ForStatement');
assert.strictEqual(Syntax.TryStatement, 'TryStatement');

// 3. Syntax enumerates standard ECMAScript expression and pattern node types
assert.strictEqual(Syntax.Identifier, 'Identifier');
assert.strictEqual(Syntax.Literal, 'Literal');
assert.strictEqual(Syntax.BinaryExpression, 'BinaryExpression');
assert.strictEqual(Syntax.UnaryExpression, 'UnaryExpression');
assert.strictEqual(Syntax.CallExpression, 'CallExpression');
assert.strictEqual(Syntax.MemberExpression, 'MemberExpression');
assert.strictEqual(Syntax.ArrowFunctionExpression, 'ArrowFunctionExpression');
assert.strictEqual(Syntax.ObjectExpression, 'ObjectExpression');
assert.strictEqual(Syntax.ArrayExpression, 'ArrayExpression');
assert.strictEqual(Syntax.ObjectPattern, 'ObjectPattern');
assert.strictEqual(Syntax.ArrayPattern, 'ArrayPattern');

// 4. Syntax enumerates JSX AST node types for JSX syntax trees
assert.strictEqual(Syntax.JSXElement, 'JSXElement');
assert.strictEqual(Syntax.JSXOpeningElement, 'JSXOpeningElement');
assert.strictEqual(Syntax.JSXClosingElement, 'JSXClosingElement');
assert.strictEqual(Syntax.JSXAttribute, 'JSXAttribute');
assert.strictEqual(Syntax.JSXIdentifier, 'JSXIdentifier');
assert.strictEqual(Syntax.JSXText, 'JSXText');
assert.strictEqual(Syntax.JSXFragment, 'JSXFragment');

// 5. Syntax constants match the node types produced by espree.parse during script and module parsing
const scriptCode = 'function add(a, b) { return a + b; } const result = add(1, 2);';
const ast = espree.parse(scriptCode, { ecmaVersion: 'latest' });
assert.strictEqual(isNodeType(ast, Syntax.Program), true);
assert.strictEqual(isNodeType(ast.body[0], Syntax.FunctionDeclaration), true);
assert.strictEqual(isNodeType(ast.body[0].id, Syntax.Identifier), true);
assert.strictEqual(isNodeType(ast.body[0].body, Syntax.BlockStatement), true);
assert.strictEqual(isNodeType(ast.body[0].body.body[0], Syntax.ReturnStatement), true);
assert.strictEqual(isNodeType(ast.body[0].body.body[0].argument, Syntax.BinaryExpression), true);
assert.strictEqual(isNodeType(ast.body[1], Syntax.VariableDeclaration), true);

const jsxCode = '<Button active={true}>Submit</Button>';
const jsxAst = espree.parse(jsxCode, {
  ecmaVersion: 'latest',
  sourceType: 'module',
  ecmaFeatures: { jsx: true },
});
const jsxExpr = jsxAst.body[0].expression;
assert.strictEqual(isNodeType(jsxExpr, Syntax.JSXElement), true);
assert.strictEqual(isNodeType(jsxExpr.openingElement, Syntax.JSXOpeningElement), true);
assert.strictEqual(isNodeType(jsxExpr.openingElement.name, Syntax.JSXIdentifier), true);
assert.strictEqual(isNodeType(jsxExpr.openingElement.attributes[0], Syntax.JSXAttribute), true);
assert.strictEqual(isNodeType(jsxExpr.children[0], Syntax.JSXText), true);

// 6. Syntax constants enable filtering and visitor dispatch across ESTree syntax trees
const sourceCode = `
  const x = 10;
  function square(n) { return n * n; }
  const y = square(x);
  export { y };
`;
const parsedAst = espree.parse(sourceCode, { ecmaVersion: 'latest', sourceType: 'module' });

const identifiers = filterNodesByType(parsedAst, Syntax.Identifier);
const idNames = identifiers.map(n => n.name);
assert.ok(idNames.includes('x'));
assert.ok(idNames.includes('square'));
assert.ok(idNames.includes('n'));
assert.ok(idNames.includes('y'));

const visitedTypes = [];
const visitor = createVisitor({
  [Syntax.FunctionDeclaration](node) {
    visitedTypes.push(node.id.name);
  },
  [Syntax.VariableDeclaration](node) {
    visitedTypes.push(node.kind);
  },
});
visitor(parsedAst);
assert.ok(visitedTypes.includes('const'));
assert.ok(visitedTypes.includes('square'));

console.log('Contract verification finished successfully: all espree.Syntax assertions passed.');

Seeder de origem

anônimo