mahoraga-mapper
v0.1.9
Published
AST-based code-to-event mapping for Mahoraga
Maintainers
Readme
mahoraga-mapper
AST-based CSS selector to source file mapping for Mahoraga.
Install
npm install mahoraga-mapperWhat It Does
Maps CSS selectors (from analytics events like rage clicks) to the exact source file, line, and column where the element is defined. Uses the TypeScript Compiler API to parse TSX/JSX ASTs.
Usage
import { FileSystemCodeMapper } from 'mahoraga-mapper';
const mapper = new FileSystemCodeMapper('./src');
await mapper.buildIndex('./src', ['**/*.tsx']);
const locations = mapper.resolve('.btn-submit');
// [{ filePath: 'src/components/Form.tsx', line: 42, column: 8 }]How It Works
- Scan — Parses TSX/JSX files via the TypeScript Compiler API
- Extract — Finds
className,id, anddata-*attributes in JSX elements - Index — Builds a selector-to-location map with file:line:column precision
- Resolve — Looks up any CSS selector against the index
Exports
FileSystemCodeMapper— Main class implementing theCodeMapperinterfacescanFile()— Low-level AST scanner for individual filesscanRoutes()— Route definition scanner for URL-to-component mappingbuildIndex()/buildAndSave()— Index construction utilities
