CodeSampleX

샘플

@typescript-eslint/scope-manager 8.69.0: TSEnumNameDefinition

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

sha256:8669e7e83f03e0c2f6d901284013966a526d822a577e0de106062e5581697f66

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

케이스

HOW
목표
verify @typescript-eslint/scope-manager.TSEnumNameDefinition in pkg:npm/%40typescript-eslint/scope-manager@8.69.0
패키지
심벌
  • @typescript-eslint/scope-manager.TSEnumNameDefinition
환경
node 22.23.2
생성일
2026-10-12T04:32:33Z

컨트랙트

  1. TSEnumNameDefinition can be directly instantiated with name identifier and enum declaration AST nodes
  2. TSEnumNameDefinition marks definition as both type definition and variable definition
  3. analyze creates TSEnumNameDefinition for enum declarations in scope
  4. analyze creates multiple TSEnumNameDefinition entries for merged enum declarations
  5. TSEnumNameDefinition assigns a unique numeric $id to each instance

파일

  • 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.TSEnumNameDefinition 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.TSEnumNameDefinition

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:03a8dbdb1a291f49a80b0c5a5e10f7490d58afa4f1b96f732dedd2ea75919f24","contract":["TSEnumNameDefinition can be directly instantiated with name identifier and enum declaration AST nodes","TSEnumNameDefinition marks definition as both type definition and variable definition","analyze creates TSEnumNameDefinition for enum declarations in scope","analyze creates multiple TSEnumNameDefinition entries for merged enum declarations","TSEnumNameDefinition assigns a unique numeric $id to each instance"],"goal":"verify @typescript-eslint/scope-manager.TSEnumNameDefinition 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.TSEnumNameDefinition"]},"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.TSEnumNameDefinition"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-scope-manager-tsenumnamedefinition",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-scope-manager-tsenumnamedefinition",
      "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-scope-manager-tsenumnamedefinition",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.TSEnumNameDefinition 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.TSEnumNameDefinition 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.TSEnumNameDefinition"
  ]
}
src/index.js
const {
  analyze,
  TSEnumNameDefinition,
  ScopeType,
  DefinitionType,
} = require('@typescript-eslint/scope-manager');

/**
 * Creates a new TSEnumNameDefinition instance directly.
 *
 * @param {object} name - The Identifier node representing the enum name.
 * @param {object} node - The TSEnumDeclaration AST node.
 * @returns {TSEnumNameDefinition} The created TSEnumNameDefinition instance.
 */
function createEnumNameDefinition(name, node) {
  return new TSEnumNameDefinition(name, node);
}

/**
 * Analyzes an AST and returns all TSEnumNameDefinition instances found across scopes.
 *
 * @param {object} ast - ESTree / TSESTree program AST.
 * @param {object} [options] - Optional scope analyzer options.
 * @returns {TSEnumNameDefinition[]} Array of TSEnumNameDefinition instances.
 */
function extractEnumNameDefinitions(ast, options) {
  const scopeManager = analyze(ast, options);
  const definitions = [];

  for (const scope of scopeManager.scopes) {
    for (const variable of scope.variables) {
      for (const def of variable.defs) {
        if (def instanceof TSEnumNameDefinition) {
          definitions.push(def);
        }
      }
    }
  }

  return definitions;
}

/**
 * Checks whether an object is an instance of TSEnumNameDefinition.
 *
 * @param {unknown} def - Value to check.
 * @returns {boolean} True if the value is a TSEnumNameDefinition.
 */
function isEnumNameDefinition(def) {
  return def instanceof TSEnumNameDefinition;
}

module.exports = {
  createEnumNameDefinition,
  extractEnumNameDefinitions,
  isEnumNameDefinition,
  TSEnumNameDefinition,
  DefinitionType,
  ScopeType,
  analyze,
};
test/contract.cjs
const assert = require('node:assert/strict');
const {
  createEnumNameDefinition,
  extractEnumNameDefinitions,
  isEnumNameDefinition,
  TSEnumNameDefinition,
  DefinitionType,
  ScopeType,
  analyze,
} = require('../src/index.js');

// 1. TSEnumNameDefinition can be directly instantiated with name identifier and enum declaration AST nodes
const identifierNameNode = {
  type: 'Identifier',
  name: 'Direction',
  range: [5, 14],
};
const enumDeclarationNode = {
  type: 'TSEnumDeclaration',
  id: identifierNameNode,
  body: {
    type: 'TSEnumBody',
    members: [],
    range: [15, 17],
  },
  range: [0, 17],
};

const directDefinition = createEnumNameDefinition(identifierNameNode, enumDeclarationNode);

assert.ok(directDefinition, 'Direct definition instance should be created');
assert.ok(isEnumNameDefinition(directDefinition), 'Instance should be recognized as TSEnumNameDefinition');
assert.strictEqual(
  directDefinition.type,
  DefinitionType.TSEnumName,
  'Definition type should match DefinitionType.TSEnumName'
);
assert.strictEqual(directDefinition.name, identifierNameNode, 'Definition name should refer to the name identifier node');
assert.strictEqual(directDefinition.node, enumDeclarationNode, 'Definition node should refer to the TSEnumDeclaration node');
assert.strictEqual(directDefinition.parent, null, 'Definition parent should be null');

// 2. TSEnumNameDefinition marks definition as both type definition and variable definition
assert.strictEqual(
  directDefinition.isTypeDefinition,
  true,
  'TSEnumNameDefinition should have isTypeDefinition set to true'
);
assert.strictEqual(
  directDefinition.isVariableDefinition,
  true,
  'TSEnumNameDefinition should have isVariableDefinition set to true'
);

// 3. analyze creates TSEnumNameDefinition for enum declarations in scope
const enumAst = {
  type: 'Program',
  body: [
    {
      type: 'TSEnumDeclaration',
      id: { type: 'Identifier', name: 'Status', range: [5, 11] },
      body: {
        type: 'TSEnumBody',
        members: [
          {
            type: 'TSEnumMember',
            id: { type: 'Identifier', name: 'Active', range: [14, 20] },
            initializer: { type: 'Literal', value: 1, raw: '1', range: [23, 24] },
            range: [14, 24],
          },
        ],
        range: [12, 26],
      },
      range: [0, 26],
    },
  ],
  sourceType: 'module',
  range: [0, 26],
};

const scopeManager = analyze(enumAst, { sourceType: 'module' });
const moduleScope = scopeManager.scopes.find((s) => s.type === ScopeType.module);
assert.ok(moduleScope, 'Module scope should exist');

const statusVar = moduleScope.variables.find((v) => v.name === 'Status');
assert.ok(statusVar, 'Status variable should exist in module scope');
assert.strictEqual(statusVar.defs.length, 1, 'Status variable should have exactly one definition');

const statusDef = statusVar.defs[0];
assert.ok(statusDef instanceof TSEnumNameDefinition, 'Status definition should be instance of TSEnumNameDefinition');
assert.strictEqual(statusDef.type, DefinitionType.TSEnumName, 'Status definition type should be TSEnumName');
assert.strictEqual(statusDef.name.name, 'Status', 'Status definition name should be Status');
assert.strictEqual(statusDef.isTypeDefinition, true, 'Status definition should be a type definition');
assert.strictEqual(statusDef.isVariableDefinition, true, 'Status definition should be a variable definition');

const extractedDefinitions = extractEnumNameDefinitions(enumAst, { sourceType: 'module' });
assert.strictEqual(extractedDefinitions.length, 1, 'Should extract 1 enum name definition');
assert.ok(extractedDefinitions.every(isEnumNameDefinition), 'Extracted definition should be TSEnumNameDefinition');

// 4. analyze creates multiple TSEnumNameDefinition entries for merged enum declarations
const mergedEnumAst = {
  type: 'Program',
  body: [
    {
      type: 'TSEnumDeclaration',
      id: { type: 'Identifier', name: 'Color', range: [0, 10] },
      body: { type: 'TSEnumBody', members: [], range: [11, 15] },
      range: [0, 15],
    },
    {
      type: 'TSEnumDeclaration',
      id: { type: 'Identifier', name: 'Color', range: [16, 26] },
      body: { type: 'TSEnumBody', members: [], range: [27, 31] },
      range: [16, 31],
    },
  ],
  range: [0, 31],
};

const mergedScopeManager = analyze(mergedEnumAst);
const globalScope = mergedScopeManager.scopes[0];
const colorVariable = globalScope.variables.find((v) => v.name === 'Color');
assert.ok(colorVariable, 'Color variable should exist in scope');
assert.strictEqual(colorVariable.defs.length, 2, 'Color should have two definitions from enum merging');
assert.ok(
  colorVariable.defs.every((d) => d instanceof TSEnumNameDefinition),
  'Both merged definitions should be TSEnumNameDefinition instances'
);
assert.strictEqual(colorVariable.defs[0].type, DefinitionType.TSEnumName);
assert.strictEqual(colorVariable.defs[1].type, DefinitionType.TSEnumName);

// 5. TSEnumNameDefinition assigns a unique numeric $id to each instance
const secondDefinition = createEnumNameDefinition(identifierNameNode, enumDeclarationNode);
assert.strictEqual(typeof directDefinition.$id, 'number', '$id should be a number');
assert.strictEqual(typeof secondDefinition.$id, 'number', '$id should be a number');
assert.notStrictEqual(
  directDefinition.$id,
  secondDefinition.$id,
  'Each TSEnumNameDefinition instance should have a unique $id'
);

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

오리진 시더

익명