semver-analyzer-ts
TypeScript/JavaScript language plugin for the semver-analyzer. Implements the Language trait from semver-analyzer-core and provides complete TypeScript-specific analysis: API surface extraction, type canonicalization, diff parsing, test discovery, JSX/CSS diffing, manifest diffing, Konveyor rule generation, and report building.
Uses the OXC parser (a fast Rust-native JavaScript/TypeScript toolchain) for all AST operations.
Modules
extract -- API Surface Extraction
OxcExtractor extracts the public API surface from .d.ts declaration files using a multi-phase approach:
- Reachability analysis -- traces
export * fromre-export graphs fromindex.d.tsentry points - Global namespace scanning -- discovers
@types/*global namespace declarations - Import map building -- collects per-file imports, merges into a global import map
- Symbol extraction -- parses declarations with OXC, extracts functions, classes, interfaces, type aliases, enums, variables, namespaces, and re-exports
- Package/import path resolution -- sets npm package names and subpath entry point provenance
End-to-end flow via extract_at_ref(): creates a git worktree, detects the package manager, installs dependencies, runs tsc --declaration, then extracts from the generated .d.ts files.
canon -- Type Canonicalization
Normalizes type annotation strings so that structurally equivalent types compare as equal. Applies 6 rules on top of tsc --declaration output:
- Union/Intersection ordering -- sort members alphabetically, flatten nested
- Array syntax --
Array<T>toT[],ReadonlyArray<T>toreadonly T[] - Parenthesization -- remove unnecessary parens, keep required ones
- Whitespace -- collapse to single spaces, normalize object type formatting
- never/unknown absorption --
T | never=T,T & unknown=T, etc. - Import resolution -- normalize
React.X,X, andimport("react").Xto the same form
Implementation: wraps the type in type T = ...;, parses with OXC, walks the AST recursively.
diff_parser -- Changed Function Detection
TsDiffParser parses git diff between two refs to identify functions whose implementations changed. Filters to source files (skipping .d.ts, tests, configs, dist/), parses both versions with OXC, extracts all function-like declarations, and compares normalized bodies (stripped of comments and whitespace).
call_graph -- Same-File Call Graph
TsCallGraphBuilder detects callers within the same file using OXC. Supports direct calls, method calls (this.target()), HOF arguments (arr.map(target)), and HOC wrappers (React.forwardRef, React.memo). Uses whole-word boundary matching to avoid substring false positives.
test_analyzer -- Test Discovery and Assertion Diffing
TsTestAnalyzer discovers test files using 7 strategies:
- Sibling
.test.*files - Sibling
.spec.*files __tests__/directory (exact name match)__tests__/subdirectories- Parent-level
__tests__/directory - Parent component name inference (e.g.,
SliderStep.tsxfindsSlider.test.tsx) - Directory-level: all test files in the same
__tests__/directory
Assertion detection supports Jest/Vitest, Mocha/Chai, Node assert, and Testing Library patterns via 36+ regex patterns.
jsx_diff -- Deterministic JSX Diffing
Compares JSX render output between two function versions without LLM. Detects 5 categories:
- Element tags (DomStructure) -- added/removed HTML/component elements
- ARIA attributes (Accessibility) -- added/removed aria-* attributes
- Role attributes (Accessibility) -- changed role values
- CSS classes (CssClass) -- AST-aware extraction that skips JS identifiers
- Data attributes (DataAttribute) -- changed data-* attributes
css_scan -- CSS Variable/Class Scanning
Deterministic scanner for CSS custom property changes (--pf-v5-* to --pf-v6-*) and CSS class prefix changes (pf-v5-c-* to pf-v6-c-*).
manifest -- Package.json Diffing
Deterministic package.json diff engine checking 6 areas: entry points (main, module, types), module system ("type" field), exports map (subpath entries and conditions), peer dependencies, engine constraints, and bin entries.
konveyor -- Konveyor Rule Generation
Generates Konveyor migration rules from analysis reports. Key functions:
generate_rules()-- main rule generation from breaking API and behavioral changesgenerate_dependency_update_rules()--builtin.jsonrules for package dependency detectiongenerate_conformance_rules()-- rules for expected child component composition patternsgenerate_fix_guidance()-- per-rule fix strategies with confidence levelswrite_ruleset_dir()-- writesruleset.yamlandbreaking-changes.yamloutput
Re-exports all shared types from semver-analyzer-konveyor-core.
report -- Report Building
Builds AnalysisReport<TypeScript> from raw AnalysisResult<TypeScript>. Handles per-file change grouping, component summary aggregation, constant group detection, child component discovery, hierarchy delta enrichment, and package-level change aggregation.
worktree -- Git Worktree Management
WorktreeGuard provides RAII git worktree lifecycle management:
- Validates repo and ref
- Creates worktree via
git worktree add - Detects package manager (yarn, npm, pnpm) and installs dependencies
- Runs
tsc --declaration --emitDeclarationOnlywith monorepo-aware fallbacks - Cleans up on drop (even on panic)
language -- TypeScript Implementation
The TypeScript struct implements four core traits:
Language-- binds associated types (TsCategory,TsManifestChangeType,TsEvidence,TsReportData) and delegates to sub-modulesLanguageSemantics-- TypeScript-specific breaking-change rules (interface member addition semantics, React component family grouping, Props identity matching, union type parsing, Promise async detection)HierarchySemantics-- React component hierarchy analysisBodyAnalysisSemantics-- runs JSX diff and CSS scan on changed function bodies
Usage
use ;
use Language;
let ts = new;
// Extract API surface at a git ref
let surface = ts.extract?;
// Find changed functions between two refs
let changed = ts.parse_changed_functions?;
// Find test files for a source file
let tests = ts.find_tests?;
Dependencies
| Crate | Purpose |
|---|---|
semver-analyzer-core |
Shared traits and types |
semver-analyzer-konveyor-core |
Shared Konveyor rule types |
oxc_parser, oxc_ast, oxc_allocator, oxc_span |
Rust-native JS/TS parser |
serde, serde_json, serde_yaml |
Serialization |
clap |
CLI argument parsing |
anyhow, thiserror |
Error handling |
regex |
Test assertion detection and pattern matching |
chrono |
Timestamps |
tracing |
Structured logging |
License
Apache-2.0