Conversation
…ts & CI Agent-Logs-Url: https://github.com/phieri/callsign.js/sessions/a52a3f34-4c0e-4d57-a7c1-d917f769a375 Co-authored-by: phieri <12006381+phieri@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor callsign.js for correctness and performance improvements
Refactor callsign.js: regex correctness, boolean config, O(1) prefix lookup, tests & CI
Mar 28, 2026
Owner
|
@copilot the CI pipeline failed. Check logs and fix. |
…k.json) Agent-Logs-Url: https://github.com/phieri/callsign.js/sessions/a7d2215d-aeab-499e-af22-83bdec9029ad Co-authored-by: phieri <12006381+phieri@users.noreply.github.com>
Contributor
Author
Fixed in 69e2b6c. The CI workflow used |
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.
Several correctness and performance bugs in
src/callsign.js: accidental commas in regex character classes, a trailing-space hack for end-of-sentence matching, string-flag config comparisons, O(n) prefix scans, and unsafeinnerHTMLreads. No tests or CI existed to catch regressions.src/callsign.js[A-Z,\d]inSEARCH_REGEXandPARTS_REGEX; replace trailing\swith\b(handles end-of-sentence call signs, removes${text}hack)new RegExp(SEARCH_REGEX.source, 'g')instead of passing the RegExp object directlygetConfig()now returns real booleans; introducesDEFAULT_CONFIGconstant to avoid duplication between the no-element fallback and the dataset-parsed path(this.textContent || '').trim()instead ofthis.innerHTMLCallsign._reversePrefixMap(prefix→ISO) once fromPREFIX_TABLE;createFlagElementandisValidPrefixuse it instead ofArray.includesscansgetPhonetics: Rewritten asArray.from(letters).map(...).filter(Boolean).join(' ')— silently drops unknown characters rather than producing"undefined"in outputcustomElements.definewithcustomElements.getcheck; exposeCallsignonwindowfor test accessTests & CI
tests/callsign.test.js: New integration tests that importsrc/callsign.jsinto jsdom and exercisegetPhonetics,isValidPrefix, andsearchCallsignsDOM replacement against the real module.github/workflows/ci.yml: New workflow runningnpm run lint+npm teston Node 20package.json: Test script updated toNODE_OPTIONS=--experimental-vm-modules jestfor ESM supportOriginal prompt
Summary
This PR refactors src/callsign.js to fix correctness bugs, improve performance, and add tests + CI. Changes are focused and backwards-compatible for typical browser usage.
Problem & goals
Files to be changed / added
Implementation details (patch highlights)
Regex changes
Regex creation inside searchCallsigns
Config boolean coercion
Reverse prefix map
Accessibility and DOM
Tests: example test file (tests/callsign.test.js)
CI workflow
PR description
Please create a pull request in phieri/callsign.js implementing the listed changes, with a single commits (or a small logical set of commits) and include tests and a GitHub Actions workflow. Run lint and tests locally in the branch before opening the PR.
If anything is unclear or you want the changes split into multiple PRs (critical fixes first, then tests...
This pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.