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% |
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).
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% |
refactor: extract ABC parser into
js/activity/abc-parser.jsDescription
This PR extracts all ABC-notation parsing logic from the monolithic:
into a new dedicated module:
This is a pure refactor and introduces:
The goal is to improve maintainability by separating a self-contained subsystem from the large Activity implementation.
Motivation
The current:
file is approximately:
long.
The ABC parser subsystem consists of:
parseABCand spans roughly:
of code.
Because the parser is a self-contained feature with well-defined responsibilities, it does not need to live inline inside the Activity constructor.
This refactor follows the same modularization pattern already used for:
and helps reduce the size and complexity of the core Activity implementation.
Changes
js/activity/abc-parser.js_adjustPitch,_abcToStandardValue,_createPitchBlocks,_searchIndexForMusicBlock, andsetupActivityAbcParser()js/activity.jssetupActivityAbcParser(this);call. AddedsetupActivityAbcParserto the/* global */declaration blockjs/loader.jsactivity/abc-parserand registered it as a dependency of theactivity/activityshimjs/__tests__/activity_startup_recovery.test.jssetupActivityAbcParser: () => {}no-op implementation for the VM sandbox used by startup recovery testsNew Module Structure
Created:
The module now owns:
The exported setup function attaches:
to the Activity instance during initialization.
Activity Integration
The previous inline parser implementation was removed from:
and replaced with:
This preserves existing behavior while reducing constructor complexity.
Loader Updates
Updated:
to:
activity/abc-parserpath aliasactivity/abc-parseras a dependency of the Activity shimThis ensures the parser module is available before Activity initialization.
Test Updates
Updated:
The test executes a sliced portion of
activity.jsinside a VM sandbox.Because the new call:
appears inside the tested slice, a no-op implementation was added:
to preserve existing test behavior.
What is preserved
The following remain completely unchanged:
Public API
remains available on the Activity instance exactly as before.
ABC Import Workflow
The complete ABC import pipeline remains unchanged:
Generated Block Structure
The generated Music Blocks structure remains identical.
No parsing logic was modified.
No algorithmic behavior was changed.
User Experience
There are:
Users will experience identical functionality before and after this refactor.
Why this is safe
This PR is a pure code organization refactor.
It:
The only goal is improved maintainability and clearer separation of concerns within the Activity subsystem.
-[x] Documentation