refactor: extract patterns.ts and placeholder-replacer.ts from index.ts#282
Open
Wolfvin wants to merge 1 commit into
Open
refactor: extract patterns.ts and placeholder-replacer.ts from index.ts#282Wolfvin wants to merge 1 commit into
Wolfvin wants to merge 1 commit into
Conversation
Extract regex patterns and PlaceholderReplacer class into dedicated modules, and decompose the monolithic spacingText method into well-named private methods. **Extracted modules:** - src/shared/patterns.ts — all 60+ regex patterns and character class constants - src/shared/placeholder-replacer.ts — PlaceholderReplacer class for content protection **Extracted private methods from Pangu.spacingText:** - applyPunctuationSpacing() — dots, periods, colons, tildes - applyQuoteSpacing() — double, single, curly quotes - applyHashSpacing() — hashtag/hash spacing with slash context - applyOperatorSpacing() — arithmetic and logical operators - applyComparisonOperatorSpacing() — < > operators - applyFilePathSpacing() — Unix/Windows path spacing - applySlashSpacing() — context-aware slash handling - applyBracketSpacing() — bracket spacing around CJK - fixBracketInnerSpacing() — inner bracket content cleanup **Verified by 3-layer regression proof:** 1. Regrets: All 8 clusters GREEN (5-run drift test stable) 2. Direct output: All 57 test cases match KEBENARAN 1 ground truth 3. Cross-check: All 8 fingerprints match KEBENARAN 2 Behavior is IDENTICAL — only structure changed, no logic modified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the monolithic
src/shared/index.ts(498 lines) into three well-structured modules with clear separation of concerns, while preserving 100% identical behavior.What Changed
Extracted Modules
src/shared/patterns.ts— All 60+ regex patterns and character class constants (CJK, AN, operators, brackets, quotes, file paths, etc.)src/shared/placeholder-replacer.ts—PlaceholderReplacerclass for protecting content during regex processingDecomposed
spacingText()into Private MethodsapplyPunctuationSpacing()applyQuoteSpacing()applyHashSpacing()applyOperatorSpacing()applyComparisonOperatorSpacing()applyFilePathSpacing()applySlashSpacing()applyBracketSpacing()fixBracketInnerSpacing()Regression Proof
This refactoring was validated using output-based regression testing (the Regrets skill) with a 3-layer verification:
Verification 1 — Regrets Fingerprints
All 8 behavioral clusters remained GREEN across 5-run drift tests.
Verification 2 — Direct Output Match
All 57 test cases produce output identical to the pre-refactor ground truth (KEBENARAN 1).
Verification 3 — Fingerprint Cross-Check
All 8 regenerated fingerprints match the pre-refactor fingerprint contract (KEBENARAN 2).
Existing Tests
All existing vitest test suites (30 test files, 60+ test cases) continue to pass.
Why This Refactoring?
index.tswas a monolith mixing pattern definitions, utility classes, and spacing logicpatterns.tswithout scrolling through 500 lines