Skip to content

Refactor/activity abc parser#7511

Draft
vanshika2720 wants to merge 1 commit into
sugarlabs:masterfrom
vanshika2720:refactor/activity-abc-parser
Draft

Refactor/activity abc parser#7511
vanshika2720 wants to merge 1 commit into
sugarlabs:masterfrom
vanshika2720:refactor/activity-abc-parser

Conversation

@vanshika2720

@vanshika2720 vanshika2720 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

refactor: extract ABC parser into js/activity/abc-parser.js

Description

This PR extracts all ABC-notation parsing logic from the monolithic:

js/activity.js

into a new dedicated module:

js/activity/abc-parser.js

This is a pure refactor and introduces:

  • No behavioral changes
  • No UX changes
  • No public API changes

The goal is to improve maintainability by separating a self-contained subsystem from the large Activity implementation.


Motivation

The current:

activity.js

file is approximately:

~8800 lines

long.

The ABC parser subsystem consists of:

  • parseABC
  • Four private helper functions

and spans roughly:

~580 lines

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:

js/activity/recorder.js

and helps reduce the size and complexity of the core Activity implementation.


Changes

File What changed
js/activity/abc-parser.js New module containing _adjustPitch, _abcToStandardValue, _createPitchBlocks, _searchIndexForMusicBlock, and setupActivityAbcParser()
js/activity.js Replaced ~580-line inline ABC parser implementation with a single setupActivityAbcParser(this); call. Added setupActivityAbcParser to the /* global */ declaration block
js/loader.js Added RequireJS path alias for activity/abc-parser and registered it as a dependency of the activity/activity shim
js/__tests__/activity_startup_recovery.test.js Added setupActivityAbcParser: () => {} no-op implementation for the VM sandbox used by startup recovery tests

New Module Structure

Created:

js/activity/abc-parser.js

The module now owns:

_adjustPitch()
_abcToStandardValue()
_createPitchBlocks()
_searchIndexForMusicBlock()
setupActivityAbcParser()

The exported setup function attaches:

parseABC()

to the Activity instance during initialization.


Activity Integration

The previous inline parser implementation was removed from:

js/activity.js

and replaced with:

setupActivityAbcParser(this);

This preserves existing behavior while reducing constructor complexity.


Loader Updates

Updated:

js/loader.js

to:

  • Register the new activity/abc-parser path alias
  • Add activity/abc-parser as a dependency of the Activity shim

This ensures the parser module is available before Activity initialization.


Test Updates

Updated:

js/__tests__/activity_startup_recovery.test.js

The test executes a sliced portion of activity.js inside a VM sandbox.

Because the new call:

setupActivityAbcParser(this);

appears inside the tested slice, a no-op implementation was added:

setupActivityAbcParser: () => {}

to preserve existing test behavior.


What is preserved

The following remain completely unchanged:

Public API

this.parseABC(tune)

remains available on the Activity instance exactly as before.


ABC Import Workflow

The complete ABC import pipeline remains unchanged:

abcReader.onload
    ↓
ensureABCJS
    ↓
ABCJS.parseOnly
    ↓
this.parseABC

Generated Block Structure

The generated Music Blocks structure remains identical.

No parsing logic was modified.

No algorithmic behavior was changed.


User Experience

There are:

  • No UI changes
  • No workflow changes
  • No import behavior changes

Users will experience identical functionality before and after this refactor.


Why this is safe

This PR is a pure code organization refactor.

It:

  • Extracts existing code without changing logic
  • Preserves all public interfaces
  • Preserves Activity initialization behavior
  • Preserves ABC import functionality
  • Maintains compatibility with existing tests

The only goal is improved maintainability and clearer separation of concerns within the Activity subsystem.
-[x] Documentation

@github-actions github-actions Bot added documentation Updates to docs, comments, or README size/XXL XXL: 1000+ lines changed area/javascript Changes to JS source files area/tests Changes to test files labels Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🧪 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%
Master Coverage: Statements: 48.36% | Branches: 40.07% | Functions: 53.05% | Lines: 48.75%

@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with master.

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

Tip: Enable "Allow edits from maintainers" on this PR so we can auto-rebase for you next time. This only grants access to your PR branch. Your fork's other branches are not affected.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 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%
Master Coverage: Statements: 48.36% | Branches: 40.06% | Functions: 53.04% | Lines: 48.75%

@vanshika2720 vanshika2720 force-pushed the refactor/activity-abc-parser branch from 61710d9 to b1a4c6c Compare June 12, 2026 18:07
@github-actions

Copy link
Copy Markdown
Contributor

🧪 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%
Master Coverage: Statements: 48.36% | Branches: 40.06% | Functions: 53.04% | Lines: 48.75%

@vanshika2720 vanshika2720 force-pushed the refactor/activity-abc-parser branch from b1a4c6c to eb6ae96 Compare June 12, 2026 18:26
@github-actions

Copy link
Copy Markdown
Contributor

🧪 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%
Master Coverage: Statements: 48.36% | Branches: 40.06% | Functions: 53.04% | Lines: 48.75%

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).
@vanshika2720 vanshika2720 force-pushed the refactor/activity-abc-parser branch from eb6ae96 to 7f52e67 Compare June 12, 2026 18:43
@github-actions

Copy link
Copy Markdown
Contributor

🧪 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%
Master Coverage: Statements: 48.36% | Branches: 40.06% | Functions: 53.04% | Lines: 48.75%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files area/tests Changes to test files documentation Updates to docs, comments, or README needs-rebase size/XXL XXL: 1000+ lines changed

Projects

Development

Successfully merging this pull request may close these issues.

1 participant