CodeSampleX

샘플

@typescript-eslint/typescript-estree 8.65.0: AST_TOKEN_TYPES

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

sha256:3c6cf2554c146d72e47ae2ded01d1728d45bada7f09f7961833d28abc7ae3f3e

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

케이스

HOW
목표
verify @typescript-eslint/typescript-estree.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/typescript-estree@8.65.0
패키지
심벌
  • @typescript-eslint/typescript-estree.AST_TOKEN_TYPES
환경
node 22.23.2
생성일
2026-09-05T15:01:02Z

컨트랙트

  1. AST_TOKEN_TYPES provides enum mappings for standard JavaScript token types
  2. AST_TOKEN_TYPES provides enum mappings for JSX and TypeScript extension token types
  3. AST_TOKEN_TYPES provides enum mappings for comment token types
  4. parse with tokens enabled produces tokens whose type properties match AST_TOKEN_TYPES values
  5. parse with comments enabled produces comment tokens whose type properties match AST_TOKEN_TYPES values
  6. isASTTokenType accurately validates recognized AST_TOKEN_TYPES and rejects invalid types
  7. categorizeTokenType groups token types into syntax categories

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 @typescript-eslint/typescript-estree.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/typescript-estree@8.65.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/typescript-estree@8.65.0
Demonstrate these symbols/APIs:
  - @typescript-eslint/typescript-estree.AST_TOKEN_TYPES
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:5afde80aa8c754d05488c4b4a08d82fae583b9bf6630873ed02c3487fee0847b","constraints":{"executionContext":"node"},"contract":["AST_TOKEN_TYPES provides enum mappings for standard JavaScript token types","AST_TOKEN_TYPES provides enum mappings for JSX and TypeScript extension token types","AST_TOKEN_TYPES provides enum mappings for comment token types","parse with tokens enabled produces tokens whose type properties match AST_TOKEN_TYPES values","parse with comments enabled produces comment tokens whose type properties match AST_TOKEN_TYPES values","isASTTokenType accurately validates recognized AST_TOKEN_TYPES and rejects invalid types","categorizeTokenType groups token types into syntax categories"],"goal":"verify @typescript-eslint/typescript-estree.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/typescript-estree@8.65.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/typescript-estree@8.65.0"],"schemaVersion":1,"symbols":["@typescript-eslint/typescript-estree.AST_TOKEN_TYPES"]},"contractCommand":["node","test/contract.mjs"],"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/typescript-estree@8.65.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/typescript-estree@8.65.0","symbols":["@typescript-eslint/typescript-estree.AST_TOKEN_TYPES"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-typescript-estree-ast-token-types",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-typescript-estree-ast-token-types",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@typescript-eslint/typescript-estree": "8.65.0"
      }
    },
    "node_modules/@typescript-eslint/project-service": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.65.0.tgz",
      "integrity": "sha512-SxnPhbTsGahizDgbu7oqFH/xVtzIqMd/s+WtnSxNxJZJpLbdT5IPdzg8EZxO3+PoKahXmwJLeNQOpKJb3/bi7Q==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/tsconfig-utils": "^8.65.0",
        "@typescript-eslint/types": "^8.65.0",
        "debug": "^4.4.3"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4 <6.1.0"
      }
    },
    "node_modules/@typescript-eslint/tsconfig-utils": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.65.0.tgz",
      "integrity": "sha512-j6GzGqCiRdA7Qhur2VVmKZAkBLfnHFQfx4TaJGL9RMveZqCo48jSHHO0DTgizEnGhtWnqmbtCUSrqSkdiY/0Hg==",
      "license": "MIT",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4 <6.1.0"
      }
    },
    "node_modules/@typescript-eslint/types": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz",
      "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==",
      "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/typescript-estree": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.65.0.tgz",
      "integrity": "sha512-JboAE2swaYt4tb1fHhHTABE2K+OLy09XfcTbhnk4Pw96f9dd2e9iYsJ28gBggHlo5z5x1rkyWvcPoTuNTd4oGg==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/project-service": "8.65.0",
        "@typescript-eslint/tsconfig-utils": "8.65.0",
        "@typescript-eslint/types": "8.65.0",
        "@typescript-eslint/visitor-keys": "8.65.0",
        "debug": "^4.4.3",
        "minimatch": "^10.2.2",
        "semver": "^7.7.3",
        "tinyglobby": "^0.2.15",
        "ts-api-utils": "^2.5.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4 <6.1.0"
      }
    },
    "node_modules/@typescript-eslint/visitor-keys": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz",
      "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.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/balanced-match": {
      "version": "4.0.4",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz",
      "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==",
      "license": "MIT",
      "engines": {
        "node": "18 || 20 || >=22"
      }
    },
    "node_modules/brace-expansion": {
      "version": "5.0.9",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz",
      "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^4.0.2"
      },
      "engines": {
        "node": "20 || >=22"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "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"
      }
    },
    "node_modules/fdir": {
      "version": "6.5.0",
      "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
      "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
      "license": "MIT",
      "engines": {
        "node": ">=12.0.0"
      },
      "peerDependencies": {
        "picomatch": "^3 || ^4"
      },
      "peerDependenciesMeta": {
        "picomatch": {
          "optional": true
        }
      }
    },
    "node_modules/minimatch": {
      "version": "10.2.6",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz",
      "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==",
      "license": "BlueOak-1.0.0",
      "dependencies": {
        "brace-expansion": "^5.0.8"
      },
      "engines": {
        "node": "18 || 20 || >=22"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/picomatch": {
      "version": "4.0.7",
      "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
      "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      },
      "funding": {
        "url": "https://github.com/sponsors/jonschlinkert"
      }
    },
    "node_modules/semver": {
      "version": "7.8.5",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
      "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/tinyglobby": {
      "version": "0.2.17",
      "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
      "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
      "license": "MIT",
      "dependencies": {
        "fdir": "^6.5.0",
        "picomatch": "^4.0.4"
      },
      "engines": {
        "node": ">=12.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/SuperchupuDev"
      }
    },
    "node_modules/ts-api-utils": {
      "version": "2.5.0",
      "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz",
      "integrity": "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA==",
      "license": "MIT",
      "engines": {
        "node": ">=18.12"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4"
      }
    },
    "node_modules/typescript": {
      "version": "6.0.3",
      "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
      "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
      "license": "Apache-2.0",
      "peer": true,
      "bin": {
        "tsc": "bin/tsc",
        "tsserver": "bin/tsserver"
      },
      "engines": {
        "node": ">=14.17"
      }
    }
  }
}
package.json
{
  "name": "sample-typescript-estree-ast-token-types",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @typescript-eslint/typescript-estree.AST_TOKEN_TYPES",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "@typescript-eslint/typescript-estree": "8.65.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/typescript-estree.AST_TOKEN_TYPES in pkg:npm/%40typescript-eslint/typescript-estree@8.65.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/typescript-estree@8.65.0"
  ],
  "symbols": [
    "@typescript-eslint/typescript-estree.AST_TOKEN_TYPES"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { AST_TOKEN_TYPES, parse } = require('@typescript-eslint/typescript-estree');

const TOKEN_TYPE_SET = new Set(Object.values(AST_TOKEN_TYPES));

/**
 * Validates whether a given string is a recognized AST_TOKEN_TYPES value.
 * @param {unknown} type
 * @returns {boolean}
 */
function isASTTokenType(type) {
  return typeof type === 'string' && TOKEN_TYPE_SET.has(type);
}

/**
 * Extracts tokens and comments from source code using typescript-estree.
 * @param {string} code
 * @param {object} [options]
 * @returns {{ tokens: Array<object>, comments: Array<object> }}
 */
function tokenizeCode(code, options = {}) {
  const ast = parse(code, {
    tokens: true,
    comment: true,
    loc: true,
    range: true,
    jsx: true,
    ...options,
  });
  return {
    tokens: ast.tokens || [],
    comments: ast.comments || [],
  };
}

/**
 * Categorizes a token type into higher-level syntactic groups.
 * @param {string} type
 * @returns {'literal' | 'identifier' | 'comment' | 'punctuator' | 'keyword' | 'template' | 'unknown'}
 */
function categorizeTokenType(type) {
  switch (type) {
    case AST_TOKEN_TYPES.Boolean:
    case AST_TOKEN_TYPES.Null:
    case AST_TOKEN_TYPES.Numeric:
    case AST_TOKEN_TYPES.String:
    case AST_TOKEN_TYPES.RegularExpression:
      return 'literal';
    case AST_TOKEN_TYPES.Identifier:
    case AST_TOKEN_TYPES.JSXIdentifier:
    case AST_TOKEN_TYPES.PrivateIdentifier:
      return 'identifier';
    case AST_TOKEN_TYPES.Block:
    case AST_TOKEN_TYPES.Line:
      return 'comment';
    case AST_TOKEN_TYPES.Punctuator:
      return 'punctuator';
    case AST_TOKEN_TYPES.Keyword:
      return 'keyword';
    case AST_TOKEN_TYPES.Template:
    case AST_TOKEN_TYPES.JSXText:
      return 'template';
    default:
      return 'unknown';
  }
}

module.exports = {
  AST_TOKEN_TYPES,
  isASTTokenType,
  tokenizeCode,
  categorizeTokenType,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  AST_TOKEN_TYPES,
  isASTTokenType,
  tokenizeCode,
  categorizeTokenType,
} = require('../src/index.js');

// 1. AST_TOKEN_TYPES provides enum mappings for standard JavaScript token types
assert.equal(AST_TOKEN_TYPES.Boolean, 'Boolean');
assert.equal(AST_TOKEN_TYPES.Identifier, 'Identifier');
assert.equal(AST_TOKEN_TYPES.Keyword, 'Keyword');
assert.equal(AST_TOKEN_TYPES.Null, 'Null');
assert.equal(AST_TOKEN_TYPES.Numeric, 'Numeric');
assert.equal(AST_TOKEN_TYPES.Punctuator, 'Punctuator');
assert.equal(AST_TOKEN_TYPES.RegularExpression, 'RegularExpression');
assert.equal(AST_TOKEN_TYPES.String, 'String');
assert.equal(AST_TOKEN_TYPES.Template, 'Template');

// 2. AST_TOKEN_TYPES provides enum mappings for JSX and TypeScript extension token types
assert.equal(AST_TOKEN_TYPES.JSXIdentifier, 'JSXIdentifier');
assert.equal(AST_TOKEN_TYPES.JSXText, 'JSXText');
assert.equal(AST_TOKEN_TYPES.PrivateIdentifier, 'PrivateIdentifier');

// 3. AST_TOKEN_TYPES provides enum mappings for comment token types
assert.equal(AST_TOKEN_TYPES.Block, 'Block');
assert.equal(AST_TOKEN_TYPES.Line, 'Line');

// 4. parse with tokens enabled produces tokens whose type properties match AST_TOKEN_TYPES values
const code = 'const num = 123; let str = "hello"; if (true) { null; /test/; class C { #field = 1; } } <Button>Click</Button>; `temp${num}`;';
const { tokens, comments } = tokenizeCode(code);

assert.ok(tokens.length > 0);
for (const token of tokens) {
  assert.ok(isASTTokenType(token.type), `Expected valid AST_TOKEN_TYPES but got ${token.type}`);
}

const tokenTypes = new Set(tokens.map((t) => t.type));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Keyword));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Identifier));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Punctuator));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Numeric));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.String));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Boolean));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Null));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.RegularExpression));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.PrivateIdentifier));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.JSXIdentifier));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.JSXText));
assert.ok(tokenTypes.has(AST_TOKEN_TYPES.Template));

// 5. parse with comments enabled produces comment tokens whose type properties match AST_TOKEN_TYPES values
const commentedCode = '/* multi-line block comment */\n// single-line comment\nconst x = 1;';
const resultWithComments = tokenizeCode(commentedCode);
assert.equal(resultWithComments.comments.length, 2);
assert.equal(resultWithComments.comments[0].type, AST_TOKEN_TYPES.Block);
assert.equal(resultWithComments.comments[1].type, AST_TOKEN_TYPES.Line);
assert.ok(isASTTokenType(resultWithComments.comments[0].type));
assert.ok(isASTTokenType(resultWithComments.comments[1].type));

// 6. isASTTokenType accurately validates recognized AST_TOKEN_TYPES and rejects invalid types
assert.equal(isASTTokenType(AST_TOKEN_TYPES.Identifier), true);
assert.equal(isASTTokenType(AST_TOKEN_TYPES.Keyword), true);
assert.equal(isASTTokenType('InvalidTokenType'), false);
assert.equal(isASTTokenType(null), false);
assert.equal(isASTTokenType(123), false);

// 7. categorizeTokenType groups token types into syntax categories
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Numeric), 'literal');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.String), 'literal');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Boolean), 'literal');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Null), 'literal');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.RegularExpression), 'literal');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Identifier), 'identifier');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.JSXIdentifier), 'identifier');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.PrivateIdentifier), 'identifier');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Block), 'comment');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Line), 'comment');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Punctuator), 'punctuator');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Keyword), 'keyword');
assert.equal(categorizeTokenType(AST_TOKEN_TYPES.Template), 'template');
assert.equal(categorizeTokenType('NonExistent'), 'unknown');

오리진 시더

익명