Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ goog.require('Blockly.Blocks');
goog.require('Blockly.Comment');
goog.require('Blockly.Connection');
goog.require('Blockly.Extensions');
goog.require('Blockly.Generator');
goog.require('Blockly.Input');
goog.require('Blockly.Mutator');
goog.require('Blockly.Warning');
Expand All @@ -52,6 +53,14 @@ goog.require('goog.string');
* @constructor
*/
Blockly.Block = function(workspace, prototypeName, opt_id) {
if (typeof Blockly.Generator.prototype[prototypeName] !== 'undefined') {
console.warn('FUTURE ERROR: Block prototypeName "' + prototypeName
+ '" conflicts with Blockly.Generator members. Registering Generators '
+ 'for this block type will incur errors.'
+ '\nThis name will be DISALLOWED (throwing an error) in future '
+ 'versions of Blockly.');
}

/** @type {string} */
this.id = (opt_id && !workspace.getBlockById(opt_id)) ?
opt_id : Blockly.utils.genUid();
Expand Down
29 changes: 24 additions & 5 deletions core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) {
line = line[0];
}
if (line) {
if (block.outputConnection && this.scrubNakedValue) {
if (block.outputConnection) {
// This block is a naked value. Ask the language's code generator if
// it wants to append a semicolon, or something.
line = this.scrubNakedValue(line);
Expand Down Expand Up @@ -380,7 +380,11 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) {
* names.
* @param {!Blockly.Workspace} workspace Workspace to generate code from.
*/
Blockly.Generator.prototype.init = undefined;
Blockly.Generator.prototype.init = function(
/* eslint-disable no-unused-vars */ workspace
/* eslint-enable no-unused-vars */) {
// Optionally override
};

/**
* Common tasks for generating code from blocks. This is called from
Expand All @@ -393,7 +397,12 @@ Blockly.Generator.prototype.init = undefined;
* @return {string} JavaScript code with comments and subsequent blocks added.
* @private
*/
Blockly.Generator.prototype.scrub_ = undefined;
Blockly.Generator.prototype.scrub_ = function(
/* eslint-disable no-unused-vars */ block, code
/* eslint-enable no-unused-vars */) {
// Optionally override
return code;
};

/**
* Hook for code to run at end of code generation.
Expand All @@ -402,7 +411,12 @@ Blockly.Generator.prototype.scrub_ = undefined;
* @param {string} code Generated code.
* @return {string} Completed code.
*/
Blockly.Generator.prototype.finish = undefined;
Blockly.Generator.prototype.finish = function(
/* eslint-disable no-unused-vars */ code
/* eslint-enable no-unused-vars */) {
// Optionally override
return code;
};

/**
* Naked values are top-level blocks with outputs that aren't plugged into
Expand All @@ -412,4 +426,9 @@ Blockly.Generator.prototype.finish = undefined;
* @param {string} line Line of generated code.
* @return {string} Legal line of code.
*/
Blockly.Generator.prototype.scrubNakedValue = undefined;
Blockly.Generator.prototype.scrubNakedValue = function(
/* eslint-disable no-unused-vars */ line
/* eslint-enable no-unused-vars */) {
// Optionally override
return line;
};