CodeSampleX

샘플

eslint-scope 8.4.0: analyze

검증된 샘플 — npm eslint-scope 8.4.0: analyze. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert eslint-scope.analyze returns a ScopeManager…

sha256:ba9e475e49cba3e50ce9c1966890efbb9ba25ec4f1cc660d9ea354064e4eb28b

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

케이스

HOW
목표
verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0
패키지
심벌
  • eslint-scope.analyze
생성일
2026-09-16T22:37:47Z

컨트랙트

  1. assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST
  2. assert eslint-scope.analyze creates global and module scopes and records module-level declarations
  3. assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables
  4. assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes
  5. assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/eslint-scope@8.4.0
Demonstrate these symbols/APIs:
  - eslint-scope.analyze

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:9eb8b46f680e7c539f17362287fb3abbeb42455936efd1b77688451675d5d559","contract":["assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST","assert eslint-scope.analyze creates global and module scopes and records module-level declarations","assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables","assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes","assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope"],"goal":"verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0","kind":"HOW","packages":["pkg:npm/eslint-scope@8.4.0"],"schemaVersion":1,"symbols":["eslint-scope.analyze"]},"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/eslint-scope@8.4.0"],"schemaVersion":1,"subject":"pkg:npm/eslint-scope@8.4.0","symbols":["eslint-scope.analyze"],"verifierAdapter":"node-typescript@1"}
index.mjs
import * as eslintScope from 'eslint-scope';

export const { analyze, ScopeManager, Scope, Variable, Reference } = eslintScope;

/**
 * Analyzes an ESTree AST and returns the ScopeManager instance.
 *
 * @param {object} ast ESTree abstract syntax tree
 * @param {object} [options] Analysis configuration options
 * @returns {eslintScope.ScopeManager} Analyzed scope manager
 */
export function analyzeAst(ast, options = {}) {
  return analyze(ast, options);
}

export default analyze;
package-lock.json
{
  "name": "sample-eslint-scope-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eslint-scope-verify",
      "version": "1.0.0",
      "dependencies": {
        "eslint-scope": "8.4.0"
      }
    },
    "node_modules/eslint-scope": {
      "version": "8.4.0",
      "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz",
      "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "esrecurse": "^4.3.0",
        "estraverse": "^5.2.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    },
    "node_modules/esrecurse": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
      "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "estraverse": "^5.2.0"
      },
      "engines": {
        "node": ">=4.0"
      }
    },
    "node_modules/estraverse": {
      "version": "5.3.0",
      "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",
      "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-eslint-scope-verify",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "eslint-scope": "8.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/eslint-scope@8.4.0"
  ],
  "symbols": [
    "eslint-scope.analyze"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  analyze,
  ScopeManager,
  Scope,
  Variable,
  analyzeAst,
} from '../index.mjs';

function createSampleAst() {
  return {
    type: 'Program',
    range: [0, 100],
    sourceType: 'module',
    body: [
      {
        type: 'VariableDeclaration',
        range: [0, 20],
        kind: 'let',
        declarations: [
          {
            type: 'VariableDeclarator',
            range: [4, 20],
            id: { type: 'Identifier', name: 'count', range: [4, 9] },
            init: { type: 'Literal', value: 0, raw: '0', range: [12, 13] },
          },
        ],
      },
      {
        type: 'FunctionDeclaration',
        range: [22, 90],
        id: { type: 'Identifier', name: 'increment', range: [31, 40] },
        params: [{ type: 'Identifier', name: 'step', range: [41, 45] }],
        body: {
          type: 'BlockStatement',
          range: [47, 90],
          body: [
            {
              type: 'BlockStatement',
              range: [50, 75],
              body: [
                {
                  type: 'VariableDeclaration',
                  range: [52, 65],
                  kind: 'const',
                  declarations: [
                    {
                      type: 'VariableDeclarator',
                      range: [58, 65],
                      id: { type: 'Identifier', name: 'temp', range: [58, 62] },
                      init: { type: 'Identifier', name: 'step', range: [65, 69] },
                    },
                  ],
                },
              ],
            },
            {
              type: 'ReturnStatement',
              range: [77, 88],
              argument: {
                type: 'BinaryExpression',
                range: [84, 88],
                operator: '+',
                left: { type: 'Identifier', name: 'count', range: [84, 85] },
                right: { type: 'Identifier', name: 'step', range: [87, 88] },
              },
            },
          ],
        },
      },
    ],
  };
}

// 1. assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST
{
  assert.strictEqual(typeof analyze, 'function', 'analyze must be a function');
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  assert.ok(manager instanceof ScopeManager, 'result must be an instance of ScopeManager');
  assert.ok(manager.globalScope instanceof Scope, 'globalScope must be an instance of Scope');
  assert.strictEqual(manager.globalScope.type, 'global');
  assert.ok(Array.isArray(manager.scopes), 'scopes must be an array');
  assert.strictEqual(manager.scopes.length, 4, 'scopes count must match expected');
}

// 2. assert eslint-scope.analyze creates global and module scopes and records module-level declarations
{
  const ast = createSampleAst();
  const manager = analyzeAst(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const moduleScope = manager.scopes.find((s) => s.type === 'module');
  assert.ok(moduleScope, 'module scope must exist');
  assert.strictEqual(moduleScope.upper, manager.globalScope);
  assert.ok(moduleScope.set.has('count'), 'module scope should define count');
  assert.ok(moduleScope.set.has('increment'), 'module scope should define increment');

  const countVar = moduleScope.set.get('count');
  assert.ok(countVar instanceof Variable, 'count must be a Variable instance');
  assert.strictEqual(countVar.name, 'count');
  assert.strictEqual(countVar.defs.length, 1);
  assert.strictEqual(countVar.defs[0].type, 'Variable');
}

// 3. assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables
{
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const fnScope = manager.scopes.find((s) => s.type === 'function');
  assert.ok(fnScope, 'function scope must exist');
  assert.ok(fnScope.set.has('arguments'), 'function scope should contain arguments');
  assert.ok(fnScope.set.has('step'), 'function scope should contain parameter step');
  assert.strictEqual(fnScope.block.id.name, 'increment');

  const blockScope = manager.scopes.find((s) => s.type === 'block');
  assert.ok(blockScope, 'block scope must exist');
  assert.ok(blockScope.set.has('temp'), 'block scope should contain local variable temp');
  assert.strictEqual(blockScope.upper, fnScope, 'block scope upper must be function scope');
}

// 4. assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes
{
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const fnDecl = ast.body[1];
  const acquired = manager.acquire(fnDecl);
  assert.ok(acquired, 'acquire should find scope for function declaration');
  assert.strictEqual(acquired.type, 'function');

  const varDecl = ast.body[0];
  const declared = manager.getDeclaredVariables(varDecl);
  assert.strictEqual(declared.length, 1);
  assert.strictEqual(declared[0].name, 'count');
}

// 5. assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope
{
  const scriptAst = {
    type: 'Program',
    range: [0, 25],
    sourceType: 'script',
    body: [
      {
        type: 'VariableDeclaration',
        range: [0, 20],
        kind: 'var',
        declarations: [
          {
            type: 'VariableDeclarator',
            range: [4, 20],
            id: { type: 'Identifier', name: 'appConfig', range: [4, 13] },
            init: { type: 'Literal', value: 1, raw: '1', range: [16, 17] },
          },
        ],
      },
    ],
  };

  const nodeManager = analyze(scriptAst, {
    ecmaVersion: 2020,
    sourceType: 'script',
    nodejsScope: true,
  });
  assert.strictEqual(nodeManager.scopes.length, 2);
  assert.strictEqual(nodeManager.scopes[0].type, 'global');
  assert.strictEqual(nodeManager.scopes[1].type, 'function');
  assert.ok(nodeManager.isGlobalReturn());
}

console.log('All eslint-scope.analyze contract assertions passed.');

오리진 시더

익명