샘플
typescript 7.0.2: isMethodDeclaration
검증된 샘플 — npm typescript 7.0.2: isMethodDeclaration. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: isMethodDeclaration returns true for…
sha256:e1cd880e493983ec3976f44af6e7ffb9c302730902c0ba1303c37a98599972c3
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-28 |
케이스
HOW- 목표
- verify typescript.isMethodDeclaration in pkg:npm/typescript@7.0.2
- 패키지
- 심벌
-
- typescript.isMethodDeclaration
- 생성일
- 2026-08-28T07:59:17Z
컨트랙트
- isMethodDeclaration returns true for MethodDeclaration AST nodes created with factory.createMethodDeclaration
- isMethodDeclaration returns false for other AST nodes such as Identifier, Block, ParameterDeclaration, and PropertyDeclaration
- isMethodDeclaration returns false for plain objects with different kind values
- findMethodDeclarations extracts and filters only method declarations from class declaration members
- getMethodInfo retrieves name, parameter count, and body presence from validated MethodDeclaration nodes and throws TypeError for non-method nodes
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
소스
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.isMethodDeclaration in pkg:npm/typescript@7.0.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/typescript@7.0.2
Demonstrate these symbols/APIs:
- typescript.isMethodDeclaration
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.
{"case":{"caseId":"case:sha256:f96f82119b0a446346c811e47382386356949a031c698b65a177e4a5fbb1028c","contract":["isMethodDeclaration returns true for MethodDeclaration AST nodes created with factory.createMethodDeclaration","isMethodDeclaration returns false for other AST nodes such as Identifier, Block, ParameterDeclaration, and PropertyDeclaration","isMethodDeclaration returns false for plain objects with different kind values","findMethodDeclarations extracts and filters only method declarations from class declaration members","getMethodInfo retrieves name, parameter count, and body presence from validated MethodDeclaration nodes and throws TypeError for non-method nodes"],"goal":"verify typescript.isMethodDeclaration in pkg:npm/typescript@7.0.2","kind":"HOW","packages":["pkg:npm/typescript@7.0.2"],"schemaVersion":1,"symbols":["typescript.isMethodDeclaration"]},"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/typescript@7.0.2"],"schemaVersion":1,"subject":"pkg:npm/typescript@7.0.2","symbols":["typescript.isMethodDeclaration"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-68682851",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-68682851",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"typescript": "^7.0.2"
}
},
"node_modules/@typescript/typescript-aix-ppc64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz",
"integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==",
"cpu": [
"ppc64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"aix"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-darwin-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz",
"integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-darwin-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz",
"integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-freebsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz",
"integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-freebsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz",
"integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-arm": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz",
"integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==",
"cpu": [
"arm"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz",
"integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-loong64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz",
"integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==",
"cpu": [
"loong64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-mips64el": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz",
"integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==",
"cpu": [
"mips64el"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-ppc64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz",
"integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==",
"cpu": [
"ppc64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-riscv64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz",
"integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==",
"cpu": [
"riscv64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-s390x": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz",
"integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==",
"cpu": [
"s390x"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz",
"integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-netbsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz",
"integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-netbsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz",
"integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-openbsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz",
"integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-openbsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz",
"integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-sunos-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz",
"integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"sunos"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-win32-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz",
"integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-win32-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz",
"integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/typescript": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz",
"integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==",
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc"
},
"engines": {
"node": ">=16.20.0"
},
"optionalDependencies": {
"@typescript/typescript-aix-ppc64": "7.0.2",
"@typescript/typescript-darwin-arm64": "7.0.2",
"@typescript/typescript-darwin-x64": "7.0.2",
"@typescript/typescript-freebsd-arm64": "7.0.2",
"@typescript/typescript-freebsd-x64": "7.0.2",
"@typescript/typescript-linux-arm": "7.0.2",
"@typescript/typescript-linux-arm64": "7.0.2",
"@typescript/typescript-linux-loong64": "7.0.2",
"@typescript/typescript-linux-mips64el": "7.0.2",
"@typescript/typescript-linux-ppc64": "7.0.2",
"@typescript/typescript-linux-riscv64": "7.0.2",
"@typescript/typescript-linux-s390x": "7.0.2",
"@typescript/typescript-linux-x64": "7.0.2",
"@typescript/typescript-netbsd-arm64": "7.0.2",
"@typescript/typescript-netbsd-x64": "7.0.2",
"@typescript/typescript-openbsd-arm64": "7.0.2",
"@typescript/typescript-openbsd-x64": "7.0.2",
"@typescript/typescript-sunos-x64": "7.0.2",
"@typescript/typescript-win32-arm64": "7.0.2",
"@typescript/typescript-win32-x64": "7.0.2"
}
}
}
}
{
"name": "sample-typescript-is-method-declaration",
"version": "1.0.0",
"description": "Construct and validate TypeScript method declarations using isMethodDeclaration",
"type": "module",
"main": "src/index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"typescript": "7.0.2"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify typescript.isMethodDeclaration in pkg:npm/typescript@7.0.2",
"kind": "HOW",
"packages": [
"pkg:npm/typescript@7.0.2"
],
"symbols": [
"typescript.isMethodDeclaration"
]
}
import {
createMethodDeclaration,
createIdentifier,
createBlock,
createParameterDeclaration,
createPropertyDeclaration,
createClassDeclaration,
createKeywordTypeNode
} from 'typescript/unstable/ast/factory';
import {
isMethodDeclaration,
SyntaxKind
} from 'typescript/unstable/ast';
/**
* Creates a simple MethodDeclaration AST node with the given name, parameter names, and optional statements.
*
* @param {string} name - Method name identifier.
* @param {string[]} [paramNames=[]] - Parameter names.
* @param {object[]} [statements=[]] - Statements for the method body block.
* @returns {object} MethodDeclaration AST node.
*/
export function createSimpleMethod(name, paramNames = [], statements = []) {
const methodName = createIdentifier(name);
const parameters = paramNames.map(paramName =>
createParameterDeclaration(
undefined,
undefined,
createIdentifier(paramName),
undefined,
undefined,
undefined
)
);
const body = createBlock(statements, true);
return createMethodDeclaration(
undefined,
undefined,
methodName,
undefined,
undefined,
parameters,
undefined,
body
);
}
/**
* Extracts and filters all valid MethodDeclaration nodes from a class declaration.
*
* @param {object} classNode - AST node (e.g. ClassDeclaration).
* @returns {object[]} Array of validated MethodDeclaration AST nodes.
*/
export function findMethodDeclarations(classNode) {
if (!classNode || !Array.isArray(classNode.members)) {
return [];
}
return classNode.members.filter(node => node && isMethodDeclaration(node));
}
/**
* Retrieves summary information from a validated MethodDeclaration AST node.
*
* @param {object} node - MethodDeclaration AST node.
* @returns {{ name: string, parameterCount: number, hasBody: boolean }} Method summary info.
*/
export function getMethodInfo(node) {
if (!node || !isMethodDeclaration(node)) {
throw new TypeError('Expected an AST MethodDeclaration node');
}
return {
name: node.name && node.name.text ? node.name.text : '',
parameterCount: Array.isArray(node.parameters) ? node.parameters.length : 0,
hasBody: Boolean(node.body)
};
}
export {
isMethodDeclaration,
createMethodDeclaration,
createIdentifier,
createBlock,
createParameterDeclaration,
createPropertyDeclaration,
createClassDeclaration,
createKeywordTypeNode,
SyntaxKind
};
import assert from 'node:assert/strict';
import {
createIdentifier,
createBlock,
createParameterDeclaration,
createPropertyDeclaration,
createClassDeclaration,
createKeywordTypeNode
} from 'typescript/unstable/ast/factory';
import {
isMethodDeclaration,
createSimpleMethod,
findMethodDeclarations,
getMethodInfo,
SyntaxKind
} from '../src/index.mjs';
// Contract 1: isMethodDeclaration returns true for MethodDeclaration AST nodes created with factory.createMethodDeclaration
{
const method = createSimpleMethod('calculateTotal', ['price', 'tax']);
assert.strictEqual(isMethodDeclaration(method), true, 'Method declaration should satisfy isMethodDeclaration');
assert.strictEqual(method.kind, SyntaxKind.MethodDeclaration, 'Kind should be SyntaxKind.MethodDeclaration');
assert.strictEqual(method.name.text, 'calculateTotal', 'Method name should match');
assert.strictEqual(method.parameters.length, 2, 'Should have 2 parameters');
assert.ok(method.body, 'Method should have a body block');
}
// Contract 2: isMethodDeclaration returns false for other AST nodes such as Identifier, Block, ParameterDeclaration, and PropertyDeclaration
{
const idNode = createIdentifier('calculateTotal');
assert.strictEqual(isMethodDeclaration(idNode), false, 'Identifier should not be a MethodDeclaration');
const blockNode = createBlock([], true);
assert.strictEqual(isMethodDeclaration(blockNode), false, 'Block should not be a MethodDeclaration');
const paramNode = createParameterDeclaration(undefined, undefined, createIdentifier('x'), undefined, undefined, undefined);
assert.strictEqual(isMethodDeclaration(paramNode), false, 'ParameterDeclaration should not be a MethodDeclaration');
const propNode = createPropertyDeclaration(undefined, createIdentifier('count'), undefined, undefined, undefined);
assert.strictEqual(isMethodDeclaration(propNode), false, 'PropertyDeclaration should not be a MethodDeclaration');
}
// Contract 3: isMethodDeclaration returns false for plain objects with different kind values
{
const fakeIdentifier = { kind: SyntaxKind.Identifier, text: 'test' };
assert.strictEqual(isMethodDeclaration(fakeIdentifier), false, 'Object with Identifier kind should return false');
const fakeBlock = { kind: SyntaxKind.Block };
assert.strictEqual(isMethodDeclaration(fakeBlock), false, 'Object with Block kind should return false');
}
// Contract 4: findMethodDeclarations extracts and filters only method declarations from class declaration members
{
const method1 = createSimpleMethod('start');
const method2 = createSimpleMethod('stop');
const prop = createPropertyDeclaration(undefined, createIdentifier('status'), undefined, undefined, undefined);
const classDecl = createClassDeclaration(
undefined,
createIdentifier('Service'),
undefined,
undefined,
[method1, prop, method2]
);
const methods = findMethodDeclarations(classDecl);
assert.strictEqual(methods.length, 2, 'Should extract exactly 2 methods');
assert.strictEqual(methods[0], method1, 'First method should match method1');
assert.strictEqual(methods[1], method2, 'Second method should match method2');
assert.deepStrictEqual(findMethodDeclarations(null), [], 'Null input should return empty array');
assert.deepStrictEqual(findMethodDeclarations({}), [], 'Empty object should return empty array');
}
// Contract 5: getMethodInfo retrieves name, parameter count, and body presence from validated MethodDeclaration nodes and throws TypeError for non-method nodes
{
const method = createSimpleMethod('execute', ['input', 'options']);
const info = getMethodInfo(method);
assert.deepStrictEqual(info, {
name: 'execute',
parameterCount: 2,
hasBody: true
}, 'Method info should match expected structure');
const idNode = createIdentifier('invalid');
assert.throws(
() => getMethodInfo(idNode),
{
name: 'TypeError',
message: 'Expected an AST MethodDeclaration node'
},
'Should throw TypeError when passed non-method AST node'
);
assert.throws(
() => getMethodInfo(null),
{
name: 'TypeError',
message: 'Expected an AST MethodDeclaration node'
},
'Should throw TypeError when passed null'
);
}
console.log('Contract test passed successfully.');
오리진 시더
익명