JavaScript won't translate back to blocks

JavaScript code generated from MakeCode blocks won’t always translate back to blocks. Is this a MakeCode defect or documented somewhere as expected behavior?

Details: I am using an Adafruit Circuit Playground Express and in a Firefox browser to program it. I had a problem in a larger program and reduced it to the following. Enter these blocks.
Switch to the JavaScript view and see this code.

let MyColors = [Colors.Red, Colors.Orange]
let MyNotes = [523, 587]
light.setPixelColor(0, MyColors[0])
music.playTone(MyNotes[0], music.beat(BeatFraction.Whole))

Going back and forth between Blocks and JavaScript at this point is no problem. Start a new empty project, go to the JavaScript view, and paste in the JavaScript. It simulates fine and all is well so far. But switch to the Blocks view and see the next image. I had to be quick with a screen capture to get the image because the warnings go away in a few seconds. (This is a separate issue – Why do the warnings go away soon after being displayed?)
Notice “” and “523” instead of “red” and “High C” as were seen before. Then trying to go back to the JavaScript view fails with “Oops, there is a problem converting your code.” The JavaScript can no longer be seen.

I can understand perhaps seeing in the block view that “red” and “High C” are replaced by their RGB and Hz values (similar to how JavaScript “0xff” becomes “255”). But it doesn’t seem right that JavaScript generated from MakeCode blocks gives errors (that then go away but are still really there) when converted back to blocks.

1 Like

Yep, this is a bug! Thanks for reporting it!

I have created a PR to fix the grey blocks here: