4.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Commands
npm run build # Compile TypeScript → es6/, lib/ (CommonJS), browser/
npm test # Prettier check + Jest (also runs build first via pretest)
npm run format # Auto-fix formatting with Prettier
Run a single test file:
npm test -- tests/unit/parser.spec.ts
Run tests matching a pattern:
npm test -- --testNamePattern "block with tags"
Architecture
comment-parser is a zero-dependency JSDoc comment parser. It converts /** */ comment strings into structured data and back (bidirectional).
Parse pipeline
raw source string
→ source-parser (splits into Line[] with Tokens per line)
→ block-parser (groups lines into description block + tag sections)
→ spec-parser (runs tokenizers on each tag section → Spec[])
→ Block[]
Each stage is independently configurable. The public parse(source, options) function wires them together.
Key data types (src/primitives.ts)
Block— one/** */comment; hasdescription,tags(Spec[]),source(Line[]),problemsSpec— one@tag; hastag,type,name,optional,default,description,sourceLine— a raw source line with itstokensTokens— fine-grained breakdown of a line:start,delimiter,postDelimiter,tag,postTag,type,postType,name,postName,description,end,lineEnd
Module layout
| Directory | Responsibility |
|---|---|
src/parser/ |
index.ts (factory), source-parser.ts, block-parser.ts, spec-parser.ts |
src/parser/tokenizers/ |
tag.ts, type.ts, name.ts, description.ts — each extracts one Tokens field |
src/stringifier/ |
Converts Block/Tokens back to source string; inspect.ts for debugging |
src/transforms/ |
Post-parse transformations: align, indent, crlf, composed via flow |
src/util.ts |
seedBlock, seedTokens, rewireSpecs, rewireSource helpers |
Customization points
Tokenizers and the source-line parser are injected via options, so callers can override any parsing step. Transforms are pure functions composed with transforms.flow(...).
Build outputs
es6/— ES modules (primary dev target, whatexports["."]points to for ESM consumers)lib/— CommonJS (.cjsextensions, generated byconvert-extension)browser/— IIFE bundle via Rollup
Playground
The live demo at https://syavorsky.github.io/comment-parser is hosted in a separate public repo: syavorsky/syavorsky.github.io, under the comment-parser/ directory. It is not auto-deployed from this repo — the bundled library is updated manually.
To update the playground to a new version, in the syavorsky/syavorsky.github.io repo:
cd syavorsky.github.io
./comment-parser/upgrade.sh <version> # e.g. ./comment-parser/upgrade.sh 1.4.5
This script:
- Installs the specified version of
comment-parserfrom npm - Copies
browser/index.jsandtests/e2e/examples.jsintocomment-parser/lib/ - Updates
comment-parser/lib/VERSION - Updates the version label in
comment-parser/index.html - Commits
package.json,package-lock.json, andcomment-parser/
Branching
Always work on a dedicated branch, never directly on main:
- GitHub issue →
issue-186/non-optional-defaults - Bug without an issue →
bug/short-description - Feature without an issue →
feature/short-description
Versioning & releases
PRs must include a changeset file or carry the skip-changeset label (enforced by CI).
npm run release:add is interactive and can't be automated. Instead, create the changeset file directly:
# .changeset/<random-name>.md
---
'comment-parser': patch
---
Description of the fix or change.
Use patch for bug fixes, minor for new features, major for breaking changes. The filename can be anything unique (e.g. use a random word combo).
Add the changeset file as a separate commit alongside the code changes.
Full release flow
npm run release:version # bumps version, updates CHANGELOG, commits
npm run release:publish # publishes to npm, pushes tags
After publishing, update the playground (see above).
CI tests against Node 20, 22, and 24.