microsoft / microsoft/pxt-microbit
Blocks mode changes order of JavaScript functions and modifies comments
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
Arising from support ticket https://support.microbit.org/helpdesk/tickets/97465 (private)
Switching to blocks mode changes the order of JavaScript functions, and modifies comments.
The original example was some code created in JavaScript mode. Here is a very similar example:
https://makecode.microbit.org/_TasfM9biJgFx
After a round trip to Blocks mode and back, without any code modification, the JavaScript functions are reordered, and the global comments are changed to block specific ones.
I tried a simpler example, creating functions a b c d e f in that order. Whether I create then in Blocks mode or JavaScript, the involvement of Blocks mode seems to enforce the JavaScript order ecfbad. The commits in these GitHub repos record the steps.
https://github.com/martinwork/test-code-order-simple/ (starting in Blocks mode)
https://github.com/martinwork/test-code-order-simple-js2/ (starting in JavaScript mode)
To Reproduce
Steps to reproduce the behavior:
- Open https://makecode.microbit.org/_TasfM9biJgFx
- Click on Blocks
- Click on JavaScript
- See error
Expected behavior
Could the order after a mode switch be based on the order before?
And comments preserved?
Screenshots
Add screenshots to help explain your problem. You can copy paste the screenshot in the github report. The .gif screen recording is very useful as well.
micro:bit version (please complete the following information):
not hardware related ]
Desktop (please complete the following information):
- OS: [e.g. iOS] Windows 11
- Browser [e.g. chrome, safari] Chrome
- Version [e.g. 22] 145
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the round trip from Blocks to JavaScript with the linked MakeCode example and the simpler function-order repositories. Trace the mode-switch conversion and compare the source before and after switching modes. Done means function order follows the pre-switch order and global comments are preserved without code edits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100