Refactor/activity abc parser#7511
Conversation
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.36% | Branches: 40.05% | Functions: 53.02% | Lines: 48.74% |
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.3% | Functions: 53.24% | Lines: 48.92% |
61710d9 to
b1a4c6c
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.31% | Functions: 53.25% | Lines: 48.93% |
b1a4c6c to
eb6ae96
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.3% | Functions: 53.25% | Lines: 48.92% |
eb6ae96 to
7f52e67
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.3% | Functions: 53.25% | Lines: 48.92% |
7f52e67 to
db01350
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.29% | Functions: 53.25% | Lines: 48.92% |
db01350 to
b23d6ca
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.3% | Functions: 53.25% | Lines: 48.92% |
Move _adjustPitch, _abcToStandardValue, _createPitchBlocks, _searchIndexForMusicBlock, and parseABC out of activity.js and into a dedicated js/activity/abc-parser.js module. The new module follows the same AMD + guarded module.exports pattern as js/activity/recorder.js. setupActivityAbcParser(activityInstance) attaches this.parseABC to the activity instance, preserving the existing import workflow and public API without any UX changes. loader.js is updated with a path alias and a dep entry for activity/abc-parser so it is loaded before activity/activity. The activity_startup_recovery test sandbox is updated with a no-op setupActivityAbcParser so the vm slice of activity.js continues to evaluate without a ReferenceError. Additionally, add a unit test suite under js/activity/__tests__/abc-parser.test.js covering key scenarios to guarantee exact behavioral preservation. Verified: npm run lint (0 new errors), prettier --check (pass), npm test (5449/5449 pass).
b23d6ca to
3670c86
Compare
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 48.53% | Branches: 40.31% | Functions: 53.25% | Lines: 48.92% |
refactor: extract ABC parser into js/activity/abc-parser.js
Description
This PR extracts the ABC notation parser from
js/activity.jsinto a dedicated module:The goal is to improve maintainability and reduce the size and complexity of the Activity implementation by isolating the ABC import subsystem into its own file.
Motivation
The ABC parser previously lived inline inside
activity.js, which is one of the largest files in the codebase.The parser is a self-contained subsystem responsible for:
Moving this logic into a dedicated module follows the same modularization approach already used by other Activity subsystems and makes future maintenance easier.
Changes
New module
Created:
The module now contains:
_adjustPitch()_abcToStandardValue()_createPitchBlocks()_searchIndexForMusicBlock()setupActivityAbcParser()setupActivityAbcParser()attachesparseABC()to the Activity instance during initialization.Activity integration
Removed the inline ABC parser implementation from:
and replaced it with:
Loader updates
Updated:
to:
activity/abc-parserRequireJS pathTest updates
Updated:
with a no-op
setupActivityAbcParser()implementation required by the VM sandbox used in the test.Added:
to provide coverage for:
Defensive improvements
While extracting the parser, a small number of defensive checks were added around:
These guards prevent runtime failures caused by malformed or incomplete ABC data while preserving existing behavior for valid inputs.
Preserved behavior
The following remain unchanged:
this.parseABC(tune))Result
This refactor improves separation of concerns by moving the ABC parser into its own module while maintaining compatibility with the existing ABC import pipeline and adding test coverage around parser behavior.
-[x] Documentation
-[x] Tests