It's not throwing; it's logging a warning and going through a
different code path. But that's okay; I can set a breakpoint and get a
trace that way:
(anonymous)@VM177:1
Blockly.Names.getNameForUserVariable_@blockly_compressed.js:formatted:24568
Blockly.Names.getName@blockly_compressed.js:formatted:24574
Blockly.JavaScript.variables_set@javascript_compressed.js:95
Blockly.Generator.blockToCode@blockly_compressed.js:formatted:24450
Blockly.Generator.statementToCode@blockly_compressed.js:formatted:24499
Blockly.JavaScript.controls_if@javascript_compressed.js:41
Blockly.Generator.blockToCode@blockly_compressed.js:formatted:24450
(anonymous)@VM155:1
I'm using current git master, unmodified, and I can reproduce it using
demos/code/index.html. It doesn't happen with the demo as-is since the
demo only ever uses Blockly.JavaScript.workspaceToCode to generate
code, but the following steps reproduce it consistently:
1. Open the demo.
2. Create a variable named "foo".
3. Add a "set foo to" block to the workspace.
4. Attach a "123" block from Math.
5. Switch to the JavaScript tab. Observe that the code is generated correctly.
6. Return to the Workspace tab.
7. Open the Inspector console.
8. Execute this statement:
> Blockly.JavaScript.blockToCode(Blockly.mainWorkspace.topBlocks_[0])
9. Observe the warning:
> Deprecated call to Blockly.Names.prototype.getName without defining a variable map. To fix, add the folowing code in your generator's init() function:
> Blockly.YourGeneratorName.variableDB_.setVariableMap(workspace.getVariableMap());
10. Observe that the generated code uses a unique ID instead of the
human-readable variable name.
This is not limited to the JS generator; I can reproduce it with the
other generators as well.
Note that if you skip step 5, you instead get the following exception:
Uncaught TypeError: Cannot read property 'getName' of undefined at
Blockly.BlockSvg.Blockly.JavaScript.variables_set
(javascript_compressed.js:95) at Blockly.Generator.blockToCode
(blockly_compressed.js:1585) at <anonymous>:1:20
Blockly.JavaScript.variables_set@javascript_compressed.js:95
Blockly.Generator.blockToCode@blockly_compressed.js:1585
(anonymous)@VM410:1
On the other hand, if you skip step 5, but you invoke this statement:
> Blockly.JavaScript.init(Blockly.mainWorkspace)
before step 8, the warning does not trigger and the generated code is correct.
/s/ Adam
> --
> You received this message because you are subscribed to the Google Groups "Blockly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
blockly+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.