Okay so I see your point.
If you look carefully at how the Javascript generator works, it saves the function definitions in the Blockly.JavaScript.definitions_ list then prepends them onto the code.
If you notice here is where the code is stored in the definitions:
If you change line 60 to return code that will make our previous code work.
So this is where the definitions are read and output:
Hopefully that makes sense.
Here are the steps. Not really relevant, I just don't have the heart to delete them.
1) Clear all blocks (from console)
> Blockly.mainWorkspace.clear()
2) Load two blocks (from console)
var xml_text = '<xml xmlns="
http://www.w3.org/1999/xhtml"><block type="procedures_defnoreturn" x="90" y="64"><field name="NAME">foo</field><statement name="STACK"><block type="text_print"><value name="TEXT"><block type="text"><field name="TEXT">bar</field></block></value></block></statement></block><block type="controls_if" x="88" y="163"></block></xml>'
var xml = Blockly.Xml.textToDom(xml_text);
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
2) In the console get the top blocks (from console)
> var tb = Blockly.mainWorkspace.getTopBlocks()
3) Init JavaScript Generator (from console)
> Blockly.JavaScript.init(Blockly.mainWorkspace);
3) Try to generate code (from console)
> Blockly.JavaScript.blockToCode(tb[0])
""
> Blockly.JavaScript.blockToCode(tb[1])