Update to latest version.

This commit is contained in:
Neil Fraser
2014-09-08 14:26:52 -07:00
parent 58f264f4ce
commit d998a1c8ec
737 changed files with 29546 additions and 27625 deletions

View File

@@ -29,6 +29,10 @@ goog.provide('Blockly.JavaScript');
goog.require('Blockly.Generator');
/**
* JavaScript code generator.
* @type !Blockly.Generator
*/
Blockly.JavaScript = new Blockly.Generator('JavaScript');
/**
@@ -99,14 +103,6 @@ Blockly.JavaScript.ORDER_ASSIGNMENT = 16; // = += -= *= /= %= <<= >>= ...
Blockly.JavaScript.ORDER_COMMA = 17; // ,
Blockly.JavaScript.ORDER_NONE = 99; // (...)
/**
* Arbitrary code to inject into locations that risk causing infinite loops.
* Any instances of '%1' will be replaced by the block ID that failed.
* E.g. ' checkTimeout(%1);\n'
* @type ?string
*/
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
/**
* Initialise the database of variable names.
*/
@@ -117,23 +113,21 @@ Blockly.JavaScript.init = function() {
// to actual function names (to avoid collisions with user functions).
Blockly.JavaScript.functionNames_ = Object.create(null);
if (Blockly.Variables) {
if (!Blockly.JavaScript.variableDB_) {
Blockly.JavaScript.variableDB_ =
new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);
} else {
Blockly.JavaScript.variableDB_.reset();
}
var defvars = [];
var variables = Blockly.Variables.allVariables();
for (var x = 0; x < variables.length; x++) {
defvars[x] = 'var ' +
Blockly.JavaScript.variableDB_.getName(variables[x],
Blockly.Variables.NAME_TYPE) + ';';
}
Blockly.JavaScript.definitions_['variables'] = defvars.join('\n');
if (!Blockly.JavaScript.variableDB_) {
Blockly.JavaScript.variableDB_ =
new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);
} else {
Blockly.JavaScript.variableDB_.reset();
}
var defvars = [];
var variables = Blockly.Variables.allVariables();
for (var x = 0; x < variables.length; x++) {
defvars[x] = 'var ' +
Blockly.JavaScript.variableDB_.getName(variables[x],
Blockly.Variables.NAME_TYPE) + ';';
}
Blockly.JavaScript.definitions_['variables'] = defvars.join('\n');
};
/**
@@ -182,21 +176,16 @@ Blockly.JavaScript.quote_ = function(string) {
* @param {!Blockly.Block} block The current block.
* @param {string} code The JavaScript code created for this block.
* @return {string} JavaScript code with comments and subsequent blocks added.
* @this {Blockly.CodeGenerator}
* @private
*/
Blockly.JavaScript.scrub_ = function(block, code) {
if (code === null) {
// Block has handled code generation itself.
return '';
}
var commentCode = '';
// Only collect comments for blocks that aren't inline.
if (!block.outputConnection || !block.outputConnection.targetConnection) {
// Collect comment for this block.
var comment = block.getCommentText();
if (comment) {
commentCode += this.prefixLines(comment, '// ') + '\n';
commentCode += Blockly.JavaScript.prefixLines(comment, '// ') + '\n';
}
// Collect comments for all value arguments.
// Don't collect comments for nested statements.
@@ -204,15 +193,15 @@ Blockly.JavaScript.scrub_ = function(block, code) {
if (block.inputList[x].type == Blockly.INPUT_VALUE) {
var childBlock = block.inputList[x].connection.targetBlock();
if (childBlock) {
var comment = this.allNestedComments(childBlock);
var comment = Blockly.JavaScript.allNestedComments(childBlock);
if (comment) {
commentCode += this.prefixLines(comment, '// ');
commentCode += Blockly.JavaScript.prefixLines(comment, '// ');
}
}
}
}
}
var nextBlock = block.nextConnection && block.nextConnection.targetBlock();
var nextCode = this.blockToCode(nextBlock);
var nextCode = Blockly.JavaScript.blockToCode(nextBlock);
return commentCode + code + nextCode;
};