CodeSampleX

샘플

@typescript-eslint/scope-manager 8.69.0: ClassScope

검증된 샘플 — npm @typescript-eslint/scope-manager 8.69.0: ClassScope. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: ClassScope instance can be…

sha256:c91beaa2c8ca99a63ef568ae0c6c2c7874d36cf660e1a039ef2468edb6753fec

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify @typescript-eslint/scope-manager.ClassScope in pkg:npm/%40typescript-eslint/scope-manager@8.69.0
패키지
심벌
  • @typescript-eslint/scope-manager.ClassScope
환경
node 22.23.2
생성일
2026-10-11T16:10:53Z

컨트랙트

  1. ClassScope instance can be directly instantiated with ScopeManager, upper scope, and ClassDeclaration block
  2. analyze creates a ClassScope for ClassDeclaration with class identifier bound inside the scope
  3. analyze creates a ClassScope for ClassExpression with inner identifier scoped locally to the class
  4. ClassScope manages child scopes for class member methods with their upper reference pointing to ClassScope
  5. ClassScope enforces ECMAScript strict mode semantics with isStrict set to true across all class forms

파일

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

소스 아티팩트 내려받기 (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.ClassScope in pkg:npm/%40typescript-eslint/scope-manager@8.69.0
Kind: HOW

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

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:d226c367b0d6413b3c2d6f68f9dbfb6690a7c2fcd5061a940d326e9d6053b9d2","contract":["ClassScope instance can be directly instantiated with ScopeManager, upper scope, and ClassDeclaration block","analyze creates a ClassScope for ClassDeclaration with class identifier bound inside the scope","analyze creates a ClassScope for ClassExpression with inner identifier scoped locally to the class","ClassScope manages child scopes for class member methods with their upper reference pointing to ClassScope","ClassScope enforces ECMAScript strict mode semantics with isStrict set to true across all class forms"],"goal":"verify @typescript-eslint/scope-manager.ClassScope in pkg:npm/%40typescript-eslint/scope-manager@8.69.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.69.0"],"schemaVersion":1,"symbols":["@typescript-eslint/scope-manager.ClassScope"]},"contractCommand":["node","test/contract.cjs"],"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/scope-manager@8.69.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/scope-manager@8.69.0","symbols":["@typescript-eslint/scope-manager.ClassScope"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-typescript-eslint-scope-manager-class-scope",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-typescript-eslint-scope-manager-class-scope",
      "version": "1.0.0",
      "dependencies": {
        "@typescript-eslint/scope-manager": "8.69.0"
      }
    },
    "node_modules/@typescript-eslint/scope-manager": {
      "version": "8.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.69.0.tgz",
      "integrity": "sha512-ewfspqWvSxKSOaplqAUNbaSFO0eB6w1EtQ+esfYFRm3614Ty4uNtExkcbgd6nWsXphbqKyf9ZYdbZdv2xEoWEQ==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.69.0",
        "@typescript-eslint/visitor-keys": "8.69.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.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.69.0.tgz",
      "integrity": "sha512-K3VrubUPhlo9VDBS6QdI8YB5j7ClpqLRdefcz6PFrhnwicehBweqQ9Evhl4l+FYz0HdDmMqIiSX0aldGRYtDCA==",
      "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.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.69.0.tgz",
      "integrity": "sha512-+rmdgPA+EXkNgKYvHvFfhrs35utXbwaC5PGpDquSXcoXQDKUA5UjV0LmTucG/4JXkM31BTu4TilHtrN8IVBe8w==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.69.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-typescript-eslint-scope-manager-class-scope",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.ClassScope in pkg:npm/@typescript-eslint/scope-manager@8.69.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@typescript-eslint/scope-manager": "8.69.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/scope-manager.ClassScope in pkg:npm/%40typescript-eslint/scope-manager@8.69.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/scope-manager@8.69.0"
  ],
  "symbols": [
    "@typescript-eslint/scope-manager.ClassScope"
  ]
}
src/index.js
const {
  analyze,
  ClassScope,
  ScopeManager,
  GlobalScope,
  ScopeType,
} = require('@typescript-eslint/scope-manager');

/**
 * Creates a ClassScope directly with a given scope manager, upper scope, and class AST node.
 *
 * @param {ScopeManager} scopeManager - The scope manager instance
 * @param {import('@typescript-eslint/scope-manager').Scope} upperScope - The enclosing parent scope
 * @param {object} classNode - AST node representing the ClassDeclaration or ClassExpression
 * @returns {ClassScope}
 */
function createDirectClassScope(scopeManager, upperScope, classNode) {
  return new ClassScope(scopeManager, upperScope, classNode);
}

/**
 * Analyzes an AST and extracts all ClassScope instances.
 *
 * @param {object} ast - ESTree Program AST node
 * @param {object} [options] - Optional analysis configuration
 * @returns {{ scopeManager: ScopeManager, classScopes: ClassScope[] }}
 */
function analyzeAndFindClassScopes(ast, options) {
  const scopeManager = analyze(ast, options);
  const classScopes = scopeManager.scopes.filter(
    (scope) => scope instanceof ClassScope
  );
  return { scopeManager, classScopes };
}

/**
 * Extracts metadata from a ClassScope instance.
 *
 * @param {ClassScope} classScope - The ClassScope to inspect
 * @returns {{
 *   type: string,
 *   isStrict: boolean,
 *   blockType: string | null,
 *   boundVariables: string[],
 *   childScopeTypes: string[],
 *   upperType: string | null
 * }}
 */
function getClassScopeMetadata(classScope) {
  if (!classScope || !(classScope instanceof ClassScope)) {
    throw new TypeError('Expected an instance of ClassScope');
  }
  return {
    type: classScope.type,
    isStrict: classScope.isStrict,
    blockType: classScope.block ? classScope.block.type : null,
    boundVariables: Array.from(classScope.set.keys()),
    childScopeTypes: classScope.childScopes.map((child) => child.type),
    upperType: classScope.upper ? classScope.upper.type : null,
  };
}

module.exports = {
  createDirectClassScope,
  analyzeAndFindClassScopes,
  getClassScopeMetadata,
};
test/contract.cjs
const assert = require('node:assert/strict');
const {
  analyze,
  ClassScope,
  ScopeManager,
  GlobalScope,
  ScopeType,
} = require('@typescript-eslint/scope-manager');
const {
  createDirectClassScope,
  analyzeAndFindClassScopes,
  getClassScopeMetadata,
} = require('../src/index.js');

// 1. ClassScope instance can be directly instantiated with ScopeManager, upper scope, and ClassDeclaration block
const manager = new ScopeManager({});
const programNode = { type: 'Program', sourceType: 'module', body: [] };
const globalScope = new GlobalScope(manager, programNode);
const directClassNode = {
  type: 'ClassDeclaration',
  id: { type: 'Identifier', name: 'DirectService', decorators: [] },
  superClass: null,
  body: { type: 'ClassBody', body: [] },
  decorators: [],
  implements: [],
};
const directClassScope = createDirectClassScope(manager, globalScope, directClassNode);

assert.ok(directClassScope instanceof ClassScope, 'Instance should be ClassScope');
assert.strictEqual(directClassScope.type, ScopeType.class, 'Scope type should match ScopeType.class');
assert.strictEqual(directClassScope.type, 'class', 'Scope type should be "class"');
assert.strictEqual(directClassScope.isStrict, true, 'ClassScope should be strict mode by default');
assert.strictEqual(directClassScope.upper, globalScope, 'Upper scope should match provided parent scope');
assert.strictEqual(directClassScope.block, directClassNode, 'Block should reference the class AST node');

const directMeta = getClassScopeMetadata(directClassScope);
assert.strictEqual(directMeta.type, 'class');
assert.strictEqual(directMeta.isStrict, true);
assert.strictEqual(directMeta.blockType, 'ClassDeclaration');
assert.strictEqual(directMeta.upperType, 'global');

// 2. analyze creates a ClassScope for ClassDeclaration with class identifier bound inside the scope
const declAst = {
  type: 'Program',
  sourceType: 'module',
  body: [
    {
      type: 'ClassDeclaration',
      id: { type: 'Identifier', name: 'OrderProcessor', decorators: [] },
      superClass: null,
      typeParameters: undefined,
      superTypeArguments: undefined,
      implements: [],
      decorators: [],
      body: {
        type: 'ClassBody',
        body: [
          {
            type: 'MethodDefinition',
            key: { type: 'Identifier', name: 'process', decorators: [] },
            value: {
              type: 'FunctionExpression',
              id: null,
              generator: false,
              async: false,
              params: [{ type: 'Identifier', name: 'orderId', decorators: [] }],
              body: { type: 'BlockStatement', body: [] },
            },
            kind: 'method',
            computed: false,
            static: false,
            override: false,
            decorators: [],
          },
        ],
      },
    },
  ],
  range: [0, 80],
  loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 1 } },
};

const { scopeManager: declManager, classScopes: declClassScopes } =
  analyzeAndFindClassScopes(declAst);

assert.strictEqual(declClassScopes.length, 1, 'Should find exactly one ClassScope');
const declClassScope = declClassScopes[0];

assert.ok(declClassScope instanceof ClassScope, 'Must be an instance of ClassScope');
assert.strictEqual(declClassScope.block, declAst.body[0], 'ClassScope block should be ClassDeclaration node');
assert.strictEqual(declClassScope.isStrict, true, 'isStrict must be true for analyzed ClassScope');
assert.ok(declClassScope.set.has('OrderProcessor'), 'Class identifier should be bound in ClassScope set');
assert.ok(
  declClassScope.variables.some((v) => v.name === 'OrderProcessor'),
  'Class identifier should be recorded in variables list'
);
const classVar = declClassScope.set.get('OrderProcessor');
assert.strictEqual(classVar.name, 'OrderProcessor', 'Variable name should match class name');
assert.ok(classVar.defs.length > 0, 'Class variable should have definitions');
assert.strictEqual(classVar.defs[0].type, 'ClassName', 'Definition type should be ClassName');

// 3. analyze creates a ClassScope for ClassExpression with inner identifier scoped locally to the class
const exprAst = {
  type: 'Program',
  sourceType: 'module',
  body: [
    {
      type: 'VariableDeclaration',
      kind: 'const',
      declarations: [
        {
          type: 'VariableDeclarator',
          id: { type: 'Identifier', name: 'ExportedHandler', decorators: [] },
          init: {
            type: 'ClassExpression',
            id: { type: 'Identifier', name: 'InternalHandler', decorators: [] },
            superClass: null,
            typeParameters: undefined,
            superTypeArguments: undefined,
            implements: [],
            decorators: [],
            body: { type: 'ClassBody', body: [] },
          },
        },
      ],
    },
  ],
  range: [0, 80],
  loc: { start: { line: 1, column: 0 }, end: { line: 3, column: 1 } },
};

const { scopeManager: exprManager, classScopes: exprClassScopes } =
  analyzeAndFindClassScopes(exprAst);

assert.strictEqual(exprClassScopes.length, 1, 'Should find exactly one ClassScope for expression');
const exprClassScope = exprClassScopes[0];

assert.strictEqual(exprClassScope.block.type, 'ClassExpression', 'ClassScope block type should be ClassExpression');
assert.ok(exprClassScope.set.has('InternalHandler'), 'Inner class name must be bound in ClassScope');
const outerScope = exprManager.scopes.find((s) => s.type === 'module' || s.type === 'global');
assert.ok(outerScope, 'Outer scope should be present');
assert.strictEqual(outerScope.set.has('InternalHandler'), false, 'Inner class name must not leak to outer scope');
assert.ok(outerScope.set.has('ExportedHandler'), 'Outer variable must be present in outer scope');

// 4. ClassScope manages child scopes for class member methods with their upper reference pointing to ClassScope
assert.strictEqual(declClassScope.childScopes.length, 1, 'ClassScope should contain child scope for method');
const methodScope = declClassScope.childScopes[0];
assert.strictEqual(methodScope.type, ScopeType.function, 'Method scope type should be function');
assert.strictEqual(methodScope.upper, declClassScope, 'Method upper scope should point back to ClassScope');

const declMeta = getClassScopeMetadata(declClassScope);
assert.deepStrictEqual(declMeta.childScopeTypes, ['function']);
assert.ok(declMeta.boundVariables.includes('OrderProcessor'));

// 5. ClassScope enforces ECMAScript strict mode semantics with isStrict set to true across all class forms
assert.strictEqual(directClassScope.isStrict, true, 'Direct instance isStrict must be true');
assert.strictEqual(declClassScope.isStrict, true, 'ClassDeclaration isStrict must be true');
assert.strictEqual(exprClassScope.isStrict, true, 'ClassExpression isStrict must be true');

// Error handling validation
assert.throws(
  () => getClassScopeMetadata(null),
  /Expected an instance of ClassScope/,
  'getClassScopeMetadata should throw TypeError for invalid scope argument'
);

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

오리진 시더

익명