CodeSampleX

Ejemplo

@typescript-eslint/scope-manager 8.65.0: CatchScope

Muestra verificada para npm @typescript-eslint/scope-manager 8.65.0: CatchScope. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:c1e75bbfa4774f7dd507f8f8189993fd2a5769b4e60623ef6f6e12bc431da5aa

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 linux 24 · ubuntu · glibc 2.39 x64 npm

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-09-05

Caso

HOW
Objetivo
verify @typescript-eslint/scope-manager.CatchScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Paquetes
Símbolos
  • @typescript-eslint/scope-manager.CatchScope
Creado
2026-09-05T14:55:49Z

Contrato

  1. CatchScope is exported by @typescript-eslint/scope-manager and instantiates with catch ScopeType, upper scope, and block AST node
  2. ScopeManager.nestCatchScope creates and registers a CatchScope within the active scope hierarchy
  3. analyze produces a CatchScope for try-catch statements with catch parameter recorded in variables and set
  4. CatchScope defines separate variables for destructured object pattern parameters
  5. CatchScope handles optional catch binding with null parameter and links child block scopes

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/scope-manager.CatchScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Demonstrate these symbols/APIs:
  - @typescript-eslint/scope-manager.CatchScope

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:133e198dfec726a850c4a368382104a612c54b5f73ecfc2ec74da054b5b22c4d","contract":["CatchScope is exported by @typescript-eslint/scope-manager and instantiates with catch ScopeType, upper scope, and block AST node","ScopeManager.nestCatchScope creates and registers a CatchScope within the active scope hierarchy","analyze produces a CatchScope for try-catch statements with catch parameter recorded in variables and set","CatchScope defines separate variables for destructured object pattern parameters","CatchScope handles optional catch binding with null parameter and links child block scopes"],"goal":"verify @typescript-eslint/scope-manager.CatchScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"symbols":["@typescript-eslint/scope-manager.CatchScope"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/scope-manager@8.65.0","symbols":["@typescript-eslint/scope-manager.CatchScope"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-scope-manager-catch-scope",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-scope-manager-catch-scope",
      "version": "1.0.0",
      "dependencies": {
        "@typescript-eslint/scope-manager": "8.65.0"
      }
    },
    "node_modules/@typescript-eslint/scope-manager": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.65.0.tgz",
      "integrity": "sha512-Esbl8OSYiVxBokYgWPf7VVWg/BE798wXhimnn9ML9Pt5qoDf8bfQlgjlKXR/k98+AcNzlLKYrpCcrcuZ9DZLgg==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "@typescript-eslint/visitor-keys": "8.65.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "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"
      }
    },
    "node_modules/@typescript-eslint/visitor-keys": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz",
      "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "eslint-visitor-keys": "^5.0.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/eslint-visitor-keys": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz",
      "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^20.19.0 || ^22.13.0 || >=24"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "verify-scope-manager-catch-scope",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.CatchScope in pkg:npm/@typescript-eslint/scope-manager@8.65.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@typescript-eslint/scope-manager": "8.65.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/scope-manager.CatchScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/scope-manager@8.65.0"
  ],
  "symbols": [
    "@typescript-eslint/scope-manager.CatchScope"
  ]
}
src/index.js
const { ScopeManager, CatchScope, analyze } = require('@typescript-eslint/scope-manager');

/**
 * Creates an instance of CatchScope directly given a ScopeManager, upper scope, and CatchClause node.
 *
 * @param {ScopeManager} scopeManager - The managing ScopeManager instance
 * @param {import('@typescript-eslint/scope-manager').Scope} upperScope - The parent scope
 * @param {object} catchNode - The ESTree/TSESTree CatchClause AST node
 * @returns {CatchScope} The newly instantiated CatchScope
 */
function createCatchScope(scopeManager, upperScope, catchNode) {
  return new CatchScope(scopeManager, upperScope, catchNode);
}

/**
 * Nests a CatchScope within an existing ScopeManager hierarchy for a CatchClause AST node.
 *
 * @param {ScopeManager} scopeManager - The ScopeManager instance
 * @param {object} catchNode - The ESTree/TSESTree CatchClause AST node
 * @returns {CatchScope} The nested CatchScope
 */
function nestCatchScopeInManager(scopeManager, catchNode) {
  return scopeManager.nestCatchScope(catchNode);
}

/**
 * Analyzes an ESTree/TSESTree Program AST containing a try-catch construct and returns all CatchScope instances.
 *
 * @param {object} ast - The ESTree Program AST node
 * @param {object} [options={}] - Optional analyzer options
 * @returns {CatchScope[]} Array of CatchScope instances found in the analyzed AST
 */
function findCatchScopes(ast, options = {}) {
  const scopeManager = analyze(ast, options);
  return scopeManager.scopes.filter((scope) => scope instanceof CatchScope);
}

/**
 * Extracts variable names defined within a CatchScope (e.g., error parameter bindings).
 *
 * @param {CatchScope} catchScope - The CatchScope instance
 * @returns {string[]} Array of declared variable names
 */
function getCatchVariableNames(catchScope) {
  return catchScope.variables.map((variable) => variable.name);
}

module.exports = {
  CatchScope,
  ScopeManager,
  analyze,
  createCatchScope,
  nestCatchScopeInManager,
  findCatchScopes,
  getCatchVariableNames,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  CatchScope,
  ScopeManager,
  createCatchScope,
  nestCatchScopeInManager,
  findCatchScopes,
  getCatchVariableNames,
} = require('../src/index.js');
const scopeManagerModule = require('@typescript-eslint/scope-manager');

// 1. CatchScope is exported by @typescript-eslint/scope-manager and instantiates with catch ScopeType, upper scope, and block AST node
assert.strictEqual(typeof CatchScope, 'function', 'CatchScope constructor should be exported as a function');
assert.strictEqual(CatchScope, scopeManagerModule.CatchScope, 'CatchScope export must match package CatchScope export');

const sm1 = new ScopeManager({});
const globalNode1 = { type: 'Program', body: [] };
const globalScope1 = sm1.nestGlobalScope(globalNode1);
const catchNode1 = {
  type: 'CatchClause',
  param: null,
  body: { type: 'BlockStatement', body: [] },
};
const directScope = createCatchScope(sm1, globalScope1, catchNode1);

assert.strictEqual(directScope instanceof CatchScope, true, 'Instance should be an instanceof CatchScope');
assert.strictEqual(directScope.type, 'catch', 'Scope type must be "catch"');
assert.strictEqual(directScope.upper, globalScope1, 'CatchScope upper must point to the parent scope');
assert.strictEqual(directScope.block, catchNode1, 'CatchScope block must point to the CatchClause node');

// 2. ScopeManager.nestCatchScope creates and registers a CatchScope within the active scope hierarchy
const sm2 = new ScopeManager({});
const globalNode2 = { type: 'Program', body: [] };
sm2.nestGlobalScope(globalNode2);
const catchNode2 = {
  type: 'CatchClause',
  param: null,
  body: { type: 'BlockStatement', body: [] },
};

const nestedScope = nestCatchScopeInManager(sm2, catchNode2);
assert.strictEqual(nestedScope instanceof CatchScope, true, 'nestedScope should be an instance of CatchScope');
assert.strictEqual(nestedScope.type, 'catch', 'nestedScope type must be "catch"');
assert.strictEqual(sm2.scopes.includes(nestedScope), true, 'ScopeManager scopes array must contain the CatchScope');
assert.strictEqual(sm2.acquire(catchNode2), nestedScope, 'ScopeManager acquire must resolve the CatchClause to the CatchScope');
assert.strictEqual(sm2.currentScope, nestedScope, 'ScopeManager currentScope should be updated to the CatchScope');

// 3. analyze produces a CatchScope for try-catch statements with catch parameter recorded in variables and set
const astWithParam = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'TryStatement',
      block: { type: 'BlockStatement', body: [] },
      handler: {
        type: 'CatchClause',
        param: { type: 'Identifier', name: 'err' },
        body: {
          type: 'BlockStatement',
          body: [
            {
              type: 'ExpressionStatement',
              expression: { type: 'Identifier', name: 'err' },
            },
          ],
        },
      },
      finalizer: null,
    },
  ],
};

const catchScopesWithParam = findCatchScopes(astWithParam);
assert.strictEqual(catchScopesWithParam.length, 1, 'Exactly one CatchScope should be found in AST');
const [catchScope3] = catchScopesWithParam;

assert.strictEqual(catchScope3.type, 'catch', 'Scope type must be "catch"');
assert.strictEqual(catchScope3.set.has('err'), true, 'CatchScope set must contain the error variable');
const names = getCatchVariableNames(catchScope3);
assert.deepStrictEqual(names, ['err'], 'Variables declared in CatchScope must match parameter name');

const errVariable = catchScope3.set.get('err');
assert.strictEqual(errVariable.name, 'err');
assert.strictEqual(errVariable.defs[0].type, 'CatchClause', 'Variable definition type should be CatchClause');
assert.strictEqual(errVariable.references.length, 1, 'Variable should resolve the identifier reference in catch body');
assert.strictEqual(errVariable.references[0].identifier.name, 'err');

// 4. CatchScope defines separate variables for destructured object pattern parameters
const astDestructured = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'TryStatement',
      block: { type: 'BlockStatement', body: [] },
      handler: {
        type: 'CatchClause',
        param: {
          type: 'ObjectPattern',
          properties: [
            {
              type: 'Property',
              key: { type: 'Identifier', name: 'message' },
              value: { type: 'Identifier', name: 'message' },
              kind: 'init',
              method: false,
              shorthand: true,
              computed: false,
            },
            {
              type: 'Property',
              key: { type: 'Identifier', name: 'code' },
              value: { type: 'Identifier', name: 'code' },
              kind: 'init',
              method: false,
              shorthand: true,
              computed: false,
            },
          ],
        },
        body: {
          type: 'BlockStatement',
          body: [
            {
              type: 'ExpressionStatement',
              expression: { type: 'Identifier', name: 'message' },
            },
          ],
        },
      },
      finalizer: null,
    },
  ],
};

const [catchScope4] = findCatchScopes(astDestructured);
assert.ok(catchScope4, 'CatchScope should be found for destructured pattern');
assert.strictEqual(catchScope4.set.has('message'), true, 'Scope set should have "message" variable');
assert.strictEqual(catchScope4.set.has('code'), true, 'Scope set should have "code" variable');
const destructuredNames = getCatchVariableNames(catchScope4);
assert.strictEqual(destructuredNames.length, 2, 'Should define two variables for the two pattern properties');
assert.strictEqual(destructuredNames.includes('message'), true);
assert.strictEqual(destructuredNames.includes('code'), true);

// 5. CatchScope handles optional catch binding with null parameter and links child block scopes
const astOptional = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'TryStatement',
      block: { type: 'BlockStatement', body: [] },
      handler: {
        type: 'CatchClause',
        param: null,
        body: {
          type: 'BlockStatement',
          body: [],
        },
      },
      finalizer: null,
    },
  ],
};

const [catchScope5] = findCatchScopes(astOptional);
assert.ok(catchScope5, 'CatchScope should be created even when param is null');
assert.strictEqual(catchScope5.variables.length, 0, 'Variables list must be empty for optional catch binding');
assert.strictEqual(catchScope5.block.param, null, 'CatchScope block param should be null');
assert.strictEqual(catchScope5.childScopes.length, 1, 'CatchScope must contain the inner body BlockScope as child');
assert.strictEqual(catchScope5.childScopes[0].type, 'block', 'Child scope should have type "block"');
assert.strictEqual(catchScope5.childScopes[0].upper, catchScope5, 'Child block scope upper pointer must link to CatchScope');

console.log('All CatchScope contract assertions passed successfully.');

Seeder de origen

anónimo