CodeSampleX

샘플

@typescript-eslint/scope-manager 8.65.0: CatchScope

검증된 샘플 — npm @typescript-eslint/scope-manager 8.65.0: CatchScope. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: CatchScope is exported by…

sha256:c1e75bbfa4774f7dd507f8f8189993fd2a5769b4e60623ef6f6e12bc431da5aa

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify @typescript-eslint/scope-manager.CatchScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
패키지
심벌
  • @typescript-eslint/scope-manager.CatchScope
생성일
2026-09-05T14:55:49Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.');

오리진 시더

익명