Skip to content

Commit 23d767c

Browse files
authored
Added initial blog for JSeditor updates (#159)
* Added initial blog for JSeditor updates * Small changes to blogpost * wording changes * Added paragraph emphasizing importance of learning to debug and problem solve, not just learning to program
1 parent 1ddc5f0 commit 23d767c

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
334 KB
Loading
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "JavaScript Editor Updates and Future Features"
3+
excerpt: "Overview of changes being made to the JavaScript editor tool in MusicBlocks v3, and future plans"
4+
category: "DEVELOPER NEWS"
5+
date: "2025-05-20"
6+
slug: "JSeditor-updates"
7+
author: "Elwin Li"
8+
description: "GSoC Contributor"
9+
tags: "gsoc, javaScript editor, development, contribution, debugger"
10+
---
11+
12+
This is the first update report on the MusicBlocks JavaScript editor enhancement project for
13+
GSoC 2025. This and future reports will discuss the progress and future plans for the improvement
14+
of user experience and features for the editor.
15+
16+
## Contents
17+
- Upcoming Features
18+
- Motivation
19+
- JavaScript to Music Blocks
20+
- Debugger
21+
- Syntax highlighting
22+
23+
---
24+
25+
### Upcoming Features
26+
This project aims to significantly enhance the JavaScript editor within Sugar Labs'
27+
MusicBlocks environment. By implementing translation from JavaScript code to
28+
MusicBlocks visual blocks, users will gain a powerful tool for iterative learning and code
29+
exploration. Additionally, the project will introduce a JavaScript visualizer for step-by-step
30+
debugging and syntax highlighting to improve the editor's usability and appeal to young
31+
learners. This upgrade will bridge the gap between visual programming and text-based coding,
32+
promoting a deeper understanding of real programming and empowering kids to debug
33+
effectively.
34+
35+
### Motivation
36+
I believe that kids cannot learn to
37+
code without coding. Although they can learn the concept of coding through MusicBlocks, they
38+
still cannot learn text-based coding effectively. The JavaScript-to-MusicBlocks conversion feature
39+
will enable them to better transition between visual block-based programming and
40+
textual JavaScript coding. This promotes a deeper understanding of programming concepts and
41+
has kids learn them more effectively.
42+
43+
Even more important than learning how to code is learning how to problem solve. Debugging and
44+
problem solving skills provide kids with the knowledge to overcome problems of any kind, not
45+
just in programming. With the step by step debugger, kids will learn how to break a problem down, and
46+
identify where problems are and track them.
47+
48+
### JavaScript to Music Blocks
49+
The JavaScript to Music Blocks feature is fairly simple as an end product: implementing the ability
50+
for users to convert the JavaScript code in the editor to music blocks. The execution of this feature
51+
is less simple. Currently, I have implemented support for all blocks from the rhythm, flow, number, and boolean palettes. There is also support for a few blocks from the pitch, tone, and action palettes. These implementations can be seen with the [first PR](https://github.com/sugarlabs/musicblocks/pull/4591) and the [second PR](https://github.com/sugarlabs/musicblocks/pull/4692).
52+
53+
This was all done using the following process:
54+
55+
1. Using the [acorn parser library](https://github.com/acornjs/acorn), convert the input code by the user in the editor into an
56+
[**Abstract Syntax Tree**](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST)
57+
2. Convert the AST into a custom intermediate representation
58+
- In this case, it is a simpler tree consisting of all the different blocks that the code creates
59+
- For each block in the intermediate tree, there is information on its type, arguments, children, and/or value if it has one
60+
3. Convert the intermediate tree into a blocklist
61+
- MusicBlocks generate blocks using the representation of a list of blocks, which are mostly in the form of
62+
[id, name, x, y, [connections]]
63+
- Carefully parsing through the intermediate tree and dealing with the connections produce a list of such blocks,
64+
which MusicBlocks will then load into the visual programming blocks
65+
- The connections are made during the process of creating the blocks.
66+
- For each block, if it has arguments, they will be created and connected with the block
67+
- Then its children are created and connected to each other
68+
- Finally the first child is then connected back to the block itself
69+
- During this process, vertical sizes of arguments are kept track of to insert the necessary amount of vertical spacers before the children
70+
71+
Although this process is proven to work very well as shown by the [merged PR](https://github.com/sugarlabs/musicblocks/pull/4591),
72+
adding future blocks is not yet as simple as it can be.
73+
74+
Thus, I am currently working on refactoring the code to use JSON config files to store pairs of AST to block mappings, which would
75+
make adding new blocks an extremely quick and trivial process. The next report may go into more details on this.
76+
77+
### Debugger
78+
The JavaScript editor debugger will be a tool located as a separate tab within the console space. I plan on implementing this tool as part of GSoC this summer. Although currently unavailable, I have created a simple design as to what it may look like.
79+
![JSeditor debugger](/assets/post-assets/debugger.png)
80+
81+
The debugger will have the following functionalities:
82+
- Ability to set one or multiple breakpoints
83+
- Have the state of all variables at breakpoints
84+
- Show function call frames
85+
- User can run program all the way to the next breakpoint (stops in order until user goes to next one)
86+
- User can step forward line by line or evaluate by unit
87+
88+
### Syntax Highlighting
89+
A good IDE or code editor will always have syntax highlighting. This makes the environment easier and more fun to work with. Thus,
90+
this feature will also be added to the JavaScript editor in MusicBlocks. Although this also has not been implemented yet, I foresee this
91+
part of the project being the fastest, as there are many established libraries that can provide syntax highlighting. Some candidates may include highlight.js, and CodeJar.
92+
93+
---
94+
95+
This concludes the first report on the MusicBlocks JavaScript editor enhancement project for GSoC 2025. Thanks for reading, and more updates will come soon!

0 commit comments

Comments
 (0)