Beispiel
typescript 7.0.2: formatSyntaxKind
Verifiziertes Beispiel für npm typescript 7.0.2: formatSyntaxKind. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.
sha256:2998b3201b504a2425cae1b5410e29b53db79f3a0bfc006676c4c7447277e8ba
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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 |
Fall
HOW- Ziel
- verify typescript.formatSyntaxKind in pkg:npm/typescript@7.0.2
- Pakete
- Symbole
-
- typescript.formatSyntaxKind
- Erstellt
- 2026-08-28T07:46:33Z
Contract
- formatKind returns the canonical string name for standard SyntaxKind enum values using formatSyntaxKind
- formatKind returns formatted Unknown representation for unrecognized numeric syntax kind values
- formatNodeKind extracts and formats the SyntaxKind of AST node objects using formatSyntaxKind
- formatTokenKinds formats an array of token kind numbers into an array of readable syntax kind names
- inspectAndFormatTokens scans source code and attaches formatted syntax kind names to tokens
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Quelltext
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.formatSyntaxKind 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.formatSyntaxKind
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:9bbbc617666757c59950c19a6a6db1d6e61d195f1ec8e6b123bdc6c5fa4e2d79","contract":["formatKind returns the canonical string name for standard SyntaxKind enum values using formatSyntaxKind","formatKind returns formatted Unknown representation for unrecognized numeric syntax kind values","formatNodeKind extracts and formats the SyntaxKind of AST node objects using formatSyntaxKind","formatTokenKinds formats an array of token kind numbers into an array of readable syntax kind names","inspectAndFormatTokens scans source code and attaches formatted syntax kind names to tokens"],"goal":"verify typescript.formatSyntaxKind in pkg:npm/typescript@7.0.2","kind":"HOW","packages":["pkg:npm/typescript@7.0.2"],"schemaVersion":1,"symbols":["typescript.formatSyntaxKind"]},"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.formatSyntaxKind"],"verifierAdapter":"node-typescript@1"}
{
"name": "typescript-formatsyntaxkind-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "typescript-formatsyntaxkind-sample",
"version": "1.0.0",
"license": "MIT-0",
"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": "typescript-formatsyntaxkind-sample",
"version": "1.0.0",
"description": "verify typescript.formatSyntaxKind in pkg:npm/typescript@7.0.2",
"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.formatSyntaxKind in pkg:npm/typescript@7.0.2",
"kind": "HOW",
"packages": [
"pkg:npm/typescript@7.0.2"
],
"symbols": [
"typescript.formatSyntaxKind"
]
}
import {
formatSyntaxKind,
SyntaxKind,
createScanner,
LanguageVariant,
} from 'typescript/unstable/ast';
/**
* Formats a numeric SyntaxKind value into its human-readable string representation.
*
* @param {number} kind - The SyntaxKind enum value or numeric kind.
* @returns {string} The formatted name of the syntax kind.
*/
export function formatKind(kind) {
return formatSyntaxKind(kind);
}
/**
* Extracts and formats the SyntaxKind from an AST node.
*
* @param {{ kind: number }} node - An AST node object with a numeric kind property.
* @returns {string} The formatted name of the AST node's syntax kind.
*/
export function formatNodeKind(node) {
if (!node || typeof node.kind !== 'number') {
throw new TypeError('Expected an AST node object with numeric kind property');
}
return formatSyntaxKind(node.kind);
}
/**
* Formats an array of numeric SyntaxKind values into an array of readable names.
*
* @param {number[]} kinds - Array of numeric SyntaxKind values.
* @returns {string[]} Array of formatted syntax kind names.
*/
export function formatTokenKinds(kinds) {
if (!Array.isArray(kinds)) {
throw new TypeError('Expected kinds to be an array of numbers');
}
return kinds.map((k) => formatSyntaxKind(k));
}
/**
* Scans source code and returns tokens enriched with formatted syntax kind names.
*
* @param {string} sourceText - Source code string to scan.
* @param {object} [options={}] - Scanning options.
* @param {boolean} [options.skipTrivia=true] - Whether to skip trivia tokens.
* @param {number} [options.languageVariant=LanguageVariant.Standard] - Language variant.
* @returns {Array<{ kind: number, kindName: string, text: string, start: number, end: number }>}
*/
export function inspectAndFormatTokens(sourceText, options = {}) {
const skipTrivia = options.skipTrivia !== false;
const languageVariant = options.languageVariant ?? LanguageVariant.Standard;
const scanner = createScanner(skipTrivia, languageVariant, sourceText);
const results = [];
let token;
while ((token = scanner.scan()) !== SyntaxKind.EndOfFile) {
results.push({
kind: token,
kindName: formatSyntaxKind(token),
text: scanner.getTokenText(),
start: scanner.getTokenStart(),
end: scanner.getTokenEnd(),
});
}
return results;
}
export { formatSyntaxKind, SyntaxKind, createScanner, LanguageVariant };
import assert from 'node:assert/strict';
import {
formatKind,
formatNodeKind,
formatTokenKinds,
inspectAndFormatTokens,
formatSyntaxKind,
SyntaxKind,
} from '../src/index.mjs';
// Contract 1: formatKind returns the canonical string name for standard SyntaxKind enum values using formatSyntaxKind
{
assert.strictEqual(formatKind(SyntaxKind.Unknown), 'Unknown');
assert.strictEqual(formatKind(SyntaxKind.Identifier), 'Identifier');
assert.strictEqual(formatKind(SyntaxKind.SourceFile), 'SourceFile');
assert.strictEqual(formatKind(SyntaxKind.FunctionDeclaration), 'FunctionDeclaration');
assert.strictEqual(formatKind(SyntaxKind.ReturnStatement), 'ReturnStatement');
assert.strictEqual(formatKind(SyntaxKind.NumericLiteral), 'NumericLiteral');
assert.strictEqual(formatKind(SyntaxKind.StringLiteral), 'StringLiteral');
assert.strictEqual(formatKind(SyntaxKind.PlusToken), 'PlusToken');
assert.strictEqual(formatKind(SyntaxKind.ExportKeyword), 'ExportKeyword');
}
// Contract 2: formatKind returns formatted Unknown representation for unrecognized numeric syntax kind values
{
const unknownCustomKind = 99999;
const formattedUnknown = formatKind(unknownCustomKind);
assert.strictEqual(formattedUnknown, 'Unknown(99999)');
const negativeKind = -5;
const formattedNegative = formatKind(negativeKind);
assert.strictEqual(formattedNegative, 'Unknown(-5)');
}
// Contract 3: formatNodeKind extracts and formats the SyntaxKind of AST node objects using formatSyntaxKind
{
const mockFuncNode = { kind: SyntaxKind.FunctionDeclaration, name: 'compute' };
const mockClassNode = { kind: SyntaxKind.ClassDeclaration, name: 'Calculator' };
const mockVarNode = { kind: SyntaxKind.VariableStatement };
const mockIfNode = { kind: SyntaxKind.IfStatement };
assert.strictEqual(formatNodeKind(mockFuncNode), 'FunctionDeclaration');
assert.strictEqual(formatNodeKind(mockClassNode), 'ClassDeclaration');
assert.strictEqual(formatNodeKind(mockVarNode), 'VariableStatement');
assert.strictEqual(formatNodeKind(mockIfNode), 'IfStatement');
assert.throws(() => formatNodeKind(null), { name: 'TypeError' });
assert.throws(() => formatNodeKind({}), { name: 'TypeError' });
}
// Contract 4: formatTokenKinds formats an array of token kind numbers into an array of readable syntax kind names
{
const kinds = [
SyntaxKind.ConstKeyword,
SyntaxKind.Identifier,
SyntaxKind.EqualsToken,
SyntaxKind.NumericLiteral,
SyntaxKind.SemicolonToken,
];
const formatted = formatTokenKinds(kinds);
assert.deepStrictEqual(formatted, [
'ConstKeyword',
'Identifier',
'EqualsToken',
'NumericLiteral',
'SemicolonToken',
]);
}
// Contract 5: inspectAndFormatTokens scans source code and attaches formatted syntax kind names to tokens
{
const code = 'export const total = 100;';
const tokens = inspectAndFormatTokens(code);
assert.ok(Array.isArray(tokens));
assert.strictEqual(tokens.length, 6);
const kindNames = tokens.map((t) => t.kindName);
assert.deepStrictEqual(kindNames, [
'ExportKeyword',
'ConstKeyword',
'Identifier',
'EqualsToken',
'NumericLiteral',
'SemicolonToken',
]);
const texts = tokens.map((t) => t.text);
assert.deepStrictEqual(texts, ['export', 'const', 'total', '=', '100', ';']);
}
console.log('All typescript.formatSyntaxKind contracts passed successfully.');
Ursprungs-Seeder
anonym