On 31 October 2013 09:14, Siman007 <
willc...@googlemail.com> wrote:
> Hi I created the following blocks to add javascript comments
Very nice. I think this is superior to the current comment bubbles.
If it were up to me I'd switch, but when we tried, there was strong
push-back from existing users. I'm still deciding whether this is a
battle that's worth fighting.
> and to inject pure code into the javascript file (i.e. whatever you type is injected into the javascript verbatim)
Hmm. This is an idea that's been discussed for years. The giant
stumbling block is that variables defined in Blockly are often renamed
when code is generated. Thus one is not sure what the variable and
function names are. Consider that Blockly allows a variable named
'+'. Solving this properly requires some interesting parsers.
> Both are very similar blocks BUT both suffer from the same problem i.e. the JavaScript produced
> always has a ';' appended at the end of the line of code - is there a way to prevent this?
Yes. The offending code is Blockly.JavaScript.scrubNakedValue. It
should only kick in if one is generating code from a top-level block
(not part of a program), that has a left output tab
(Blockly.Generator.prototype.workspaceToCode).
This should not apply to your comment block, so there is no reason you
should see a semicolon on code generated from this block. On the
other hand, if your code injection block does have a left output. If
it is not connected to other blocks and is orphaned on the workspace,
then it will have a semicolon appended (which is a good thing).
Please take another look at your code and verify what you are seeing. Thanks!
> return [code, Blockly.JavaScript.ORDER_ATOMIC];
Please change this to Blockly.JavaScript.ORDER_NONE. Otherwise
enclosing code may rip apart your code due to order of operations.
You have no idea what the minimum bond strength of your user's code
is, so to be safe you have to state that it has no cohesion.
--
Neil Fraser
http://neil.fraser.name