From eafc3cd0999b2235654d2acedfb91b87e238b51e Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 26 Jun 2018 18:19:01 -0700 Subject: [PATCH 01/78] Adding appropriate test values to number field test blocks (#1943) --- tests/playground.html | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/playground.html b/tests/playground.html index 745ba0cab..0b22f4a93 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -1131,10 +1131,18 @@ h1 { - - - - + + 123.456 + + + 123.456 + + + 123.456 + + + 60 + From 83855248a6f15dd1c97e73fa88847a9bcff6040c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 27 Jun 2018 14:32:40 -0700 Subject: [PATCH 02/78] Correctly adjust indices in colour tests --- tests/generators/colour.xml | 88 ++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/tests/generators/colour.xml b/tests/generators/colour.xml index bae853d4d..4f951d755 100644 --- a/tests/generators/colour.xml +++ b/tests/generators/colour.xml @@ -1,13 +1,18 @@ + + item + i + test colour picker + Describe this function... - - static colour - - + + static colour + + #ff6600 @@ -23,13 +28,14 @@ test rgb + Describe this function... - - from rgb - - + + from rgb + + @@ -81,6 +87,7 @@ test colour random + Describe this function... @@ -90,22 +97,22 @@ - item + item - - test name - - + + test name + + - item + item @@ -118,17 +125,17 @@ - - test name - - + + test name + + FIRST - item + item @@ -140,31 +147,35 @@ - i + i - 2 + 1 - 7 + 6 - - - test name - - TRUE + + + test name + + NEQ - - 0 + + + + -1 + + @@ -181,12 +192,16 @@ FROM_START - item + item - - i + + + + i + + @@ -210,13 +225,14 @@ test blend + Describe this function... - - blend - - + + blend + + From 28eb8317548fe4ada4a87a358434961bf6dee804 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 27 Jun 2018 14:35:49 -0700 Subject: [PATCH 03/78] Better error messages in colour generator tests --- tests/generators/colour.xml | 58 ++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/tests/generators/colour.xml b/tests/generators/colour.xml index 4f951d755..91178793d 100644 --- a/tests/generators/colour.xml +++ b/tests/generators/colour.xml @@ -104,8 +104,18 @@ - - test name + + + + + length of random colour string: + + + + + item + + @@ -125,8 +135,18 @@ - - test name + + + + + format of random colour string: + + + + + item + + @@ -162,8 +182,32 @@ TRUE - - test name + + + + + contents of random colour string: + + + + + item + + + + + at index: + + + + + + + i + + + + @@ -223,7 +267,7 @@ - + test blend Describe this function... From b4e54631955964eb2d1b3d43ba87248fc40001b6 Mon Sep 17 00:00:00 2001 From: "translatewiki.net" Date: Thu, 28 Jun 2018 07:18:22 +0200 Subject: [PATCH 04/78] Localisation updates from https://translatewiki.net. --- msg/json/bn.json | 3 ++- msg/json/nl.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/msg/json/bn.json b/msg/json/bn.json index 805085547..9148d1a55 100644 --- a/msg/json/bn.json +++ b/msg/json/bn.json @@ -6,7 +6,8 @@ "Tauhid16", "MasterMinhaz", "এম আবু সাঈদ", - "Rasal Lia" + "Rasal Lia", + "আফতাবুজ্জামান" ] }, "VARIABLES_DEFAULT_NAME": "পদ", diff --git a/msg/json/nl.json b/msg/json/nl.json index f9053d7c6..b5e010fbd 100644 --- a/msg/json/nl.json +++ b/msg/json/nl.json @@ -12,7 +12,8 @@ "Jeleniccz", "Festina90", "Optilete", - "Patio" + "Patio", + "KlaasZ4usV" ] }, "VARIABLES_DEFAULT_NAME": "item", From 999f8a114d0af4dbf6e437e56c7834c98ec2039f Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 29 Jun 2018 10:43:04 -0700 Subject: [PATCH 05/78] Remove variable IDs from colour test XML --- tests/generators/colour.xml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/generators/colour.xml b/tests/generators/colour.xml index 91178793d..747e54941 100644 --- a/tests/generators/colour.xml +++ b/tests/generators/colour.xml @@ -1,8 +1,4 @@ - - item - i - test colour picker Describe this function... @@ -97,7 +93,7 @@ - item + item @@ -113,7 +109,7 @@ - item + item @@ -122,7 +118,7 @@ - item + item @@ -144,7 +140,7 @@ - item + item @@ -155,7 +151,7 @@ FIRST - item + item @@ -167,7 +163,7 @@ - i + i 1 @@ -191,7 +187,7 @@ - item + item @@ -203,7 +199,7 @@ - i + i @@ -236,14 +232,14 @@ FROM_START - item + item - i + i From 13f7e75ffba2e9f7897b43c4c2f5ff92cdd200f8 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 17:22:01 -0700 Subject: [PATCH 06/78] Supress empty tag in XML. --- core/xml.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/xml.js b/core/xml.js index 34b3f3085..d8a62902d 100644 --- a/core/xml.js +++ b/core/xml.js @@ -44,8 +44,11 @@ goog.require('goog.dom'); */ Blockly.Xml.workspaceToDom = function(workspace, opt_noId) { var xml = goog.dom.createDom('xml'); - xml.appendChild(Blockly.Xml.variablesToDom( - Blockly.Variables.allUsedVarModels(workspace))); + var variablesElement = Blockly.Xml.variablesToDom( + Blockly.Variables.allUsedVarModels(workspace)); + if (variablesElement.hasChildNodes()) { + xml.appendChild(variablesElement); + } var comments = workspace.getTopComments(true); for (var i = 0, comment; comment = comments[i]; i++) { xml.appendChild(comment.toXmlWithXY(opt_noId)); From 1bd135c9a51ac86db49950b66f8fc8dec88d6115 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Mon, 2 Jul 2018 12:34:03 -0700 Subject: [PATCH 07/78] Updating NPM package version to 1.20180629.0-develop (#1962) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e6e3a7947..cf98b4b5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockly", - "version": "1.20180420.0-develop", + "version": "1.20180629.0-develop", "description": "Blockly is a library for building visual programming editors.", "main": "blockly_node_javascript_en.js", "keywords": [ From cf3f914be8a1acb611f5bb47687b9f85e0fc0690 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 3 Jul 2018 11:42:40 -0700 Subject: [PATCH 08/78] Moving TODOs out of jsdoc comments. (#1965) --- core/ws_comment_events.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/ws_comment_events.js b/core/ws_comment_events.js index dec55d8a4..0161c1fd5 100644 --- a/core/ws_comment_events.js +++ b/core/ws_comment_events.js @@ -191,9 +191,9 @@ Blockly.Events.CommentCreate.prototype.type = Blockly.Events.COMMENT_CREATE; /** * Encode the event as JSON. - * TODO (#1266): "Full" and "minimal" serialization. * @return {!Object} JSON representation. */ +// TODO(#1266): "Full" and "minimal" serialization. Blockly.Events.CommentCreate.prototype.toJson = function() { var json = Blockly.Events.CommentCreate.superClass_.toJson.call(this); json['xml'] = Blockly.Xml.domToText(this.xml); @@ -255,9 +255,9 @@ Blockly.Events.CommentDelete.prototype.type = Blockly.Events.COMMENT_DELETE; /** * Encode the event as JSON. - * TODO (#1266): "Full" and "minimal" serialization. * @return {!Object} JSON representation. */ +// TODO(#1266): "Full" and "minimal" serialization. Blockly.Events.CommentDelete.prototype.toJson = function() { var json = Blockly.Events.CommentDelete.superClass_.toJson.call(this); return json; @@ -357,9 +357,9 @@ Blockly.Events.CommentMove.prototype.setOldCoordinate = function(xy) { /** * Encode the event as JSON. - * TODO (#1266): "Full" and "minimal" serialization. * @return {!Object} JSON representation. */ +// TODO(#1266): "Full" and "minimal" serialization. Blockly.Events.CommentMove.prototype.toJson = function() { var json = Blockly.Events.CommentMove.superClass_.toJson.call(this); if (this.newCoordinate_) { From 02dc7b1d1dd2cbd41cff0ffe8ec183470126985c Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 3 Jul 2018 12:07:25 -0700 Subject: [PATCH 09/78] Fixing JSDoc for the return type of Blockly.WorkspaceComment.parseAttributes (#1966) --- core/workspace_comment.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 4941a01d4..7067795b4 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -331,7 +331,8 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { /** * Decode an XML comment tag and return the results in an object. * @param {!Element} xml XML comment element. - * @return {!Object} An object containing the information about the comment. + * @return {{w: number, h: number, x: number, y: number, content: string}} An + * object containing the id, size, position, and comment string. * @package */ Blockly.WorkspaceComment.parseAttributes = function(xml) { @@ -339,31 +340,23 @@ Blockly.WorkspaceComment.parseAttributes = function(xml) { var xmlW = xml.getAttribute('w'); return { - /* @type {string} */ + // @type {string} id: xml.getAttribute('id'), - /** - * The height of the comment in workspace units, or 100 if not specified. - * @type {number} - */ + // The height of the comment in workspace units, or 100 if not specified. + // @type {number} h: xmlH ? parseInt(xmlH, 10) : 100, - /** - * The width of the comment in workspace units, or 100 if not specified. - * @type {number} - */ + // The width of the comment in workspace units, or 100 if not specified. + // @type {number} w: xmlW ? parseInt(xmlW, 10) : 100, - /** - * The x position of the comment in workspace coordinates, or NaN if not - * specified in the XML. - * @type {number} - */ + // The x position of the comment in workspace coordinates, or NaN if not + // specified in the XML. + // @type {number} x: parseInt(xml.getAttribute('x'), 10), - /** - * The y position of the comment in workspace coordinates, or NaN if not - * specified in the XML. - * @type {number} - */ + // The y position of the comment in workspace coordinates, or NaN if not + // specified in the XML. + // @type {number} y: parseInt(xml.getAttribute('y'), 10), - /* @type {string} */ + // @type {string} content: xml.textContent }; }; From 3909bd420a22fec4cc830b0d7a31e75c5d0ff244 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sun, 10 Jun 2018 00:15:22 -0700 Subject: [PATCH 10/78] Remove all goog.asserts and goog.isXxx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First step to reducing Closure’s footprint. --- core/block.js | 109 +++++++++++++++++------------ core/block_drag_surface.js | 11 +-- core/block_dragger.js | 1 - core/block_events.js | 2 +- core/block_svg.js | 17 +++-- core/bubble_dragger.js | 1 - core/connection.js | 39 ++++++----- core/connection_db.js | 6 +- core/contextmenu.js | 3 +- core/events.js | 2 +- core/extensions.js | 11 ++- core/field.js | 9 +-- core/field_dropdown.js | 21 +++--- core/field_textinput.js | 5 +- core/field_variable.js | 6 +- core/flyout_base.js | 14 ++-- core/flyout_dragger.js | 1 - core/flyout_horizontal.js | 2 +- core/flyout_vertical.js | 2 +- core/generator.js | 39 ++++++----- core/gesture.js | 41 ++++++----- core/inject.js | 4 +- core/input.js | 11 ++- core/rendered_connection.js | 4 +- core/scrollbar.js | 2 +- core/toolbox.js | 3 +- core/tooltip.js | 5 +- core/touch_gesture.js | 1 - core/utils.js | 12 ++-- core/workspace.js | 5 +- core/workspace_comment_svg.js | 4 +- core/workspace_drag_surface_svg.js | 17 +++-- core/workspace_dragger.js | 1 - core/workspace_svg.js | 25 ++++--- core/xml.js | 20 +++--- 35 files changed, 251 insertions(+), 205 deletions(-) diff --git a/core/block.js b/core/block.js index 7492d1359..c1e43e58c 100644 --- a/core/block.js +++ b/core/block.js @@ -40,7 +40,6 @@ goog.require('Blockly.Warning'); goog.require('Blockly.Workspace'); goog.require('Blockly.Xml'); goog.require('goog.array'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); goog.require('goog.string'); @@ -57,11 +56,11 @@ goog.require('goog.string'); */ 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.'); + 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} */ @@ -153,15 +152,16 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { /** @type {string} */ this.type = prototypeName; var prototype = Blockly.Blocks[prototypeName]; - goog.asserts.assertObject(prototype, - 'Error: Unknown block type "%s".', prototypeName); + if (!prototype || typeof prototype != 'object') { + throw Error('Unknown block type: ' + prototypeName); + } goog.mixin(this, prototype); } workspace.addTopBlock(this); // Call an initialization function, if it exists. - if (goog.isFunction(this.init)) { + if (typeof this.init == 'function') { this.init(); } // Record initial inline state. @@ -184,7 +184,7 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { } // Bind an onchange function, if it exists. - if (goog.isFunction(this.onchange)) { + if (typeof this.onchange == 'function') { this.setOnChange(this.onchange); } }; @@ -501,10 +501,10 @@ Blockly.Block.prototype.setParent = function(newParent) { // Disconnect from superior blocks. if (this.previousConnection && this.previousConnection.isConnected()) { - throw 'Still connected to previous block.'; + throw Error('Still connected to previous block.'); } if (this.outputConnection && this.outputConnection.isConnected()) { - throw 'Still connected to parent block.'; + throw Error('Still connected to parent block.'); } this.parentBlock_ = null; // This block hasn't actually moved on-screen, so there's no need to update @@ -686,14 +686,14 @@ Blockly.Block.prototype.getHue = function() { * or a message reference string pointing to one of those two values. */ Blockly.Block.prototype.setColour = function(colour) { - var dereferenced = goog.isString(colour) ? + var dereferenced = (typeof colour == 'string') ? Blockly.utils.replaceMessageReferences(colour) : colour; var hue = Number(dereferenced); if (!isNaN(hue) && 0 <= hue && hue <= 360) { this.hue_ = hue; this.colour_ = Blockly.hueToRgb(hue); - } else if (goog.isString(dereferenced) && + } else if ((typeof dereferenced == 'string') && /^#[0-9a-fA-F]{6}$/.test(dereferenced)) { this.colour_ = dereferenced; // Only store hue if colour is set as a hue. @@ -717,8 +717,8 @@ Blockly.Block.prototype.setColour = function(colour) { * @throws {Error} if onchangeFn is not falsey or a function. */ Blockly.Block.prototype.setOnChange = function(onchangeFn) { - if (onchangeFn && !goog.isFunction(onchangeFn)) { - throw new Error("onchange must be a function."); + if (onchangeFn && typeof onchangeFn != 'function') { + throw new Error('onchange must be a function.'); } if (this.onchangeWrapper_) { this.workspace.removeChangeListener(this.onchangeWrapper_); @@ -840,7 +840,9 @@ Blockly.Block.prototype.getFieldValue = function(name) { */ Blockly.Block.prototype.setFieldValue = function(newValue, name) { var field = this.getField(name); - goog.asserts.assertObject(field, 'Field "%s" not found.', name); + if (!field) { + throw ReferenceError('Field "' + name + '" not found.'); + } field.setValue(newValue); }; @@ -856,16 +858,20 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { opt_check = null; } if (!this.previousConnection) { - goog.asserts.assert(!this.outputConnection, - 'Remove output connection prior to adding previous connection.'); + if (this.outputConnection) { + throw Error('Remove output connection prior to adding previous ' + + 'connection.'); + } this.previousConnection = this.makeConnection_(Blockly.PREVIOUS_STATEMENT); } this.previousConnection.setCheck(opt_check); } else { if (this.previousConnection) { - goog.asserts.assert(!this.previousConnection.isConnected(), - 'Must disconnect previous statement before removing connection.'); + if (this.previousConnection.isConnected()) { + throw Error('Must disconnect previous statement before removing ' + + 'connection.'); + } this.previousConnection.dispose(); this.previousConnection = null; } @@ -889,8 +895,10 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { this.nextConnection.setCheck(opt_check); } else { if (this.nextConnection) { - goog.asserts.assert(!this.nextConnection.isConnected(), - 'Must disconnect next statement before removing connection.'); + if (this.nextConnection.isConnected()) { + throw Error('Must disconnect next statement before removing ' + + 'connection.'); + } this.nextConnection.dispose(); this.nextConnection = null; } @@ -910,15 +918,18 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { opt_check = null; } if (!this.outputConnection) { - goog.asserts.assert(!this.previousConnection, - 'Remove previous connection prior to adding output connection.'); + if (this.previousConnection) { + throw Error('Remove previous connection prior to adding output ' + + 'connection.'); + } this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE); } this.outputConnection.setCheck(opt_check); } else { if (this.outputConnection) { - goog.asserts.assert(!this.outputConnection.isConnected(), - 'Must disconnect output value before removing connection.'); + if (this.outputConnection.isConnected()) { + throw Error('Must disconnect output value before removing connection.'); + } this.outputConnection.dispose(); this.outputConnection = null; } @@ -1093,9 +1104,10 @@ Blockly.Block.prototype.jsonInit = function(json) { var warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : ''; // Validate inputs. - goog.asserts.assert( - json['output'] == undefined || json['previousStatement'] == undefined, - warningPrefix + 'Must not have both an output and a previousStatement.'); + if (json['output'] && json['previousStatement']) { + throw Error(warningPrefix + + 'Must not have both an output and a previousStatement.'); + } // Set basic properties of block. this.jsonInitColour_(json, warningPrefix); @@ -1135,7 +1147,7 @@ Blockly.Block.prototype.jsonInit = function(json) { var localizedValue = Blockly.utils.replaceMessageReferences(rawValue); this.setHelpUrl(localizedValue); } - if (goog.isString(json['extensions'])) { + if (typeof json['extensions'] == 'string') { console.warn( warningPrefix + 'JSON attribute \'extensions\' should be an array of' + ' strings. Found raw string in JSON for \'' + json['type'] + @@ -1188,8 +1200,8 @@ Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) { * @param {boolean=} opt_disableCheck Option flag to disable overwrite checks. */ Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) { - if (goog.isDef(opt_disableCheck) && !goog.isBoolean(opt_disableCheck)) { - throw new Error("opt_disableCheck must be a boolean if provided"); + if (opt_disableCheck !== undefined && typeof opt_disableCheck != 'boolean') { + throw new Error('opt_disableCheck must be a boolean if provided'); } if (!opt_disableCheck) { var overwrites = []; @@ -1368,9 +1380,12 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) { } } } - goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name); - goog.asserts.assert( - refIndex != -1, 'Reference input "%s" not found.', refName); + if (inputIndex == -1) { + throw ReferenceError('Named input "' + name + '" not found.'); + } + if (refIndex == -1) { + throw ReferenceError('Reference input "' + refName + '" not found.'); + } this.moveNumberedInputBefore(inputIndex, refIndex); }; @@ -1382,11 +1397,15 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) { Blockly.Block.prototype.moveNumberedInputBefore = function( inputIndex, refIndex) { // Validate arguments. - goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.'); - goog.asserts.assert(inputIndex < this.inputList.length, - 'Input index ' + inputIndex + ' out of bounds.'); - goog.asserts.assert(refIndex <= this.inputList.length, - 'Reference input ' + refIndex + ' out of bounds.'); + if (inputIndex == refIndex) { + throw Error('Can\'t move input to itself.'); + } + if (inputIndex >= this.inputList.length) { + throw RangeError('Input index ' + inputIndex + ' out of bounds.'); + } + if (refIndex > this.inputList.length) { + throw RangeError('Reference input ' + refIndex + ' out of bounds.'); + } // Remove input. var input = this.inputList[inputIndex]; this.inputList.splice(inputIndex, 1); @@ -1401,7 +1420,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function( * Remove an input from this block. * @param {string} name The name of the input. * @param {boolean=} opt_quiet True to prevent error if input is not present. - * @throws {goog.asserts.AssertionError} if the input is not present and + * @throws {ReferenceError} if the input is not present and * opt_quiet is not true. */ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { @@ -1424,7 +1443,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { } } if (!opt_quiet) { - goog.asserts.fail('Input "%s" not found.', name); + throw ReferenceErrer('Input not found: ' + name); } }; @@ -1508,7 +1527,9 @@ Blockly.Block.prototype.getRelativeToSurfaceXY = function() { * @param {number} dy Vertical offset, in workspace units. */ Blockly.Block.prototype.moveBy = function(dx, dy) { - goog.asserts.assert(!this.parentBlock_, 'Block has parent.'); + if (this.parentBlock_) { + throw Error('Block has parent.'); + } var event = new Blockly.Events.BlockMove(this); this.xy_.translate(dx, dy); event.recordNew(); diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 1a15b7544..fcd113416 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -31,7 +31,6 @@ goog.provide('Blockly.BlockDragSurfaceSvg'); goog.require('Blockly.utils'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); @@ -113,8 +112,9 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { * surface. */ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { - goog.asserts.assert( - this.dragGroup_.childNodes.length == 0, 'Already dragging a block.'); + if (this.dragGroup_.childNodes.length) { + throw Error('Already dragging a block.'); + } // appendChild removes the blocks from the previous parent this.dragGroup_.appendChild(blocks); this.SVG_.style.display = 'block'; @@ -214,7 +214,8 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { this.dragGroup_.removeChild(this.getCurrentBlock()); } this.SVG_.style.display = 'none'; - goog.asserts.assert( - this.dragGroup_.childNodes.length == 0, 'Drag group was not cleared.'); + if (this.dragGroup_.childNodes.length) { + throw Error('Drag group was not cleared.'); + } this.surfaceXY_ = null; }; diff --git a/core/block_dragger.js b/core/block_dragger.js index 4e94977da..9a6c46573 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -31,7 +31,6 @@ goog.require('Blockly.DraggedConnectionManager'); goog.require('Blockly.Events.BlockMove'); goog.require('goog.math.Coordinate'); -goog.require('goog.asserts'); /** diff --git a/core/block_events.js b/core/block_events.js index a680d069f..2bc6d6b23 100644 --- a/core/block_events.js +++ b/core/block_events.js @@ -300,7 +300,7 @@ Blockly.Events.Delete = function(block) { return; // Blank event to be populated by fromJson. } if (block.getParent()) { - throw 'Connected blocks cannot be deleted.'; + throw Error('Connected blocks cannot be deleted.'); } Blockly.Events.Delete.superClass_.constructor.call(this, block); diff --git a/core/block_svg.js b/core/block_svg.js index e54216ce1..b26396945 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -37,7 +37,6 @@ goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); -goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -145,7 +144,9 @@ Blockly.BlockSvg.INLINE = -1; * May be called more than once. */ Blockly.BlockSvg.prototype.initSvg = function() { - goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.'); + if (!this.workspace.rendered) { + throw TypeError('Workspace is headless.'); + } for (var i = 0, input; input = this.inputList[i]; i++) { input.init(); } @@ -327,7 +328,9 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() { * @param {number} dy Vertical offset in workspace units. */ Blockly.BlockSvg.prototype.moveBy = function(dx, dy) { - goog.asserts.assert(!this.parentBlock_, 'Block has parent.'); + if (this.parentBlock_) { + throw Error('Block has parent.'); + } var eventsEnabled = Blockly.Events.isEnabled(); if (eventsEnabled) { var event = new Blockly.Events.BlockMove(this); @@ -594,7 +597,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { * @private */ Blockly.BlockSvg.prototype.showHelp_ = function() { - var url = goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl; + var url = (typeof this.helpUrl == 'function') ? this.helpUrl() : this.helpUrl; if (url) { window.open(url); } @@ -936,7 +939,7 @@ Blockly.BlockSvg.prototype.getCommentText = function() { */ Blockly.BlockSvg.prototype.setCommentText = function(text) { var changedState = false; - if (goog.isString(text)) { + if (typeof text == 'string') { if (!this.comment) { this.comment = new Blockly.Comment(this); changedState = true; @@ -1009,7 +1012,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) { } var changedState = false; - if (goog.isString(text)) { + if (typeof text == 'string') { if (!this.warning) { this.warning = new Blockly.Warning(this); changedState = true; @@ -1213,7 +1216,7 @@ Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) { * Remove an input from this block. * @param {string} name The name of the input. * @param {boolean=} opt_quiet True to prevent error if input is not present. - * @throws {goog.asserts.AssertionError} if the input is not present and + * @throws {ReferenceError} if the input is not present and * opt_quiet is not true. */ Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) { diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 7a7501c59..38c8de487 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -31,7 +31,6 @@ goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.WorkspaceCommentSvg'); goog.require('goog.math.Coordinate'); -goog.require('goog.asserts'); /** diff --git a/core/connection.js b/core/connection.js index 3ff6a1b31..23dbdb6cb 100644 --- a/core/connection.js +++ b/core/connection.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Connection'); goog.require('Blockly.Events.BlockMove'); -goog.require('goog.asserts'); goog.require('goog.dom'); @@ -160,7 +159,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { // Value connections. // If female block is already connected, disconnect and bump the male. if (!orphanBlock.outputConnection) { - throw 'Orphan block does not have an output connection.'; + throw Error('Orphan block does not have an output connection.'); } // Attempt to reattach the orphan at the end of the newly inserted // block. Since this block may be a row, walk down to the end @@ -176,7 +175,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { // Statement blocks may be inserted into the middle of a stack. // Split the stack. if (!orphanBlock.previousConnection) { - throw 'Orphan block does not have a previous connection.'; + throw Error('Orphan block does not have a previous connection.'); } // Attempt to reattach the orphan at the bottom of the newly inserted // block. Since this block may be a stack, walk down to the end. @@ -238,7 +237,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { */ Blockly.Connection.prototype.dispose = function() { if (this.isConnected()) { - throw 'Disconnect connection before disposing of it.'; + throw Error('Disconnect connection before disposing of it.'); } if (this.inDB_) { this.db_.removeConnection_(this); @@ -317,22 +316,22 @@ Blockly.Connection.prototype.checkConnection_ = function(target) { case Blockly.Connection.CAN_CONNECT: break; case Blockly.Connection.REASON_SELF_CONNECTION: - throw 'Attempted to connect a block to itself.'; + throw Error('Attempted to connect a block to itself.'); case Blockly.Connection.REASON_DIFFERENT_WORKSPACES: // Usually this means one block has been deleted. - throw 'Blocks not on same workspace.'; + throw Error('Blocks not on same workspace.'); case Blockly.Connection.REASON_WRONG_TYPE: - throw 'Attempt to connect incompatible types.'; + throw Error('Attempt to connect incompatible types.'); case Blockly.Connection.REASON_TARGET_NULL: - throw 'Target connection is null.'; + throw Error('Target connection is null.'); case Blockly.Connection.REASON_CHECKS_FAILED: var msg = 'Connection checks failed. '; msg += this + ' expected ' + this.check_ + ', found ' + target.check_; - throw msg; + throw Error(msg); case Blockly.Connection.REASON_SHADOW_PARENT: - throw 'Connecting non-shadow to shadow block.'; + throw Error('Connecting non-shadow to shadow block.'); default: - throw 'Unknown connection failure: this should never happen!'; + throw Error('Unknown connection failure: this should never happen!'); } }; @@ -414,7 +413,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) { * @private */ Blockly.Connection.connectReciprocally_ = function(first, second) { - goog.asserts.assert(first && second, 'Cannot connect null connections.'); + if (!first || !second) { + throw Error('Cannot connect null connections.'); + } first.targetConnection = second; second.targetConnection = first; }; @@ -474,10 +475,12 @@ Blockly.Connection.lastConnectionInRow_ = function(startBlock, orphanBlock) { */ Blockly.Connection.prototype.disconnect = function() { var otherConnection = this.targetConnection; - goog.asserts.assert(otherConnection, 'Source connection not connected.'); - goog.asserts.assert(otherConnection.targetConnection == this, - 'Target connection not connected to source connection.'); - + if (!otherConnection) { + throw Error('Source connection not connected.'); + } + if (otherConnection.targetConnection != this) { + throw Error('Target connection not connected to source connection.'); + } var parentBlock, childBlock, parentConnection; if (this.isSuperior()) { // Superior block. @@ -531,7 +534,7 @@ Blockly.Connection.prototype.respawnShadow_ = function() { } else if (blockShadow.previousConnection) { this.connect(blockShadow.previousConnection); } else { - throw 'Child block does not have output or previous statement.'; + throw Error('Child block does not have output or previous statement.'); } } }; @@ -591,7 +594,7 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { Blockly.Connection.prototype.setCheck = function(check) { if (check) { // Ensure that check is in an array. - if (!goog.isArray(check)) { + if (!Array.isArray(check)) { check = [check]; } this.check_ = check; diff --git a/core/connection_db.js b/core/connection_db.js index acb044cf6..f1968f957 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -51,7 +51,7 @@ Blockly.ConnectionDB.constructor = Blockly.ConnectionDB; */ Blockly.ConnectionDB.prototype.addConnection = function(connection) { if (connection.inDB_) { - throw 'Connection already in database.'; + throw Error('Connection already in database.'); } if (connection.getSourceBlock().isInFlyout) { // Don't bother maintaining a database of connections in a flyout. @@ -137,11 +137,11 @@ Blockly.ConnectionDB.prototype.findPositionForConnection_ = function( */ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) { if (!connection.inDB_) { - throw 'Connection not in database.'; + throw Error('Connection not in database.'); } var removalIndex = this.findConnection(connection); if (removalIndex == -1) { - throw 'Unable to find connection in connectionDB.'; + throw Error('Unable to find connection in connectionDB.'); } connection.inDB_ = false; this.splice(removalIndex, 1); diff --git a/core/contextmenu.js b/core/contextmenu.js index 657556645..00dbd16ed 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -241,7 +241,8 @@ Blockly.ContextMenu.blockDeleteOption = function(block) { * @package */ Blockly.ContextMenu.blockHelpOption = function(block) { - var url = goog.isFunction(block.helpUrl) ? block.helpUrl() : block.helpUrl; + var url = (typeof block.helpUrl == 'function') ? + block.helpUrl() : block.helpUrl; var helpOption = { enabled: !!url, text: Blockly.Msg['HELP'], diff --git a/core/events.js b/core/events.js index 265f5114d..b57d8c0e5 100644 --- a/core/events.js +++ b/core/events.js @@ -372,7 +372,7 @@ Blockly.Events.fromJson = function(json, workspace) { event = new Blockly.Events.CommentDelete(null); break; default: - throw 'Unknown event type.'; + throw Error('Unknown event type.'); } event.fromJson(json); event.workspaceId = workspace.id; diff --git a/core/extensions.js b/core/extensions.js index 3c4e529cc..1379f2f18 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -35,7 +35,6 @@ goog.provide('Blockly.Extensions'); goog.require('Blockly.Mutator'); goog.require('Blockly.utils'); -goog.require('goog.string'); /** * The set of all registered extensions, keyed by extension name/id. @@ -54,13 +53,13 @@ Blockly.Extensions.ALL_ = {}; * registered, or extensionFn is not a function. */ Blockly.Extensions.register = function(name, initFn) { - if (!goog.isString(name) || goog.string.isEmptyOrWhitespace(name)) { + if ((typeof name != 'string') || (name.trim() == '')) { throw new Error('Error: Invalid extension name "' + name + '"'); } if (Blockly.Extensions.ALL_[name]) { throw new Error('Error: Extension "' + name + '" is already registered.'); } - if (!goog.isFunction(initFn)) { + if (typeof initFn != 'function') { throw new Error('Error: Extension "' + name + '" must be a function'); } Blockly.Extensions.ALL_[name] = initFn; @@ -74,7 +73,7 @@ Blockly.Extensions.register = function(name, initFn) { * registered. */ Blockly.Extensions.registerMixin = function(name, mixinObj) { - if (!goog.isObject(mixinObj)){ + if (!mixinObj || typeof mixinObj != 'object'){ throw new Error('Error: Mixin "' + name + '" must be a object'); } Blockly.Extensions.register(name, function() { @@ -108,7 +107,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, var hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); - if (opt_helperFn && !goog.isFunction(opt_helperFn)) { + if (opt_helperFn && (typeof opt_helperFn != 'function')) { throw new Error('Extension "' + name + '" is not a function'); } @@ -136,7 +135,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, */ Blockly.Extensions.apply = function(name, block, isMutator) { var extensionFn = Blockly.Extensions.ALL_[name]; - if (!goog.isFunction(extensionFn)) { + if (typeof extensionFn != 'function') { throw new Error('Error: Extension "' + name + '" not found.'); } if (isMutator) { diff --git a/core/field.js b/core/field.js index ce4ba1919..247113c3c 100644 --- a/core/field.js +++ b/core/field.js @@ -31,7 +31,6 @@ goog.provide('Blockly.Field'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Gesture'); -goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.math.Size'); goog.require('goog.style'); @@ -71,10 +70,10 @@ Blockly.Field.TYPE_MAP_ = {}; * object containing a fromJson function. */ Blockly.Field.register = function(type, fieldClass) { - if (!goog.isString(type) || goog.string.isEmptyOrWhitespace(type)) { + if ((typeof type != 'string') || (type.trim() == '')) { throw new Error('Invalid field type "' + type + '"'); } - if (!goog.isObject(fieldClass) || !goog.isFunction(fieldClass.fromJson)) { + if (!fieldClass || (typeof fieldClass.fromJson != 'function')) { throw new Error('Field "' + fieldClass + '" must have a fromJson function'); } @@ -171,7 +170,9 @@ Blockly.Field.prototype.EDITABLE = true; * @param {!Blockly.Block} block The block containing this field. */ Blockly.Field.prototype.setSourceBlock = function(block) { - goog.asserts.assert(!this.sourceBlock_, 'Field already bound to a block.'); + if (this.sourceBlock_) { + throw TypeError('Field already bound to a block.'); + } this.sourceBlock_ = block; }; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 8bf119af0..026389560 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -53,7 +53,7 @@ goog.require('goog.userAgent'); * @constructor */ Blockly.FieldDropdown = function(menuGenerator, opt_validator) { - if (!goog.isFunction(menuGenerator)) { + if (typeof menuGenerator != 'function') { Blockly.FieldDropdown.validateOptions_(menuGenerator); } this.menuGenerator_ = menuGenerator; @@ -291,7 +291,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { this.prefixField = null; this.suffixField = null; var options = this.menuGenerator_; - if (!goog.isArray(options)) { + if (!Array.isArray(options)) { return; } var hasImages = false; @@ -362,7 +362,7 @@ Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) * Otherwise false. */ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { - return goog.isFunction(this.menuGenerator_); + return typeof this.menuGenerator_ == 'function'; }; /** @@ -372,7 +372,7 @@ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { * @throws If generated options are incorrectly structured. */ Blockly.FieldDropdown.prototype.getOptions = function() { - if (goog.isFunction(this.menuGenerator_)) { + if (this.isOptionListDynamic()) { var generatedOptions = this.menuGenerator_.call(this); Blockly.FieldDropdown.validateOptions_(generatedOptions); return generatedOptions; @@ -537,23 +537,24 @@ Blockly.FieldDropdown.prototype.dispose = function() { * @private */ Blockly.FieldDropdown.validateOptions_ = function(options) { - if (!goog.isArray(options)) { - throw 'FieldDropdown options must be an array.'; + if (!Array.isArray(options)) { + throw Error('FieldDropdown options must be an array.'); } var foundError = false; for (var i = 0; i < options.length; ++i) { var tuple = options[i]; - if (!goog.isArray(options)) { + if (!Array.isArray(options)) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + 'array. Found: ', tuple); - } else if (!goog.isString(tuple[1])) { + } else if (typeof tuple[1] != 'string') { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + 'a string. Found ' + tuple[1] + ' in: ', tuple); - } else if (!goog.isString(tuple[0]) && !goog.isString(tuple[0].src)) { + } else if ((typeof tuple[0] != 'string') && + (typeof tuple[0].src != 'string')) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + @@ -562,7 +563,7 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { } } if (foundError) { - throw 'Found invalid FieldDropdown options.'; + throw TypeError('Found invalid FieldDropdown options.'); } }; diff --git a/core/field_textinput.js b/core/field_textinput.js index 41bbdbeea..093715eb7 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -28,7 +28,6 @@ goog.provide('Blockly.FieldTextInput'); goog.require('Blockly.Field'); goog.require('Blockly.Msg'); -goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.TagName'); goog.require('goog.userAgent'); @@ -300,7 +299,9 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { */ Blockly.FieldTextInput.prototype.validate_ = function() { var valid = true; - goog.asserts.assertObject(Blockly.FieldTextInput.htmlInput_); + if (!Blockly.FieldTextInput.htmlInput_) { + throw TypeError('htmlInput not defined'); + } var htmlInput = Blockly.FieldTextInput.htmlInput_; if (this.sourceBlock_) { valid = this.callValidator(htmlInput.value); diff --git a/core/field_variable.js b/core/field_variable.js index 3a97c4031..467586f0e 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -30,7 +30,6 @@ goog.require('Blockly.FieldDropdown'); goog.require('Blockly.Msg'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Variables'); -goog.require('goog.asserts'); goog.require('goog.string'); @@ -132,8 +131,9 @@ Blockly.FieldVariable.prototype.dispose = function() { * @param {!Blockly.Block} block The block containing this field. */ Blockly.FieldVariable.prototype.setSourceBlock = function(block) { - goog.asserts.assert(!block.isShadow(), - 'Variable fields are not allowed to exist on shadow blocks.'); + if (block.isShadow()) { + throw Error('Variable fields are not allowed to exist on shadow blocks.'); + } Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block); }; diff --git a/core/flyout_base.js b/core/flyout_base.js index a7b40ba10..3647339df 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -426,11 +426,13 @@ Blockly.Flyout.prototype.show = function(xmlList) { if (typeof xmlList == 'string') { var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( xmlList); - goog.asserts.assert(goog.isFunction(fnToApply), - 'Couldn\'t find a callback function when opening a toolbox category.'); + if (typeof fnToApply != 'function') { + throw TypeError('Couldn\'t find a callback function when opening a toolbox category.'); + } xmlList = fnToApply(this.workspace_.targetWorkspace); - goog.asserts.assert(goog.isArray(xmlList), - 'The result of a toolbox category callback must be an array.'); + if (!Array.isArray(xmlList)) { + throw TypeError('Result of toolbox category callback must be an array.'); + } } this.setVisible(true); @@ -762,7 +764,7 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { var targetWorkspace = this.targetWorkspace_; var svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { - throw 'oldBlock is not rendered.'; + throw Error('oldBlock is not rendered.'); } // Create the new block by cloning the block in the flyout (via XML). @@ -776,7 +778,7 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { var block = Blockly.Xml.domToBlock(xml, targetWorkspace); var svgRootNew = block.getSvgRoot(); if (!svgRootNew) { - throw 'block is not rendered.'; + throw Error('block is not rendered.'); } // The offset in pixels between the main workspace's origin and the upper left diff --git a/core/flyout_dragger.js b/core/flyout_dragger.js index c3909eaf2..2cc5f16a0 100644 --- a/core/flyout_dragger.js +++ b/core/flyout_dragger.js @@ -28,7 +28,6 @@ goog.provide('Blockly.FlyoutDragger'); goog.require('Blockly.WorkspaceDragger'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 8dd8032f6..e893ad70d 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -126,7 +126,7 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { return; } - if (goog.isNumber(xyRatio.x)) { + if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = -metrics.contentWidth * xyRatio.x; } diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index aa799123d..1ab3fbb40 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -125,7 +125,7 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!metrics) { return; } - if (goog.isNumber(xyRatio.y)) { + if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = -metrics.contentHeight * xyRatio.y; } this.workspace_.translate(this.workspace_.scrollX + metrics.absoluteLeft, diff --git a/core/generator.js b/core/generator.js index 3c8e397a9..8c05e0483 100644 --- a/core/generator.js +++ b/core/generator.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Generator'); goog.require('Blockly.Block'); -goog.require('goog.asserts'); /** @@ -99,7 +98,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { var blocks = workspace.getTopBlocks(true); for (var x = 0, block; block = blocks[x]; x++) { var line = this.blockToCode(block); - if (goog.isArray(line)) { + if (Array.isArray(line)) { // Value blocks return tuples of code and operator order. // Top-level blocks don't care about operator order. line = line[0]; @@ -173,31 +172,32 @@ Blockly.Generator.prototype.blockToCode = function(block) { } var func = this[block.type]; - goog.asserts.assertFunction(func, - 'Language "%s" does not know how to generate code for block type "%s".', - this.name_, block.type); + if (typeof func != 'function') { + throw Error('Language "' + this.name_ + '" does not know how to generate ' + + ' code for block type "' + block.type + '".'); + } // First argument to func.call is the value of 'this' in the generator. // Prior to 24 September 2013 'this' was the only way to access the block. // The current prefered method of accessing the block is through the second // argument to func.call, which becomes the first parameter to the generator. var code = func.call(block, block); - if (goog.isArray(code)) { + if (Array.isArray(code)) { // Value blocks return tuples of code and operator order. - goog.asserts.assert(block.outputConnection, - 'Expecting string from statement block "%s".', block.type); + if (!block.outputConnection) { + throw Error('Expecting string from statement block: ' + block.type); + } return [this.scrub_(block, code[0]), code[1]]; - } else if (goog.isString(code)) { + } else if (typeof code == 'string') { var id = block.id.replace(/\$/g, '$$$$'); // Issue 251. if (this.STATEMENT_PREFIX) { - code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') + - code; + code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') + code; } return this.scrub_(block, code); } else if (code === null) { // Block has handled code generation itself. return ''; } else { - goog.asserts.fail('Invalid code generated: %s', code); + throw SyntaxError('Invalid code generated: ' + code); } }; @@ -212,7 +212,7 @@ Blockly.Generator.prototype.blockToCode = function(block) { */ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { - goog.asserts.fail('Expecting valid order from block "%s".', block.type); + throw TypeError('Expecting valid order from block: ' + block.type); } var targetBlock = block.getInputTargetBlock(name); if (!targetBlock) { @@ -225,12 +225,13 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { } // Value blocks must return code and order of operations info. // Statement blocks must only return code. - goog.asserts.assertArray(tuple, 'Expecting tuple from value block "%s".', - targetBlock.type); + if (!Array.isArray(tuple)) { + throw TypeError('Expecting tuple from value block: ' + targetBlock.type); + } var code = tuple[0]; var innerOrder = tuple[1]; if (isNaN(innerOrder)) { - goog.asserts.fail('Expecting valid order from value block "%s".', + throw TypeError('Expecting valid order from value block: ' + targetBlock.type); } if (!code) { @@ -282,8 +283,10 @@ Blockly.Generator.prototype.statementToCode = function(block, name) { var code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. // Statement blocks must only return code. - goog.asserts.assertString(code, 'Expecting code from statement block "%s".', - targetBlock && targetBlock.type); + if (typeof code != 'string') { + throw TypeError('Expecting code from statement block: ' + + (targetBlock && targetBlock.type)); + } if (code) { code = this.prefixLines(/** @type {string} */ (code), this.INDENT); } diff --git a/core/gesture.js b/core/gesture.js index d983e7a2d..f8b3aa260 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -37,7 +37,6 @@ goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.WorkspaceDragger'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); @@ -429,8 +428,9 @@ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { */ Blockly.Gesture.prototype.updateIsDragging_ = function() { // Sanity check. - goog.asserts.assert(!this.calledUpdateIsDragging_, - 'updateIsDragging_ should only be called once per gesture.'); + if (this.calledUpdateIsDragging_) { + throw Error('updateIsDragging_ should only be called once per gesture.'); + } this.calledUpdateIsDragging_ = true; // First check if it was a bubble drag. Bubbles always sit on top of blocks. @@ -648,9 +648,10 @@ Blockly.Gesture.prototype.handleRightClick = function(e) { * @package */ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { - goog.asserts.assert(!this.hasStarted_, - 'Tried to call gesture.handleWsStart, but the gesture had already been ' + - 'started.'); + if (this.hasStarted_) { + throw Error('Tried to call gesture.handleWsStart, ' + + 'but the gesture had already been started.'); + } this.setStartWorkspace_(ws); this.mostRecentEvent_ = e; this.doStart(e); @@ -663,9 +664,10 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @package */ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { - goog.asserts.assert(!this.hasStarted_, - 'Tried to call gesture.handleFlyoutStart, but the gesture had already ' + - 'been started.'); + if (this.hasStarted_) { + throw Error('Tried to call gesture.handleFlyoutStart, ' + + 'but the gesture had already been started.'); + } this.setStartFlyout_(flyout); this.handleWsStart(e, flyout.getWorkspace()); }; @@ -677,9 +679,10 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { * @package */ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { - goog.asserts.assert(!this.hasStarted_, - 'Tried to call gesture.handleBlockStart, but the gesture had already ' + - 'been started.'); + if (this.hasStarted_) { + throw Error('Tried to call gesture.handleBlockStart, ' + + 'but the gesture had already been started.'); + } this.setStartBlock(block); this.mostRecentEvent_ = e; }; @@ -691,9 +694,10 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { * @package */ Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { - goog.asserts.assert(!this.hasStarted_, - 'Tried to call gesture.handleBubbleStart, but the gesture had already ' + - 'been started.'); + if (this.hasStarted_) { + throw Error('Tried to call gesture.handleBubbleStart, ' + + 'but the gesture had already been started.'); + } this.setStartBubble(bubble); this.mostRecentEvent_ = e; }; @@ -779,9 +783,10 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() { * @package */ Blockly.Gesture.prototype.setStartField = function(field) { - goog.asserts.assert(!this.hasStarted_, - 'Tried to call gesture.setStartField, but the gesture had already been ' + - 'started.'); + if (this.hasStarted_) { + throw Error('Tried to call gesture.setStartField, ' + + 'but the gesture had already been started.'); + } if (!this.startField_) { this.startField_ = field; } diff --git a/core/inject.js b/core/inject.js index 1918c2542..19c1e8285 100644 --- a/core/inject.js +++ b/core/inject.js @@ -47,13 +47,13 @@ goog.require('goog.userAgent'); Blockly.inject = function(container, opt_options) { Blockly.checkBlockColourConstants(); - if (goog.isString(container)) { + if (typeof container == 'string') { container = document.getElementById(container) || document.querySelector(container); } // Verify that the container is in document. if (!goog.dom.contains(document, container)) { - throw 'Error: container is not in current document.'; + throw Error('Error: container is not in current document.'); } var options = new Blockly.Options(opt_options || {}); var subContainer = goog.dom.createDom(goog.dom.TagName.DIV, 'injectionDiv'); diff --git a/core/input.js b/core/input.js index 5c7495dcf..9ac772c6d 100644 --- a/core/input.js +++ b/core/input.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Input'); goog.require('Blockly.Connection'); goog.require('Blockly.FieldLabel'); -goog.require('goog.asserts'); /** @@ -42,7 +41,7 @@ goog.require('goog.asserts'); */ Blockly.Input = function(type, name, block, connection) { if (type != Blockly.DUMMY_INPUT && !name) { - throw 'Value inputs and statement inputs must have non-empty name.'; + throw Error('Value inputs and statement inputs must have non-empty name.'); } /** @type {number} */ this.type = type; @@ -104,7 +103,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { return index; } // Generate a FieldLabel when given a plain text field. - if (goog.isString(field)) { + if (typeof field == 'string') { field = new Blockly.FieldLabel(/** @type {string} */ (field)); } field.setSourceBlock(this.sourceBlock_); @@ -136,7 +135,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { /** * Remove a field from this input. * @param {string} name The name of the field. - * @throws {goog.asserts.AssertionError} if the field is not present. + * @throws {ReferenceError} if the field is not present. */ Blockly.Input.prototype.removeField = function(name) { for (var i = 0, field; field = this.fieldRow[i]; i++) { @@ -151,7 +150,7 @@ Blockly.Input.prototype.removeField = function(name) { return; } } - goog.asserts.fail('Field "%s" not found.', name); + throw ReferenceError('Field "%s" not found.', name); }; /** @@ -205,7 +204,7 @@ Blockly.Input.prototype.setVisible = function(visible) { */ Blockly.Input.prototype.setCheck = function(check) { if (!this.connection) { - throw 'This input does not have a connection.'; + throw Error('This input does not have a connection.'); } this.connection.setCheck(check); return this; diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 76c63289b..bdf60513f 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -166,7 +166,7 @@ Blockly.RenderedConnection.prototype.tighten_ = function() { var block = this.targetBlock(); var svgRoot = block.getSvgRoot(); if (!svgRoot) { - throw 'block is not rendered.'; + throw Error('block is not rendered.'); } // Workspace coordinates. var xy = Blockly.utils.getRelativeXY(svgRoot); @@ -351,7 +351,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { Blockly.RenderedConnection.superClass_.respawnShadow_.call(this); var blockShadow = this.targetBlock(); if (!blockShadow) { - throw 'Couldn\'t respawn the shadow block that should exist here.'; + throw Error('Couldn\'t respawn the shadow block that should exist here.'); } blockShadow.initSvg(); blockShadow.render(false); diff --git a/core/scrollbar.js b/core/scrollbar.js index ec0458e31..bbaff04cf 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -660,7 +660,7 @@ Blockly.Scrollbar.prototype.setVisible = function(visible) { // Ideally this would also apply to scrollbar pairs, but that's a bigger // headache (due to interactions with the corner square). if (this.pair_) { - throw 'Unable to toggle visibility of paired scrollbars.'; + throw Error('Unable to toggle visibility of paired scrollbars.'); } this.isVisible_ = visible; if (visibilityChanged) { diff --git a/core/toolbox.js b/core/toolbox.js index 359fec8bb..ee5b4bf1b 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -286,7 +286,8 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) { this.syncTrees_(newTree, this.tree_, this.workspace_.options.pathToMedia); if (this.tree_.blocks.length) { - throw 'Toolbox cannot have both blocks and categories in the root level.'; + throw Error('Toolbox cannot have both blocks and categories ' + + 'in the root level.'); } // Fire a resize event since the toolbox may have changed width and height. diff --git a/core/tooltip.js b/core/tooltip.js index 2e3d3da49..25527eeef 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -167,7 +167,8 @@ Blockly.Tooltip.onMouseOver_ = function(e) { // If the tooltip is an object, treat it as a pointer to the next object in // the chain to look at. Terminate when a string or function is found. var element = e.target; - while (!goog.isString(element.tooltip) && !goog.isFunction(element.tooltip)) { + while ((typeof element.tooltip != 'string') && + (typeof element.tooltip != 'function')) { element = element.tooltip; } if (Blockly.Tooltip.element_ != element) { @@ -289,7 +290,7 @@ Blockly.Tooltip.show_ = function() { goog.dom.removeChildren(/** @type {!Element} */ (Blockly.Tooltip.DIV)); // Get the new text. var tip = Blockly.Tooltip.element_.tooltip; - while (goog.isFunction(tip)) { + while (typeof tip == 'function') { tip = tip(); } tip = Blockly.utils.wrap(tip, Blockly.Tooltip.LIMIT); diff --git a/core/touch_gesture.js b/core/touch_gesture.js index 3303e3a8e..ce0df947c 100644 --- a/core/touch_gesture.js +++ b/core/touch_gesture.js @@ -29,7 +29,6 @@ goog.provide('Blockly.TouchGesture'); goog.require('Blockly.Gesture'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); diff --git a/core/utils.js b/core/utils.js index 6ba9da683..543761c39 100644 --- a/core/utils.js +++ b/core/utils.js @@ -403,7 +403,7 @@ Blockly.utils.tokenizeInterpolation = function(message) { * @return {!string} String with message references replaced. */ Blockly.utils.replaceMessageReferences = function(message) { - if (!goog.isString(message)) { + if (typeof message != 'string') { return message; } var interpolatedResult = Blockly.utils.tokenizeInterpolation_(message, false); @@ -511,9 +511,9 @@ Blockly.utils.tokenizeInterpolation_ = function(message, } else if (state == 3) { // String table reference if (c == '') { // Premature end before closing '}' - buffer.splice(0, 0, '%{'); // Re-insert leading delimiter + buffer.splice(0, 0, '%{'); // Re-insert leading delimiter i--; // Parse this char again. - state = 0; // and parse as string literal. + state = 0; // and parse as string literal. } else if (c != '}') { buffer.push(c); } else { @@ -529,7 +529,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, keyUpper.substring(4) : null; if (bklyKey && bklyKey in Blockly.Msg) { var rawValue = Blockly.Msg[bklyKey]; - if (goog.isString(rawValue)) { + if (typeof rawValue == 'string') { // Attempt to dereference substrings, too, appending to the end. Array.prototype.push.apply(tokens, Blockly.utils.tokenizeInterpolation_( @@ -551,7 +551,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, } else { tokens.push('%{' + rawKey + '}'); buffer.length = 0; - state = 0; // and parse as string literal. + state = 0; // and parse as string literal. } } } @@ -839,7 +839,7 @@ Blockly.utils.insertAfter_ = function(newNode, refNode) { var siblingNode = refNode.nextSibling; var parentNode = refNode.parentNode; if (!parentNode) { - throw 'Reference node has no parent.'; + throw Error('Reference node has no parent.'); } if (siblingNode) { parentNode.insertBefore(newNode, siblingNode); diff --git a/core/workspace.js b/core/workspace.js index 2bb088c52..04952a189 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -161,7 +161,7 @@ Blockly.Workspace.prototype.addTopBlock = function(block) { */ Blockly.Workspace.prototype.removeTopBlock = function(block) { if (!goog.array.remove(this.topBlocks_, block)) { - throw 'Block not present in workspace\'s list of top-most blocks.'; + throw Error('Block not present in workspace\'s list of top-most blocks.'); } }; @@ -212,7 +212,8 @@ Blockly.Workspace.prototype.addTopComment = function(comment) { */ Blockly.Workspace.prototype.removeTopComment = function(comment) { if (!goog.array.remove(this.topComments_, comment)) { - throw 'Comment not present in workspace\'s list of top-most comments.'; + throw Error('Comment not present in workspace\'s list of top-most ' + + 'comments.'); } // Note: If the comment database starts to hold block comments, this may need // to move to a separate function. diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 64c92122e..8acf3ee08 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -132,7 +132,9 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.initSvg = function() { - goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.'); + if (!this.workspace.rendered) { + throw TypeError('Workspace is headless.'); + } if (!this.workspace.options.readOnly && !this.eventsInit_) { Blockly.bindEventWithChecks_( this.svgRectTarget_, 'mousedown', this, this.pathMouseDown_); diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index ad831e51b..07429a2e9 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -32,7 +32,6 @@ goog.provide('Blockly.WorkspaceDragSurfaceSvg'); goog.require('Blockly.utils'); -goog.require('goog.asserts'); goog.require('goog.math.Coordinate'); @@ -138,14 +137,16 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation = function() { */ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { if (!newSurface) { - throw 'Couldn\'t clear and hide the drag surface: missing new surface.'; + throw Error('Couldn\'t clear and hide the drag surface: missing ' + + 'new surface.'); } var blockCanvas = this.SVG_.childNodes[0]; var bubbleCanvas = this.SVG_.childNodes[1]; if (!blockCanvas || !bubbleCanvas || !Blockly.utils.hasClass(blockCanvas, 'blocklyBlockCanvas') || !Blockly.utils.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { - throw 'Couldn\'t clear and hide the drag surface. A node was missing.'; + throw Error('Couldn\'t clear and hide the drag surface. ' + + 'A node was missing.'); } // If there is a previous sibling, put the blockCanvas back right afterwards, @@ -160,8 +161,9 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { Blockly.utils.insertAfter_(bubbleCanvas, blockCanvas); // Hide the drag surface. this.SVG_.style.display = 'none'; - goog.asserts.assert( - this.SVG_.childNodes.length == 0, 'Drag surface was not cleared.'); + if (this.SVG_.childNodes.length) { + throw TypeError('Drag surface was not cleared.'); + } Blockly.utils.setCssTransform(this.SVG_, ''); this.previousSibling_ = null; }; @@ -180,8 +182,9 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { */ Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow = function( blockCanvas, bubbleCanvas, previousSibling, width, height, scale) { - goog.asserts.assert( - this.SVG_.childNodes.length == 0, 'Already dragging a block.'); + if (this.SVG_.childNodes.length) { + throw TypeError('Already dragging a block.'); + } this.previousSibling_ = previousSibling; // Make sure the blocks and bubble canvas are scaled appropriately. blockCanvas.setAttribute('transform', 'translate(0, 0) scale(' + scale + ')'); diff --git a/core/workspace_dragger.js b/core/workspace_dragger.js index 09cb9b818..1181e9f03 100644 --- a/core/workspace_dragger.js +++ b/core/workspace_dragger.js @@ -27,7 +27,6 @@ goog.provide('Blockly.WorkspaceDragger'); goog.require('goog.math.Coordinate'); -goog.require('goog.asserts'); /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 8ce9d553a..56e1516ac 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1427,23 +1427,23 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) { tree = Blockly.Options.parseToolboxTree(tree); if (!tree) { if (this.options.languageTree) { - throw 'Can\'t nullify an existing toolbox.'; + throw Error('Can\'t nullify an existing toolbox.'); } return; // No change (null to null). } if (!this.options.languageTree) { - throw 'Existing toolbox is null. Can\'t create new toolbox.'; + throw Error('Existing toolbox is null. Can\'t create new toolbox.'); } if (tree.getElementsByTagName('category').length) { if (!this.toolbox_) { - throw 'Existing toolbox has no categories. Can\'t change mode.'; + throw Error('Existing toolbox has no categories. Can\'t change mode.'); } this.options.languageTree = tree; this.toolbox_.populate_(tree); this.toolbox_.addColour_(); } else { if (!this.flyout_) { - throw 'Existing toolbox has categories. Can\'t change mode.'; + throw Error('Existing toolbox has categories. Can\'t change mode.'); } this.options.languageTree = tree; this.flyout_.show(tree.childNodes); @@ -1878,13 +1878,14 @@ Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_ = function() { */ Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) { if (!this.scrollbar) { - throw 'Attempt to set top level workspace scroll without scrollbars.'; + throw Error('Attempt to set top level workspace scroll without ' + + 'scrollbars.'); } var metrics = this.getMetrics(); - if (goog.isNumber(xyRatio.x)) { + if (typeof xyRatio.x == 'number') { this.scrollX = -metrics.contentWidth * xyRatio.x - metrics.contentLeft; } - if (goog.isNumber(xyRatio.y)) { + if (typeof xyRatio.y == 'number') { this.scrollY = -metrics.contentHeight * xyRatio.y - metrics.contentTop; } var x = this.scrollX + metrics.absoluteLeft; @@ -1932,8 +1933,9 @@ Blockly.WorkspaceSvg.prototype.clear = function() { * given button is clicked. */ Blockly.WorkspaceSvg.prototype.registerButtonCallback = function(key, func) { - goog.asserts.assert(goog.isFunction(func), - 'Button callbacks must be functions.'); + if (typeof func != 'function') { + throw TypeError('Button callbacks must be functions.'); + } this.flyoutButtonCallbacks_[key] = func; }; @@ -1967,8 +1969,9 @@ Blockly.WorkspaceSvg.prototype.removeButtonCallback = function(key) { */ Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key, func) { - goog.asserts.assert(goog.isFunction(func), - 'Toolbox category callbacks must be functions.'); + if (typeof func != 'function') { + throw TypeError('Toolbox category callbacks must be functions.'); + } this.toolboxCategoryCallbacks_[key] = func; }; diff --git a/core/xml.js b/core/xml.js index d8a62902d..a79ff65ec 100644 --- a/core/xml.js +++ b/core/xml.js @@ -373,7 +373,7 @@ Blockly.Xml.textToDom = function(text) { if (!doc || !doc.documentElement || doc.documentElement.nodeName.toLowerCase() != 'xml') { // Whatever we got back from the parser is not the expected structure. - throw Error('Blockly.Xml.textToDom expected an document.'); + throw TypeError('Blockly.Xml.textToDom expected an document.'); } return doc.documentElement; }; @@ -448,7 +448,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { } variablesFirst = false; } else if (name == 'shadow') { - throw Error('Shadow block cannot be a top-level block.'); + throw TypeError('Shadow block cannot be a top-level block.'); } else if (name == 'comment') { if (workspace.rendered) { Blockly.WorkspaceCommentSvg.fromXml(xmlChild, workspace, width); @@ -631,7 +631,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { var block = null; var prototypeName = xmlBlock.getAttribute('type'); if (!prototypeName) { - throw Error('Block type unspecified: ' + xmlBlock.outerHTML); + throw TypeError('Block type unspecified: ' + xmlBlock.outerHTML); } var id = xmlBlock.getAttribute('id'); block = workspace.newBlock(prototypeName, id); @@ -720,7 +720,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { } else if (blockChild.previousConnection) { input.connection.connect(blockChild.previousConnection); } else { - throw Error( + throw TypeError( 'Child block does not have output or previous statement.'); } } @@ -731,16 +731,16 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { } if (childBlockElement) { if (!block.nextConnection) { - throw Error('Next statement does not exist.'); + throw TypeError('Next statement does not exist.'); } // If there is more than one XML 'next' tag. if (block.nextConnection.isConnected()) { - throw Error('Next statement is already connected.'); + throw TypeError('Next statement is already connected.'); } blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement, workspace); if (!blockChild.previousConnection) { - throw Error('Next block does not have previous statement.'); + throw TypeError('Next block does not have previous statement.'); } block.nextConnection.connect(blockChild.previousConnection); } @@ -779,13 +779,13 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { // Ensure all children are also shadows. var children = block.getChildren(false); for (var i = 0, child; child = children[i]; i++) { - if (child.isShadow()) { - throw Error('Shadow block not allowed non-shadow child.'); + if (!child.isShadow()) { + throw TypeError('Shadow block not allowed non-shadow child.'); } } // Ensure this block doesn't have any variable inputs. if (block.getVarModels().length) { - throw Error('Shadow blocks cannot have variable references.'); + throw ReferenceError('Shadow blocks cannot have variable references.'); } block.setShadow(true); } From 03bf9f5e714a27bf7b5cfcd80bc19fbe65d6d949 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sun, 10 Jun 2018 21:28:29 -0700 Subject: [PATCH 11/78] Remove goog.string --- core/block.js | 9 +++++---- core/field_variable.js | 1 - core/gesture.js | 5 +++-- core/touch.js | 13 ++++++------- core/utils.js | 13 ++++++++++++- core/variable_model.js | 12 +++++++++--- core/variables_dynamic.js | 1 - 7 files changed, 35 insertions(+), 19 deletions(-) diff --git a/core/block.js b/core/block.js index c1e43e58c..36fb5ac28 100644 --- a/core/block.js +++ b/core/block.js @@ -41,7 +41,6 @@ goog.require('Blockly.Workspace'); goog.require('Blockly.Xml'); goog.require('goog.array'); goog.require('goog.math.Coordinate'); -goog.require('goog.string'); /** @@ -1055,12 +1054,14 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { } } } - text = goog.string.trim(text.join(' ')) || '???'; + text = text.join(' ').trim() || '???'; if (opt_maxLength) { // TODO: Improve truncation so that text from this block is given priority. // E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...". // E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...". - text = goog.string.truncate(text, opt_maxLength); + if (text.length > opt_maxLength) { + text = text.substring(0, opt_maxLength - 3) + '...'; + } } return text; }; @@ -1260,7 +1261,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { } // Add last dummy input if needed. if (elements.length && (typeof elements[elements.length - 1] == 'string' || - goog.string.startsWith( + Blockly.utils.startsWith( elements[elements.length - 1]['type'], 'field_'))) { var dummyInput = {type: 'input_dummy'}; if (lastDummyAlign) { diff --git a/core/field_variable.js b/core/field_variable.js index 467586f0e..b742ff1d9 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -30,7 +30,6 @@ goog.require('Blockly.FieldDropdown'); goog.require('Blockly.Msg'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Variables'); -goog.require('goog.string'); /** diff --git a/core/gesture.js b/core/gesture.js index f8b3aa260..7fe357a4b 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -505,8 +505,9 @@ Blockly.Gesture.prototype.doStart = function(e) { return; } - if (goog.string.caseInsensitiveEquals(e.type, 'touchstart') || - (goog.string.caseInsensitiveEquals(e.type, 'pointerdown') && e.pointerType != 'mouse')) { + if ((e.type.toLowerCase() == 'touchstart' || + e.type.toLowerCase() == 'pointerdown') && + e.pointerType != 'mouse') { Blockly.longStart_(e, this); } diff --git a/core/touch.js b/core/touch.js index d5b8c0a36..85c704302 100644 --- a/core/touch.js +++ b/core/touch.js @@ -32,7 +32,6 @@ goog.provide('Blockly.Touch'); goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); -goog.require('goog.string'); /** @@ -198,7 +197,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) { * @param {!Event} e A touch event. */ Blockly.Touch.setClientFromTouch = function(e) { - if (goog.string.startsWith(e.type, 'touch')) { + if (Blockly.utils.startsWith(e.type, 'touch')) { // Map the touch event's properties to the event. var touchPoint = e.changedTouches[0]; e.clientX = touchPoint.clientX; @@ -212,9 +211,9 @@ Blockly.Touch.setClientFromTouch = function(e) { * @return {boolean} true if it is a mouse or touch event; false otherwise. */ Blockly.Touch.isMouseOrTouchEvent = function(e) { - return goog.string.startsWith(e.type, 'touch') || - goog.string.startsWith(e.type, 'mouse') || - goog.string.startsWith(e.type, 'pointer'); + return Blockly.utils.startsWith(e.type, 'touch') || + Blockly.utils.startsWith(e.type, 'mouse') || + Blockly.utils.startsWith(e.type, 'pointer'); }; /** @@ -223,8 +222,8 @@ Blockly.Touch.isMouseOrTouchEvent = function(e) { * @return {boolean} true if it is a touch event; false otherwise. */ Blockly.Touch.isTouchEvent = function(e) { - return goog.string.startsWith(e.type, 'touch') || - goog.string.startsWith(e.type, 'pointer'); + return Blockly.utils.startsWith(e.type, 'touch') || + Blockly.utils.startsWith(e.type, 'pointer'); }; /** diff --git a/core/utils.js b/core/utils.js index 543761c39..478c07228 100644 --- a/core/utils.js +++ b/core/utils.js @@ -525,7 +525,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, // BKY_ is the prefix used to namespace the strings used in Blockly // core files and the predefined blocks in ../blocks/. These strings // are defined in ../msgs/ files. - var bklyKey = goog.string.startsWith(keyUpper, 'BKY_') ? + var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ? keyUpper.substring(4) : null; if (bklyKey && bklyKey in Blockly.Msg) { var rawValue = Blockly.Msg[bklyKey]; @@ -901,3 +901,14 @@ Blockly.utils.getViewportBBox = function() { left: scrollOffset.x }; }; + +/** + * Fast prefix-checker. + * Copied from Closure's goog.string.startsWith. + * @param {string} str The string to check. + * @param {string} prefix A string to look for at the start of `str`. + * @return {boolean} True if `str` begins with `prefix`. + */ +Blockly.utils.startsWith = function(str, prefix) { + return str.lastIndexOf(prefix, 0) == 0; +}; diff --git a/core/variable_model.js b/core/variable_model.js index 339620532..a047b18e7 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -28,8 +28,6 @@ goog.provide('Blockly.VariableModel'); goog.require('Blockly.Events.VarCreate'); -goog.require('goog.string'); - /** * Class for a variable model. @@ -97,5 +95,13 @@ Blockly.VariableModel.prototype.getId = function() { * @package */ Blockly.VariableModel.compareByName = function(var1, var2) { - return goog.string.caseInsensitiveCompare(var1.name, var2.name); + var name1 = var1.name.toLowerCase(); + var name2 = var2.name.toLowerCase(); + if (name1 < name2) { + return -1; + } else if (name1 == name2) { + return 0; + } else { + return 1; + } }; diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index 7cf3e6430..7ee4d8787 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -33,7 +33,6 @@ goog.require('Blockly.constants'); goog.require('Blockly.VariableModel'); // TODO Fix circular dependencies // goog.require('Blockly.Workspace'); -goog.require('goog.string'); Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) { From 06d90c9b3469ab5b2774661035780459ab78c927 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sun, 10 Jun 2018 22:51:55 -0700 Subject: [PATCH 12/78] Remove goog.array --- core/block.js | 7 ++++--- core/block_events.js | 1 - core/block_svg.js | 1 + core/connection.js | 10 +++++++--- core/events.js | 3 +-- core/events_abstract.js | 2 -- core/ui_events.js | 2 -- core/utils.js | 16 ++++++++++++++++ core/variable_events.js | 3 --- core/workspace.js | 9 +++++---- core/workspace_svg.js | 4 ++-- 11 files changed, 36 insertions(+), 22 deletions(-) diff --git a/core/block.js b/core/block.js index 36fb5ac28..38709e781 100644 --- a/core/block.js +++ b/core/block.js @@ -36,10 +36,11 @@ goog.require('Blockly.Events.BlockMove'); goog.require('Blockly.Extensions'); goog.require('Blockly.Input'); goog.require('Blockly.Mutator'); +goog.require('Blockly.utils'); goog.require('Blockly.Warning'); goog.require('Blockly.Workspace'); goog.require('Blockly.Xml'); -goog.require('goog.array'); + goog.require('goog.math.Coordinate'); @@ -496,7 +497,7 @@ Blockly.Block.prototype.setParent = function(newParent) { } if (this.parentBlock_) { // Remove this block from the old parent's child list. - goog.array.remove(this.parentBlock_.childBlocks_, this); + Blockly.utils.arrayRemove(this.parentBlock_.childBlocks_, this); // Disconnect from superior blocks. if (this.previousConnection && this.previousConnection.isConnected()) { @@ -1444,7 +1445,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { } } if (!opt_quiet) { - throw ReferenceErrer('Input not found: ' + name); + throw ReferenceError('Input not found: ' + name); } }; diff --git a/core/block_events.js b/core/block_events.js index 2bc6d6b23..b3a25be6f 100644 --- a/core/block_events.js +++ b/core/block_events.js @@ -37,7 +37,6 @@ goog.provide('Blockly.Events.Move'); // Deprecated. goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); -goog.require('goog.array'); goog.require('goog.math.Coordinate'); diff --git a/core/block_svg.js b/core/block_svg.js index b26396945..fbf9ea947 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -37,6 +37,7 @@ goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('goog.color'); goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/connection.js b/core/connection.js index 23dbdb6cb..d6988c55e 100644 --- a/core/connection.js +++ b/core/connection.js @@ -654,9 +654,13 @@ Blockly.Connection.prototype.toString = function() { } else if (block.nextConnection == this) { msg = 'Next Connection of '; } else { - var parentInput = goog.array.find(block.inputList, function(input) { - return input.connection == this; - }, this); + var parentInput = null; + for (var i = 0, input; input = block.inputList[i]; i++) { + if (input.connection == this) { + parentInput = input; + break; + } + } if (parentInput) { msg = 'Input "' + parentInput.name + '" connection on '; } else { diff --git a/core/events.js b/core/events.js index b57d8c0e5..da4cbd3c7 100644 --- a/core/events.js +++ b/core/events.js @@ -30,7 +30,6 @@ */ goog.provide('Blockly.Events'); -goog.require('goog.array'); goog.require('goog.math.Coordinate'); @@ -193,7 +192,7 @@ Blockly.Events.fireNow_ = function() { * @return {!Array.} Array of filtered events. */ Blockly.Events.filter = function(queueIn, forward) { - var queue = goog.array.clone(queueIn); + var queue = queueIn.slice(); // Shallow copy of queue. if (!forward) { // Undo is merged in reverse order. queue.reverse(); diff --git a/core/events_abstract.js b/core/events_abstract.js index 17eea76d1..156353137 100644 --- a/core/events_abstract.js +++ b/core/events_abstract.js @@ -28,8 +28,6 @@ goog.provide('Blockly.Events.Abstract'); goog.require('Blockly.Events'); -goog.require('goog.array'); -goog.require('goog.math.Coordinate'); /** * Abstract class for an event. diff --git a/core/ui_events.js b/core/ui_events.js index 2430ac928..d3ec6d6da 100644 --- a/core/ui_events.js +++ b/core/ui_events.js @@ -29,8 +29,6 @@ goog.provide('Blockly.Events.Ui'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); -goog.require('goog.array'); -goog.require('goog.math.Coordinate'); /** * Class for a UI event. diff --git a/core/utils.js b/core/utils.js index 478c07228..9fc42a912 100644 --- a/core/utils.js +++ b/core/utils.js @@ -912,3 +912,19 @@ Blockly.utils.getViewportBBox = function() { Blockly.utils.startsWith = function(str, prefix) { return str.lastIndexOf(prefix, 0) == 0; }; + +/** + * Removes the first occurrence of a particular value from an array. + * @param {!Array} arr Array from which to remove + * value. + * @param {*} obj Object to remove. + * @return {boolean} True if an element was removed. + */ +Blockly.utils.arrayRemove = function(arr, obj) { + var i = arr.indexOf(obj); + if (i == -1) { + return false; + } + arr.splice(i, 1); + return true; +}; diff --git a/core/variable_events.js b/core/variable_events.js index 8691dbb0f..b9b40c84c 100644 --- a/core/variable_events.js +++ b/core/variable_events.js @@ -32,9 +32,6 @@ goog.provide('Blockly.Events.VarRename'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); -goog.require('goog.array'); -goog.require('goog.math.Coordinate'); - /** * Abstract class for a variable event. diff --git a/core/workspace.js b/core/workspace.js index 04952a189..90a3cd3d5 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -26,9 +26,10 @@ goog.provide('Blockly.Workspace'); +goog.require('Blockly.utils'); goog.require('Blockly.VariableMap'); goog.require('Blockly.WorkspaceComment'); -goog.require('goog.array'); + goog.require('goog.math'); @@ -160,7 +161,7 @@ Blockly.Workspace.prototype.addTopBlock = function(block) { * @param {!Blockly.Block} block Block to remove. */ Blockly.Workspace.prototype.removeTopBlock = function(block) { - if (!goog.array.remove(this.topBlocks_, block)) { + if (!Blockly.utils.arrayRemove(this.topBlocks_, block)) { throw Error('Block not present in workspace\'s list of top-most blocks.'); } }; @@ -211,7 +212,7 @@ Blockly.Workspace.prototype.addTopComment = function(comment) { * @package */ Blockly.Workspace.prototype.removeTopComment = function(comment) { - if (!goog.array.remove(this.topComments_, comment)) { + if (!Blockly.utils.arrayRemove(this.topComments_, comment)) { throw Error('Comment not present in workspace\'s list of top-most ' + 'comments.'); } @@ -511,7 +512,7 @@ Blockly.Workspace.prototype.addChangeListener = function(func) { * @param {Function} func Function to stop calling. */ Blockly.Workspace.prototype.removeChangeListener = function(func) { - goog.array.remove(this.listeners_, func); + Blockly.utils.arrayRemove(this.listeners_, func); }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 56e1516ac..ac1d00707 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -38,6 +38,7 @@ goog.require('Blockly.ScrollbarPair'); goog.require('Blockly.Touch'); goog.require('Blockly.TouchGesture'); goog.require('Blockly.Trashcan'); +goog.require('Blockly.utils'); goog.require('Blockly.VariablesDynamic'); goog.require('Blockly.Workspace'); goog.require('Blockly.WorkspaceAudio'); @@ -48,7 +49,6 @@ goog.require('Blockly.WorkspaceDragSurfaceSvg'); goog.require('Blockly.Xml'); goog.require('Blockly.ZoomControls'); -goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -926,7 +926,7 @@ Blockly.WorkspaceSvg.prototype.highlightBlock = function(id, opt_state) { var state = (opt_state === undefined) || opt_state; // Using Set here would be great, but at the cost of IE10 support. if (!state) { - goog.array.remove(this.highlightedBlocks_, block); + Blockly.utils.arrayRemove(this.highlightedBlocks_, block); } else if (this.highlightedBlocks_.indexOf(block) == -1) { this.highlightedBlocks_.push(block); } From eea2794e38d668a0a711ac20870591d528d01958 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 11 Jun 2018 00:25:46 -0700 Subject: [PATCH 13/78] Remove goog.dom.TagName --- core/field_textinput.js | 4 +--- core/inject.js | 2 +- core/toolbox.js | 4 +--- core/tooltip.js | 4 +--- core/widgetdiv.js | 4 +--- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 093715eb7..6ccb643f8 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -29,7 +29,6 @@ goog.provide('Blockly.FieldTextInput'); goog.require('Blockly.Field'); goog.require('Blockly.Msg'); goog.require('goog.dom'); -goog.require('goog.dom.TagName'); goog.require('goog.userAgent'); @@ -191,8 +190,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { Blockly.WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_()); var div = Blockly.WidgetDiv.DIV; // Create the input. - var htmlInput = - goog.dom.createDom(goog.dom.TagName.INPUT, 'blocklyHtmlInput'); + var htmlInput = goog.dom.createDom('input', 'blocklyHtmlInput'); htmlInput.setAttribute('spellcheck', this.spellcheck_); var fontSize = (Blockly.FieldTextInput.FONTSIZE * this.workspace_.scale) + 'pt'; diff --git a/core/inject.js b/core/inject.js index 19c1e8285..0e8e944a5 100644 --- a/core/inject.js +++ b/core/inject.js @@ -56,7 +56,7 @@ Blockly.inject = function(container, opt_options) { throw Error('Error: container is not in current document.'); } var options = new Blockly.Options(opt_options || {}); - var subContainer = goog.dom.createDom(goog.dom.TagName.DIV, 'injectionDiv'); + var subContainer = goog.dom.createDom('div', 'injectionDiv'); container.appendChild(subContainer); var svg = Blockly.createDom_(subContainer, options); diff --git a/core/toolbox.js b/core/toolbox.js index ee5b4bf1b..000e8b968 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -32,7 +32,6 @@ goog.require('Blockly.HorizontalFlyout'); goog.require('Blockly.Touch'); goog.require('Blockly.VerticalFlyout'); goog.require('goog.dom'); -goog.require('goog.dom.TagName'); goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); goog.require('goog.html.SafeHtml'); @@ -155,8 +154,7 @@ Blockly.Toolbox.prototype.init = function() { * HTML container for the Toolbox menu. * @type {Element} */ - this.HtmlDiv = - goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyToolboxDiv'); + this.HtmlDiv = goog.dom.createDom('div', 'blocklyToolboxDiv'); this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR'); svg.parentNode.insertBefore(this.HtmlDiv, svg); diff --git a/core/tooltip.js b/core/tooltip.js index 25527eeef..891571256 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -36,7 +36,6 @@ goog.provide('Blockly.Tooltip'); goog.require('goog.dom'); -goog.require('goog.dom.TagName'); /** @@ -132,8 +131,7 @@ Blockly.Tooltip.createDom = function() { return; // Already created. } // Create an HTML container for popup overlays (e.g. editor widgets). - Blockly.Tooltip.DIV = - goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyTooltipDiv'); + Blockly.Tooltip.DIV = goog.dom.createDom('div', 'blocklyTooltipDiv'); document.body.appendChild(Blockly.Tooltip.DIV); }; diff --git a/core/widgetdiv.js b/core/widgetdiv.js index be8a0e14e..61215b852 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -34,7 +34,6 @@ goog.provide('Blockly.WidgetDiv'); goog.require('Blockly.Css'); goog.require('goog.dom'); -goog.require('goog.dom.TagName'); goog.require('goog.style'); @@ -66,8 +65,7 @@ Blockly.WidgetDiv.createDom = function() { return; // Already created. } // Create an HTML container for popup overlays (e.g. editor widgets). - Blockly.WidgetDiv.DIV = - goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyWidgetDiv'); + Blockly.WidgetDiv.DIV = goog.dom.createDom('div', 'blocklyWidgetDiv'); document.body.appendChild(Blockly.WidgetDiv.DIV); }; From 60cce6cd0c6c6afe0b13f0b093eaaf01323b8b38 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 28 Jun 2018 15:44:33 -0700 Subject: [PATCH 14/78] Remove goog.math angle functions. --- core/bubble.js | 3 +-- core/field_angle.js | 7 +++---- core/utils.js | 20 ++++++++++++++++++++ core/workspace.js | 8 ++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index de58ea440..66d5b68e8 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -29,7 +29,6 @@ goog.provide('Blockly.Bubble'); goog.require('Blockly.Touch'); goog.require('Blockly.Workspace'); goog.require('goog.dom'); -goog.require('goog.math'); goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); @@ -56,7 +55,7 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY, if (this.workspace_.RTL) { angle = -angle; } - this.arrow_radians_ = goog.math.toRadians(angle); + this.arrow_radians_ = Blockly.utils.toRadians(angle); var canvas = workspace.getBubbleCanvas(); canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight))); diff --git a/core/field_angle.js b/core/field_angle.js index a0549c0c3..581860484 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -27,7 +27,6 @@ goog.provide('Blockly.FieldAngle'); goog.require('Blockly.FieldTextInput'); -goog.require('goog.math'); goog.require('goog.userAgent'); @@ -231,7 +230,7 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) { // This shouldn't happen, but let's not let this error propagate further. return; } - angle = goog.math.toDegrees(angle); + angle = Blockly.utils.toDegrees(angle); // 0: East, 90: North, 180: West, 270: South. if (dx < 0) { angle += 180; @@ -278,12 +277,12 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() { return; } var angleDegrees = Number(this.getText()) + Blockly.FieldAngle.OFFSET; - var angleRadians = goog.math.toRadians(angleDegrees); + var angleRadians = Blockly.utils.toRadians(angleDegrees); var path = ['M ', Blockly.FieldAngle.HALF, ',', Blockly.FieldAngle.HALF]; var x2 = Blockly.FieldAngle.HALF; var y2 = Blockly.FieldAngle.HALF; if (!isNaN(angleRadians)) { - var angle1 = goog.math.toRadians(Blockly.FieldAngle.OFFSET); + var angle1 = Blockly.utils.toRadians(Blockly.FieldAngle.OFFSET); var x1 = Math.cos(angle1) * Blockly.FieldAngle.RADIUS; var y1 = Math.sin(angle1) * -Blockly.FieldAngle.RADIUS; if (Blockly.FieldAngle.CLOCKWISE) { diff --git a/core/utils.js b/core/utils.js index 9fc42a912..716fe87d0 100644 --- a/core/utils.js +++ b/core/utils.js @@ -928,3 +928,23 @@ Blockly.utils.arrayRemove = function(arr, obj) { arr.splice(i, 1); return true; }; + +/** + * Converts degrees to radians. + * Copied from Closure's goog.math.toRadians. + * @param {number} angleDegrees Angle in degrees. + * @return {number} Angle in radians. + */ +Blockly.utils.toRadians = function(angleDegrees) { + return angleDegrees * Math.PI / 180; +}; + +/** + * Converts radians to degrees. + * Copied from Closure's goog.math.toDegrees. + * @param {number} angleRadians Angle in radians. + * @return {number} Angle in degrees. + */ +Blockly.utils.toDegrees = function(angleRadians) { + return angleRadians * 180 / Math.PI; +}; diff --git a/core/workspace.js b/core/workspace.js index 90a3cd3d5..19823189f 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -30,8 +30,6 @@ goog.require('Blockly.utils'); goog.require('Blockly.VariableMap'); goog.require('Blockly.WorkspaceComment'); -goog.require('goog.math'); - /** * Class for a workspace. This is a data structure that contains blocks. @@ -176,7 +174,8 @@ Blockly.Workspace.prototype.getTopBlocks = function(ordered) { // Copy the topBlocks_ list. var blocks = [].concat(this.topBlocks_); if (ordered && blocks.length > 1) { - var offset = Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE)); + var offset = + Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE)); if (this.RTL) { offset *= -1; } @@ -232,7 +231,8 @@ Blockly.Workspace.prototype.getTopComments = function(ordered) { // Copy the topComments_ list. var comments = [].concat(this.topComments_); if (ordered && comments.length > 1) { - var offset = Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE)); + var offset = + Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE)); if (this.RTL) { offset *= -1; } From 284b79407e84aa78e387b68ffff7ea0b4126960a Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 28 Jun 2018 15:56:24 -0700 Subject: [PATCH 15/78] Require Blockly.utils where needed. --- core/block_animations.js | 2 ++ core/bubble_dragger.js | 1 + core/comment.js | 2 ++ core/events.js | 2 ++ core/field.js | 1 + core/field_angle.js | 2 ++ core/field_checkbox.js | 1 + core/field_image.js | 2 ++ core/field_label.js | 2 ++ core/field_textinput.js | 2 ++ core/field_variable.js | 1 + core/flyout_base.js | 2 ++ core/flyout_button.js | 2 ++ core/flyout_vertical.js | 2 +- core/gesture.js | 1 + core/icon.js | 2 ++ core/inject.js | 2 ++ core/mutator.js | 2 ++ core/rendered_connection.js | 1 + core/scrollbar.js | 2 ++ core/toolbox.js | 2 ++ core/tooltip.js | 2 ++ core/touch.js | 2 ++ core/touch_gesture.js | 1 + core/trashcan.js | 2 ++ core/variable_map.js | 2 ++ core/variable_model.js | 1 + core/warning.js | 1 + core/workspace_comment.js | 2 +- core/workspace_comment_render_svg.js | 1 + core/workspace_comment_svg.js | 1 + core/zoom_controls.js | 2 ++ 32 files changed, 51 insertions(+), 2 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 63031d515..8c97107ce 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -26,6 +26,8 @@ goog.provide('Blockly.BlockAnimations'); +goog.require('Blockly.utils'); + /** * PID of disconnect UI animation. There can only be one at a time. diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 38c8de487..26f5282c6 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -28,6 +28,7 @@ goog.provide('Blockly.BubbleDragger'); goog.require('Blockly.Bubble'); goog.require('Blockly.Events.CommentMove'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceCommentSvg'); goog.require('goog.math.Coordinate'); diff --git a/core/comment.js b/core/comment.js index 566923430..3b16f1782 100644 --- a/core/comment.js +++ b/core/comment.js @@ -30,6 +30,8 @@ goog.require('Blockly.Bubble'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Icon'); +goog.require('Blockly.utils'); + goog.require('goog.userAgent'); diff --git a/core/events.js b/core/events.js index da4cbd3c7..6a807f5e6 100644 --- a/core/events.js +++ b/core/events.js @@ -30,6 +30,8 @@ */ goog.provide('Blockly.Events'); +goog.require('Blockly.utils'); + goog.require('goog.math.Coordinate'); diff --git a/core/field.js b/core/field.js index 247113c3c..bd9f46246 100644 --- a/core/field.js +++ b/core/field.js @@ -30,6 +30,7 @@ goog.provide('Blockly.Field'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Gesture'); +goog.require('Blockly.utils'); goog.require('goog.dom'); goog.require('goog.math.Size'); diff --git a/core/field_angle.js b/core/field_angle.js index 581860484..a4ef08a2f 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -27,6 +27,8 @@ goog.provide('Blockly.FieldAngle'); goog.require('Blockly.FieldTextInput'); +goog.require('Blockly.utils'); + goog.require('goog.userAgent'); diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 74930ec4a..7d17028f5 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -27,6 +27,7 @@ goog.provide('Blockly.FieldCheckbox'); goog.require('Blockly.Field'); +goog.require('Blockly.utils'); /** diff --git a/core/field_image.js b/core/field_image.js index b41e5ca91..6027b14c4 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -27,6 +27,8 @@ goog.provide('Blockly.FieldImage'); goog.require('Blockly.Field'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.math.Size'); diff --git a/core/field_label.js b/core/field_label.js index fe603e576..ca195b3af 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -28,6 +28,8 @@ goog.provide('Blockly.FieldLabel'); goog.require('Blockly.Field'); goog.require('Blockly.Tooltip'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.math.Size'); diff --git a/core/field_textinput.js b/core/field_textinput.js index 6ccb643f8..87d1c6ac9 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -28,6 +28,8 @@ goog.provide('Blockly.FieldTextInput'); goog.require('Blockly.Field'); goog.require('Blockly.Msg'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.userAgent'); diff --git a/core/field_variable.js b/core/field_variable.js index b742ff1d9..712706d0a 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -28,6 +28,7 @@ goog.provide('Blockly.FieldVariable'); goog.require('Blockly.FieldDropdown'); goog.require('Blockly.Msg'); +goog.require('Blockly.utils'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Variables'); diff --git a/core/flyout_base.js b/core/flyout_base.js index 3647339df..e4e4688cb 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -33,7 +33,9 @@ goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.FlyoutButton'); goog.require('Blockly.Gesture'); goog.require('Blockly.Touch'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); + goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.math.Rect'); diff --git a/core/flyout_button.js b/core/flyout_button.js index 290b76a0d..6fad650b5 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -26,6 +26,8 @@ goog.provide('Blockly.FlyoutButton'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 1ab3fbb40..ec964c767 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -30,8 +30,8 @@ goog.require('Blockly.Block'); goog.require('Blockly.Events'); goog.require('Blockly.Flyout'); goog.require('Blockly.FlyoutButton'); -goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); + goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.math.Rect'); diff --git a/core/gesture.js b/core/gesture.js index 7fe357a4b..bb2070ce6 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -35,6 +35,7 @@ goog.require('Blockly.Events.Ui'); goog.require('Blockly.FlyoutDragger'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceDragger'); goog.require('goog.math.Coordinate'); diff --git a/core/icon.js b/core/icon.js index b51d90efd..fcc379c35 100644 --- a/core/icon.js +++ b/core/icon.js @@ -26,6 +26,8 @@ goog.provide('Blockly.Icon'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/inject.js b/core/inject.js index 0e8e944a5..f88434762 100644 --- a/core/inject.js +++ b/core/inject.js @@ -30,8 +30,10 @@ goog.require('Blockly.BlockDragSurfaceSvg'); goog.require('Blockly.Css'); goog.require('Blockly.Grid'); goog.require('Blockly.Options'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.WorkspaceDragSurfaceSvg'); + goog.require('goog.dom'); goog.require('goog.ui.Component'); goog.require('goog.userAgent'); diff --git a/core/mutator.js b/core/mutator.js index b40680386..1aedae875 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -31,7 +31,9 @@ goog.require('Blockly.Bubble'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Icon'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); + goog.require('goog.dom'); diff --git a/core/rendered_connection.js b/core/rendered_connection.js index bdf60513f..f5e8ef5c9 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -27,6 +27,7 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); +goog.require('Blockly.utils'); /** diff --git a/core/scrollbar.js b/core/scrollbar.js index bbaff04cf..7597ba5a1 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -27,6 +27,8 @@ goog.provide('Blockly.Scrollbar'); goog.provide('Blockly.ScrollbarPair'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.events'); diff --git a/core/toolbox.js b/core/toolbox.js index 000e8b968..b87929a6b 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -30,7 +30,9 @@ goog.require('Blockly.Events.Ui'); goog.require('Blockly.Flyout'); goog.require('Blockly.HorizontalFlyout'); goog.require('Blockly.Touch'); +goog.require('Blockly.utils'); goog.require('Blockly.VerticalFlyout'); + goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); diff --git a/core/tooltip.js b/core/tooltip.js index 891571256..f93f3ae38 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -35,6 +35,8 @@ **/ goog.provide('Blockly.Tooltip'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); diff --git a/core/touch.js b/core/touch.js index 85c704302..f7d6216ce 100644 --- a/core/touch.js +++ b/core/touch.js @@ -30,6 +30,8 @@ **/ goog.provide('Blockly.Touch'); +goog.require('Blockly.utils'); + goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); diff --git a/core/touch_gesture.js b/core/touch_gesture.js index ce0df947c..8b5f56815 100644 --- a/core/touch_gesture.js +++ b/core/touch_gesture.js @@ -28,6 +28,7 @@ goog.provide('Blockly.TouchGesture'); goog.require('Blockly.Gesture'); +goog.require('Blockly.utils'); goog.require('goog.math.Coordinate'); diff --git a/core/trashcan.js b/core/trashcan.js index a93413118..8580d0a38 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -26,6 +26,8 @@ goog.provide('Blockly.Trashcan'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); goog.require('goog.math'); goog.require('goog.math.Rect'); diff --git a/core/variable_map.js b/core/variable_map.js index f243b0358..963ad5f8c 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -28,6 +28,8 @@ goog.provide('Blockly.VariableMap'); goog.require('Blockly.Events.VarDelete'); goog.require('Blockly.Events.VarRename'); +goog.require('Blockly.utils'); + /** * Class for a variable map. This contains a dictionary data structure with diff --git a/core/variable_model.js b/core/variable_model.js index a047b18e7..f2eb1c742 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -27,6 +27,7 @@ goog.provide('Blockly.VariableModel'); goog.require('Blockly.Events.VarCreate'); +goog.require('Blockly.utils'); /** diff --git a/core/warning.js b/core/warning.js index 147f57f55..9ae3c7ea0 100644 --- a/core/warning.js +++ b/core/warning.js @@ -29,6 +29,7 @@ goog.provide('Blockly.Warning'); goog.require('Blockly.Bubble'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Icon'); +goog.require('Blockly.utils'); /** diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 7067795b4..4ebd95f08 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -30,6 +30,7 @@ goog.require('Blockly.Events.CommentChange'); goog.require('Blockly.Events.CommentCreate'); goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); +goog.require('Blockly.utils'); goog.require('goog.math.Coordinate'); @@ -360,4 +361,3 @@ Blockly.WorkspaceComment.parseAttributes = function(xml) { content: xml.textContent }; }; - diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js index 1a8dcbbe9..c0ee314a5 100644 --- a/core/workspace_comment_render_svg.js +++ b/core/workspace_comment_render_svg.js @@ -26,6 +26,7 @@ goog.provide('Blockly.WorkspaceCommentSvg.render'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceCommentSvg'); diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 8acf3ee08..ba6b9bec5 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -29,6 +29,7 @@ goog.provide('Blockly.WorkspaceCommentSvg'); goog.require('Blockly.Events.CommentCreate'); goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); +goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceComment'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 48eddb2ba..e8af00d40 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -27,6 +27,8 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.Touch'); +goog.require('Blockly.utils'); + goog.require('goog.dom'); From 07d1d8628347164b807127421d49202e30f2c980 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 28 Jun 2018 16:27:39 -0700 Subject: [PATCH 16/78] Remove remaining goog.math --- core/field_number.js | 3 +-- core/trashcan.js | 6 +++--- core/workspace_svg.js | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 708e14940..b757d7413 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -27,7 +27,6 @@ goog.provide('Blockly.FieldNumber'); goog.require('Blockly.FieldTextInput'); -goog.require('goog.math'); /** @@ -112,7 +111,7 @@ Blockly.FieldNumber.prototype.classValidator = function(text) { n = Math.round(n / this.precision_) * this.precision_; } // Get the value in range. - n = goog.math.clamp(n, this.min_, this.max_); + n = Math.min(Math.max(n, this.min_), this.max_); return String(n); }; diff --git a/core/trashcan.js b/core/trashcan.js index 8580d0a38..8ffcac17e 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -29,7 +29,6 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.utils'); goog.require('goog.dom'); -goog.require('goog.math'); goog.require('goog.math.Rect'); @@ -311,13 +310,14 @@ Blockly.Trashcan.prototype.setOpen_ = function(state) { */ Blockly.Trashcan.prototype.animateLid_ = function() { this.lidOpen_ += this.isOpen ? 0.2 : -0.2; - this.lidOpen_ = goog.math.clamp(this.lidOpen_, 0, 1); + this.lidOpen_ = Math.min(Math.max(this.lidOpen_, 0), 1); var lidAngle = this.lidOpen_ * 45; this.svgLid_.setAttribute('transform', 'rotate(' + (this.workspace_.RTL ? -lidAngle : lidAngle) + ',' + (this.workspace_.RTL ? 4 : this.WIDTH_ - 4) + ',' + (this.LID_HEIGHT_ - 2) + ')'); - var opacity = goog.math.lerp(0.4, 0.8, this.lidOpen_); + // Linear interpolation between 0.4 and 0.8. + var opacity = 0.4 + this.lidOpen_ * (0.8 - 0.4); this.svgGroup_.style.opacity = opacity; if (this.lidOpen_ > 0 && this.lidOpen_ < 1) { this.lidTask_ = setTimeout(this.animateLid_.bind(this), 20); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index ac1d00707..1d85c2771 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1090,7 +1090,8 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) { * @return {?Blockly.VariableModel} The newly created variable. * @package */ -Blockly.WorkspaceSvg.prototype.createVariable = function(name, opt_type, opt_id) { +Blockly.WorkspaceSvg.prototype.createVariable = + function(name, opt_type, opt_id) { var newVar = Blockly.WorkspaceSvg.superClass_.createVariable.call( this, name, opt_type, opt_id); this.refreshToolboxSelection(); From 67a18036d038d10f54cb8b6008f94be4e770a58b Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 12:36:59 -0700 Subject: [PATCH 17/78] Fix Travis errors --- core/utils.js | 1 - core/workspace_svg.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/utils.js b/core/utils.js index 716fe87d0..fa099627a 100644 --- a/core/utils.js +++ b/core/utils.js @@ -32,7 +32,6 @@ **/ goog.provide('Blockly.utils'); -goog.require('Blockly.Touch'); goog.require('goog.dom'); goog.require('goog.events.BrowserFeature'); goog.require('goog.math.Coordinate'); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 1d85c2771..dcc4cddef 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1090,8 +1090,8 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) { * @return {?Blockly.VariableModel} The newly created variable. * @package */ -Blockly.WorkspaceSvg.prototype.createVariable = - function(name, opt_type, opt_id) { +Blockly.WorkspaceSvg.prototype.createVariable = function(name, + opt_type, opt_id) { var newVar = Blockly.WorkspaceSvg.superClass_.createVariable.call( this, name, opt_type, opt_id); this.refreshToolboxSelection(); From 8f7674ea080af0e7b20e989d357c9cbcc0784cb7 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 12:43:58 -0700 Subject: [PATCH 18/78] Correct requires for goog.events --- core/flyout_base.js | 1 - core/flyout_horizontal.js | 2 +- core/flyout_vertical.js | 1 - core/scrollbar.js | 2 +- core/touch.js | 1 - core/utils.js | 1 - 6 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index e4e4688cb..9cf01d43f 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -37,7 +37,6 @@ goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); goog.require('goog.dom'); -goog.require('goog.events'); goog.require('goog.math.Rect'); diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index e893ad70d..ec06db373 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -31,8 +31,8 @@ goog.require('Blockly.Events'); goog.require('Blockly.FlyoutButton'); goog.require('Blockly.Flyout'); goog.require('Blockly.WorkspaceSvg'); + goog.require('goog.dom'); -goog.require('goog.events'); goog.require('goog.math.Rect'); goog.require('goog.userAgent'); diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index ec964c767..86548196d 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -33,7 +33,6 @@ goog.require('Blockly.FlyoutButton'); goog.require('Blockly.WorkspaceSvg'); goog.require('goog.dom'); -goog.require('goog.events'); goog.require('goog.math.Rect'); goog.require('goog.userAgent'); diff --git a/core/scrollbar.js b/core/scrollbar.js index 7597ba5a1..37b53f9e4 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -30,7 +30,7 @@ goog.provide('Blockly.ScrollbarPair'); goog.require('Blockly.utils'); goog.require('goog.dom'); -goog.require('goog.events'); +goog.require('goog.events.BrowserFeature'); /** diff --git a/core/touch.js b/core/touch.js index f7d6216ce..46b7b4850 100644 --- a/core/touch.js +++ b/core/touch.js @@ -32,7 +32,6 @@ goog.provide('Blockly.Touch'); goog.require('Blockly.utils'); -goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); diff --git a/core/utils.js b/core/utils.js index fa099627a..cd0e98818 100644 --- a/core/utils.js +++ b/core/utils.js @@ -33,7 +33,6 @@ goog.provide('Blockly.utils'); goog.require('goog.dom'); -goog.require('goog.events.BrowserFeature'); goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); From 0583bee502a11bac7d8acd271a4dc3f26a154c49 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 12:50:52 -0700 Subject: [PATCH 19/78] Correct requires for goog.dom --- core/block_animations.js | 2 ++ core/block_events.js | 1 + core/connection.js | 2 -- core/contextmenu.js | 1 - core/field_colour.js | 1 - core/field_date.js | 1 - core/flyout_horizontal.js | 1 - core/flyout_vertical.js | 1 - core/procedures.js | 2 ++ core/rendered_connection.js | 2 ++ core/variables.js | 2 ++ core/workspace_comment.js | 1 + core/workspace_comment_svg.js | 2 ++ core/ws_comment_events.js | 1 + 14 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 8c97107ce..3ec7a575a 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -28,6 +28,8 @@ goog.provide('Blockly.BlockAnimations'); goog.require('Blockly.utils'); +goog.require('goog.dom'); + /** * PID of disconnect UI animation. There can only be one at a time. diff --git a/core/block_events.js b/core/block_events.js index b3a25be6f..75ded21bc 100644 --- a/core/block_events.js +++ b/core/block_events.js @@ -37,6 +37,7 @@ goog.provide('Blockly.Events.Move'); // Deprecated. goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); +goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/connection.js b/core/connection.js index d6988c55e..91a6f19a7 100644 --- a/core/connection.js +++ b/core/connection.js @@ -28,8 +28,6 @@ goog.provide('Blockly.Connection'); goog.require('Blockly.Events.BlockMove'); -goog.require('goog.dom'); - /** * Class for a connection between blocks. diff --git a/core/contextmenu.js b/core/contextmenu.js index 00dbd16ed..3e64f5ba5 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -34,7 +34,6 @@ goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.utils'); goog.require('Blockly.utils.uiMenu'); -goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.style'); goog.require('goog.ui.Menu'); diff --git a/core/field_colour.js b/core/field_colour.js index dfeee67d9..19d0ac96b 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -29,7 +29,6 @@ goog.provide('Blockly.FieldColour'); goog.require('Blockly.Field'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.style'); goog.require('goog.ui.ColorPicker'); diff --git a/core/field_date.js b/core/field_date.js index 6a5c5a434..b6de147a9 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -31,7 +31,6 @@ goog.require('Blockly.utils'); goog.require('goog.date'); goog.require('goog.date.DateTime'); -goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.i18n.DateTimeSymbols'); goog.require('goog.i18n.DateTimeSymbols_he'); diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index ec06db373..3129e5386 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -32,7 +32,6 @@ goog.require('Blockly.FlyoutButton'); goog.require('Blockly.Flyout'); goog.require('Blockly.WorkspaceSvg'); -goog.require('goog.dom'); goog.require('goog.math.Rect'); goog.require('goog.userAgent'); diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 86548196d..73f98bbc0 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -32,7 +32,6 @@ goog.require('Blockly.Flyout'); goog.require('Blockly.FlyoutButton'); goog.require('Blockly.WorkspaceSvg'); -goog.require('goog.dom'); goog.require('goog.math.Rect'); goog.require('goog.userAgent'); diff --git a/core/procedures.js b/core/procedures.js index 01f72dfd3..5cc94fa1f 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -37,6 +37,8 @@ goog.require('Blockly.Field'); goog.require('Blockly.Names'); goog.require('Blockly.Workspace'); +goog.require('goog.dom'); + /** * Constant to separate procedure names from variables and generated functions diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f5e8ef5c9..7eb8ed72c 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -29,6 +29,8 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); goog.require('Blockly.utils'); +goog.require('goog.dom'); + /** * Class for a connection between blocks that may be rendered on screen. diff --git a/core/variables.js b/core/variables.js index b63925235..fe66eafc6 100644 --- a/core/variables.js +++ b/core/variables.js @@ -34,6 +34,8 @@ goog.require('Blockly.Blocks'); goog.require('Blockly.constants'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Workspace'); + +goog.require('goog.dom'); goog.require('goog.string'); diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 4ebd95f08..06cb7ddd4 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -32,6 +32,7 @@ goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.utils'); +goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index ba6b9bec5..e9bf1ee05 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -32,6 +32,8 @@ goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceComment'); +goog.require('goog.dom'); + /** * Class for a workspace comment's SVG representation. diff --git a/core/ws_comment_events.js b/core/ws_comment_events.js index 0161c1fd5..1118dba50 100644 --- a/core/ws_comment_events.js +++ b/core/ws_comment_events.js @@ -33,6 +33,7 @@ goog.provide('Blockly.Events.CommentMove'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); +goog.require('goog.dom'); goog.require('goog.math.Coordinate'); From 51e86263c7af26d3b15749700a905c3973df4f69 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 14:26:11 -0700 Subject: [PATCH 20/78] Correct requires for goog.math.* --- core/contextmenu.js | 1 + core/events.js | 2 -- core/field_textinput.js | 1 + core/field_variable.js | 2 ++ core/flyout_dragger.js | 2 -- core/rendered_connection.js | 1 + core/scrollbar.js | 1 + core/workspace_comment_render_svg.js | 2 ++ core/workspace_comment_svg.js | 1 + core/workspace_drag_surface_svg.js | 2 -- 10 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/contextmenu.js b/core/contextmenu.js index 3e64f5ba5..b93cc1d73 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -35,6 +35,7 @@ goog.require('Blockly.utils'); goog.require('Blockly.utils.uiMenu'); goog.require('goog.events'); +goog.require('goog.math.Coordinate'); goog.require('goog.style'); goog.require('goog.ui.Menu'); goog.require('goog.ui.MenuItem'); diff --git a/core/events.js b/core/events.js index 6a807f5e6..fe4d1af57 100644 --- a/core/events.js +++ b/core/events.js @@ -32,8 +32,6 @@ goog.provide('Blockly.Events'); goog.require('Blockly.utils'); -goog.require('goog.math.Coordinate'); - /** * Group ID for new events. Grouped events are indivisible. diff --git a/core/field_textinput.js b/core/field_textinput.js index 87d1c6ac9..5398b9b3a 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -31,6 +31,7 @@ goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('goog.dom'); +goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); diff --git a/core/field_variable.js b/core/field_variable.js index 712706d0a..56ef4a798 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -32,6 +32,8 @@ goog.require('Blockly.utils'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Variables'); +goog.require('goog.math.Size'); + /** * Class for a variable's dropdown field. diff --git a/core/flyout_dragger.js b/core/flyout_dragger.js index 2cc5f16a0..a261de57f 100644 --- a/core/flyout_dragger.js +++ b/core/flyout_dragger.js @@ -28,8 +28,6 @@ goog.provide('Blockly.FlyoutDragger'); goog.require('Blockly.WorkspaceDragger'); -goog.require('goog.math.Coordinate'); - /** * Class for a flyout dragger. It moves a flyout workspace around when it is diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 7eb8ed72c..c39f5b989 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -30,6 +30,7 @@ goog.require('Blockly.Connection'); goog.require('Blockly.utils'); goog.require('goog.dom'); +goog.require('goog.math.Coordinate'); /** diff --git a/core/scrollbar.js b/core/scrollbar.js index 37b53f9e4..22db386c9 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -31,6 +31,7 @@ goog.require('Blockly.utils'); goog.require('goog.dom'); goog.require('goog.events.BrowserFeature'); +goog.require('goog.math.Coordinate'); /** diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js index c0ee314a5..5390a0618 100644 --- a/core/workspace_comment_render_svg.js +++ b/core/workspace_comment_render_svg.js @@ -29,6 +29,8 @@ goog.provide('Blockly.WorkspaceCommentSvg.render'); goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceCommentSvg'); +goog.require('goog.math.Coordinate'); + /** * Size of the resize icon. diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index e9bf1ee05..8786f4488 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -33,6 +33,7 @@ goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceComment'); goog.require('goog.dom'); +goog.require('goog.math.Coordinate'); /** diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 07429a2e9..6c45a0cba 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -32,8 +32,6 @@ goog.provide('Blockly.WorkspaceDragSurfaceSvg'); goog.require('Blockly.utils'); -goog.require('goog.math.Coordinate'); - /** * Blocks are moved into this SVG during a drag, improving performance. From c8e08109f2315d305f31a4223b419a9fee34db3f Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 14:33:54 -0700 Subject: [PATCH 21/78] Correct requires for goog.style --- core/contextmenu.js | 1 - core/field_dropdown.js | 1 - 2 files changed, 2 deletions(-) diff --git a/core/contextmenu.js b/core/contextmenu.js index b93cc1d73..d29eae364 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -36,7 +36,6 @@ goog.require('Blockly.utils.uiMenu'); goog.require('goog.events'); goog.require('goog.math.Coordinate'); -goog.require('goog.style'); goog.require('goog.ui.Menu'); goog.require('goog.ui.MenuItem'); goog.require('goog.userAgent'); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 026389560..059070171 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -34,7 +34,6 @@ goog.require('Blockly.utils.uiMenu'); goog.require('goog.dom'); goog.require('goog.events'); -goog.require('goog.style'); goog.require('goog.ui.Menu'); goog.require('goog.ui.MenuItem'); goog.require('goog.userAgent'); From f8028595479a132ef85fe78a3baaa72395352c0e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 15:22:43 -0700 Subject: [PATCH 22/78] Remove goog.dom.removeChildren HTML can be nullified with innerHTML, SVG needs a loop. --- core/field_dropdown.js | 5 ++++- core/tooltip.js | 5 +++-- core/widgetdiv.js | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 059070171..ceddf39a9 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -437,7 +437,10 @@ Blockly.FieldDropdown.prototype.render_ = function() { // Update arrow's colour. this.arrow_.style.fill = this.sourceBlock_.getColour(); } - goog.dom.removeChildren(/** @type {!Element} */ (this.textElement_)); + var child; + while ((child = this.textElement_.firstChild)) { + this.textElement_.removeChild(child); + } goog.dom.removeNode(this.imageElement_); this.imageElement_ = null; diff --git a/core/tooltip.js b/core/tooltip.js index f93f3ae38..cea221c7e 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -133,7 +133,8 @@ Blockly.Tooltip.createDom = function() { return; // Already created. } // Create an HTML container for popup overlays (e.g. editor widgets). - Blockly.Tooltip.DIV = goog.dom.createDom('div', 'blocklyTooltipDiv'); + Blockly.Tooltip.DIV = document.createElement('div'); + Blockly.Tooltip.DIV.className = 'blocklyTooltipDiv'; document.body.appendChild(Blockly.Tooltip.DIV); }; @@ -287,7 +288,7 @@ Blockly.Tooltip.show_ = function() { return; } // Erase all existing text. - goog.dom.removeChildren(/** @type {!Element} */ (Blockly.Tooltip.DIV)); + Blockly.Tooltip.DIV.innerHTML = ''; // Get the new text. var tip = Blockly.Tooltip.element_.tooltip; while (typeof tip == 'function') { diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 61215b852..82de6a02b 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -33,7 +33,6 @@ goog.provide('Blockly.WidgetDiv'); goog.require('Blockly.Css'); -goog.require('goog.dom'); goog.require('goog.style'); @@ -65,7 +64,8 @@ Blockly.WidgetDiv.createDom = function() { return; // Already created. } // Create an HTML container for popup overlays (e.g. editor widgets). - Blockly.WidgetDiv.DIV = goog.dom.createDom('div', 'blocklyWidgetDiv'); + Blockly.WidgetDiv.DIV = document.createElement('div'); + Blockly.WidgetDiv.DIV.className = 'blocklyWidgetDiv'; document.body.appendChild(Blockly.WidgetDiv.DIV); }; @@ -99,7 +99,7 @@ Blockly.WidgetDiv.hide = function() { Blockly.WidgetDiv.DIV.style.top = ''; Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_(); Blockly.WidgetDiv.dispose_ = null; - goog.dom.removeChildren(Blockly.WidgetDiv.DIV); + Blockly.WidgetDiv.DIV.innerHTML = ''; } }; From c51cf0b79cd19d7d4dd6cd1a6dd5879d6773ae9f Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 15:58:41 -0700 Subject: [PATCH 23/78] Remove goog.dom.removeNode --- core/block_animations.js | 6 ++---- core/block_svg.js | 3 +-- core/bubble.js | 3 +-- core/field.js | 7 ++++--- core/field_dropdown.js | 7 ++++--- core/field_image.js | 7 ++++--- core/field_label.js | 7 ++++--- core/flyout_base.js | 5 ++--- core/flyout_button.js | 3 +-- core/icon.js | 3 +-- core/rendered_connection.js | 3 +-- core/scrollbar.js | 5 ++--- core/toolbox.js | 2 +- core/trashcan.js | 3 +-- core/variables_dynamic.js | 2 ++ core/workspace_comment_svg.js | 2 +- core/workspace_svg.js | 2 +- core/xml.js | 4 ++-- core/zoom_controls.js | 4 +--- 19 files changed, 36 insertions(+), 42 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 3ec7a575a..3d35dfee1 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -28,8 +28,6 @@ goog.provide('Blockly.BlockAnimations'); goog.require('Blockly.utils'); -goog.require('goog.dom'); - /** * PID of disconnect UI animation. There can only be one at a time. @@ -83,7 +81,7 @@ Blockly.BlockAnimations.disposeUiStep_ = function(clone, rtl, start, var ms = new Date - start; var percent = ms / 150; if (percent > 1) { - goog.dom.removeNode(clone); + clone.parentNode.removeChild(clone); } else { var x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; @@ -143,7 +141,7 @@ Blockly.BlockAnimations.connectionUiStep_ = function(ripple, start, scale) { var ms = new Date - start; var percent = ms / 150; if (percent > 1) { - goog.dom.removeNode(ripple); + ripple.parentNode.removeChild(ripple); } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; diff --git a/core/block_svg.js b/core/block_svg.js index fbf9ea947..526787c06 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -38,7 +38,6 @@ goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('goog.color'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -849,7 +848,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { } Blockly.BlockSvg.superClass_.dispose.call(this, healStack); - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); blockWorkspace.resizeContents(); // Sever JavaScript to DOM connections. this.svgGroup_ = null; diff --git a/core/bubble.js b/core/bubble.js index 66d5b68e8..f0cc1182f 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Bubble'); goog.require('Blockly.Touch'); goog.require('Blockly.Workspace'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); @@ -605,7 +604,7 @@ Blockly.Bubble.prototype.setColour = function(hexColour) { Blockly.Bubble.prototype.dispose = function() { Blockly.Bubble.unbindDragEvents_(); // Dispose of and unlink the bubble. - goog.dom.removeNode(this.bubbleGroup_); + this.bubbleGroup_.parentNode.removeChild(this.bubbleGroup_); this.bubbleGroup_ = null; this.bubbleArrow_ = null; this.bubbleBack_ = null; diff --git a/core/field.js b/core/field.js index bd9f46246..a3123e38c 100644 --- a/core/field.js +++ b/core/field.js @@ -32,7 +32,6 @@ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Gesture'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Size'); goog.require('goog.style'); goog.require('goog.userAgent'); @@ -228,8 +227,10 @@ Blockly.Field.prototype.dispose = function() { this.mouseDownWrapper_ = null; } this.sourceBlock_ = null; - goog.dom.removeNode(this.fieldGroup_); - this.fieldGroup_ = null; + if (this.fieldGroup_) { + this.fieldGroup_.parentNode.removeChild(this.fieldGroup_); + this.fieldGroup_ = null; + } this.textElement_ = null; this.borderRect_ = null; this.validator_ = null; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index ceddf39a9..b7ca8fdc0 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -32,7 +32,6 @@ goog.require('Blockly.Field'); goog.require('Blockly.utils'); goog.require('Blockly.utils.uiMenu'); -goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.ui.Menu'); goog.require('goog.ui.MenuItem'); @@ -441,8 +440,10 @@ Blockly.FieldDropdown.prototype.render_ = function() { while ((child = this.textElement_.firstChild)) { this.textElement_.removeChild(child); } - goog.dom.removeNode(this.imageElement_); - this.imageElement_ = null; + if (this.imageElement_) { + this.imageElement_.parentNode.removeChild(this.imageElement_); + this.imageElement_ = null; + } if (this.imageJson_) { this.renderSelectedImage_(); diff --git a/core/field_image.js b/core/field_image.js index 6027b14c4..f6d0c534f 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -29,7 +29,6 @@ goog.provide('Blockly.FieldImage'); goog.require('Blockly.Field'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Size'); @@ -120,8 +119,10 @@ Blockly.FieldImage.prototype.init = function() { * Dispose of all DOM objects belonging to this text. */ Blockly.FieldImage.prototype.dispose = function() { - goog.dom.removeNode(this.fieldGroup_); - this.fieldGroup_ = null; + if (this.fieldGroup_) { + this.fieldGroup_.parentNode.removeChild(this.fieldGroup_); + this.fieldGroup_ = null; + } this.imageElement_ = null; }; diff --git a/core/field_label.js b/core/field_label.js index ca195b3af..c473d2be5 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -30,7 +30,6 @@ goog.require('Blockly.Field'); goog.require('Blockly.Tooltip'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Size'); @@ -96,8 +95,10 @@ Blockly.FieldLabel.prototype.init = function() { * Dispose of all DOM objects belonging to this text. */ Blockly.FieldLabel.prototype.dispose = function() { - goog.dom.removeNode(this.textElement_); - this.textElement_ = null; + if (this.textElement_) { + this.textElement_.parentNode.removeChild(this.textElement_); + this.textElement_ = null; + } }; /** diff --git a/core/flyout_base.js b/core/flyout_base.js index 9cf01d43f..65b51ef4b 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -36,7 +36,6 @@ goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); -goog.require('goog.dom'); goog.require('goog.math.Rect'); @@ -277,7 +276,7 @@ Blockly.Flyout.prototype.dispose = function() { this.workspace_ = null; } if (this.svgGroup_) { - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); this.svgGroup_ = null; } this.svgBackground_ = null; @@ -527,7 +526,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { for (var j = 0; j < this.mats_.length; j++) { var rect = this.mats_[j]; if (rect) { - goog.dom.removeNode(rect); + rect.parentNode.removeChild(rect); } } this.mats_.length = 0; diff --git a/core/flyout_button.js b/core/flyout_button.js index 6fad650b5..718a9f692 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -28,7 +28,6 @@ goog.provide('Blockly.FlyoutButton'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -240,7 +239,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { Blockly.unbindEvent_(this.onMouseUpWrapper_); } if (this.svgGroup_) { - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); this.svgGroup_ = null; } this.workspace_ = null; diff --git a/core/icon.js b/core/icon.js index fcc379c35..51c4d8e0d 100644 --- a/core/icon.js +++ b/core/icon.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Icon'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -97,7 +96,7 @@ Blockly.Icon.prototype.createIcon = function() { */ Blockly.Icon.prototype.dispose = function() { // Dispose of and unlink the icon. - goog.dom.removeNode(this.iconGroup_); + this.iconGroup_.parentNode.removeChild(this.iconGroup_); this.iconGroup_ = null; // Dispose of and unlink the bubble. this.setVisible(false); diff --git a/core/rendered_connection.js b/core/rendered_connection.js index c39f5b989..cfcc375e3 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -29,7 +29,6 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -263,7 +262,7 @@ Blockly.RenderedConnection.prototype.unhideAll = function() { * Remove the highlighting around this connection. */ Blockly.RenderedConnection.prototype.unhighlight = function() { - goog.dom.removeNode(Blockly.Connection.highlightedPath_); + Blockly.Connection.highlightedPath_.parentNode.removeChild(Blockly.Connection.highlightedPath_); delete Blockly.Connection.highlightedPath_; }; diff --git a/core/scrollbar.js b/core/scrollbar.js index 22db386c9..5af4c3163 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -29,7 +29,6 @@ goog.provide('Blockly.ScrollbarPair'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.events.BrowserFeature'); goog.require('goog.math.Coordinate'); @@ -73,7 +72,7 @@ Blockly.ScrollbarPair.prototype.oldHostMetrics_ = null; * Unlink from all DOM elements to prevent memory leaks. */ Blockly.ScrollbarPair.prototype.dispose = function() { - goog.dom.removeNode(this.corner_); + this.corner_.parentNode.removeChild(this.corner_); this.corner_ = null; this.workspace_ = null; this.oldHostMetrics_ = null; @@ -348,7 +347,7 @@ Blockly.Scrollbar.prototype.dispose = function() { Blockly.unbindEvent_(this.onMouseDownHandleWrapper_); this.onMouseDownHandleWrapper_ = null; - goog.dom.removeNode(this.outerSvg_); + this.outerSvg_.parentNode.removeChild(this.outerSvg_); this.outerSvg_ = null; this.svgGroup_ = null; this.svgBackground_ = null; diff --git a/core/toolbox.js b/core/toolbox.js index b87929a6b..13d3dcfe8 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -218,7 +218,7 @@ Blockly.Toolbox.prototype.init = function() { Blockly.Toolbox.prototype.dispose = function() { this.flyout_.dispose(); this.tree_.dispose(); - goog.dom.removeNode(this.HtmlDiv); + this.HtmlDiv.parentNode.removeChild(this.HtmlDiv); this.workspace_ = null; this.lastCategory_ = null; }; diff --git a/core/trashcan.js b/core/trashcan.js index 8ffcac17e..6b96a2889 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -28,7 +28,6 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Rect'); @@ -229,7 +228,7 @@ Blockly.Trashcan.prototype.init = function(bottom) { */ Blockly.Trashcan.prototype.dispose = function() { if (this.svgGroup_) { - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); this.svgGroup_ = null; } this.svgLid_ = null; diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index 7ee4d8787..fc76f32a1 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -34,6 +34,8 @@ goog.require('Blockly.VariableModel'); // TODO Fix circular dependencies // goog.require('Blockly.Workspace'); +goog.require('goog.dom'); + Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) { Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'String'); diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 8786f4488..9205ad350 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -118,7 +118,7 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() { Blockly.Events.fire(new Blockly.Events.CommentDelete(this)); } - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); // Sever JavaScript to DOM connections. this.svgGroup_ = null; this.svgRect_ = null; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index dcc4cddef..8e32e29a9 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -494,7 +494,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { } Blockly.WorkspaceSvg.superClass_.dispose.call(this); if (this.svgGroup_) { - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); this.svgGroup_ = null; } this.svgBlockCanvas_ = null; diff --git a/core/xml.js b/core/xml.js index a79ff65ec..ddb608e7b 100644 --- a/core/xml.js +++ b/core/xml.js @@ -289,7 +289,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) { if (textNode.nodeType == 3 && textNode.data.trim() == '' && node.firstChild != textNode) { // Prune whitespace after a tag. - goog.dom.removeNode(textNode); + textNode.parentNode.removeChild(textNode); } } if (node) { @@ -297,7 +297,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) { node = node.nextSibling; if (textNode.nodeType == 3 && textNode.data.trim() == '') { // Prune whitespace before a tag. - goog.dom.removeNode(textNode); + textNode.parentNode.removeChild(textNode); } } } diff --git a/core/zoom_controls.js b/core/zoom_controls.js index e8af00d40..40908a99b 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -29,8 +29,6 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); -goog.require('goog.dom'); - /** * Class for a zoom controls. @@ -124,7 +122,7 @@ Blockly.ZoomControls.prototype.init = function(bottom) { */ Blockly.ZoomControls.prototype.dispose = function() { if (this.svgGroup_) { - goog.dom.removeNode(this.svgGroup_); + this.svgGroup_.parentNode.removeChild(this.svgGroup_); this.svgGroup_ = null; } this.workspace_ = null; From dce60fd152e2e695a0ec40e8149b071bfdde3f02 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 16:53:26 -0700 Subject: [PATCH 24/78] Replace ReferenceError with Error. Change to 4-space indentation rather than aligning with parent structure. --- core/block.js | 22 +++++++++++----------- core/block_svg.js | 2 +- core/events_abstract.js | 2 +- core/field.js | 2 +- core/field_dropdown.js | 2 +- core/generator.js | 4 ++-- core/gesture.js | 10 +++++----- core/input.js | 4 ++-- core/toolbox.js | 2 +- core/variable_map.js | 4 ++-- core/workspace.js | 2 +- core/workspace_drag_surface_svg.js | 8 ++++---- core/workspace_svg.js | 2 +- core/xml.js | 12 ++++++------ 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/block.js b/core/block.js index 38709e781..f5727690e 100644 --- a/core/block.js +++ b/core/block.js @@ -153,7 +153,7 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { this.type = prototypeName; var prototype = Blockly.Blocks[prototypeName]; if (!prototype || typeof prototype != 'object') { - throw Error('Unknown block type: ' + prototypeName); + throw TypeError('Unknown block type: ' + prototypeName); } goog.mixin(this, prototype); } @@ -841,7 +841,7 @@ Blockly.Block.prototype.getFieldValue = function(name) { Blockly.Block.prototype.setFieldValue = function(newValue, name) { var field = this.getField(name); if (!field) { - throw ReferenceError('Field "' + name + '" not found.'); + throw Error('Field "' + name + '" not found.'); } field.setValue(newValue); }; @@ -860,7 +860,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { if (!this.previousConnection) { if (this.outputConnection) { throw Error('Remove output connection prior to adding previous ' + - 'connection.'); + 'connection.'); } this.previousConnection = this.makeConnection_(Blockly.PREVIOUS_STATEMENT); @@ -870,7 +870,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { if (this.previousConnection) { if (this.previousConnection.isConnected()) { throw Error('Must disconnect previous statement before removing ' + - 'connection.'); + 'connection.'); } this.previousConnection.dispose(); this.previousConnection = null; @@ -897,7 +897,7 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { if (this.nextConnection) { if (this.nextConnection.isConnected()) { throw Error('Must disconnect next statement before removing ' + - 'connection.'); + 'connection.'); } this.nextConnection.dispose(); this.nextConnection = null; @@ -920,7 +920,7 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { if (!this.outputConnection) { if (this.previousConnection) { throw Error('Remove previous connection prior to adding output ' + - 'connection.'); + 'connection.'); } this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE); } @@ -1108,7 +1108,7 @@ Blockly.Block.prototype.jsonInit = function(json) { // Validate inputs. if (json['output'] && json['previousStatement']) { throw Error(warningPrefix + - 'Must not have both an output and a previousStatement.'); + 'Must not have both an output and a previousStatement.'); } // Set basic properties of block. @@ -1383,10 +1383,10 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) { } } if (inputIndex == -1) { - throw ReferenceError('Named input "' + name + '" not found.'); + throw Error('Named input "' + name + '" not found.'); } if (refIndex == -1) { - throw ReferenceError('Reference input "' + refName + '" not found.'); + throw Error('Reference input "' + refName + '" not found.'); } this.moveNumberedInputBefore(inputIndex, refIndex); }; @@ -1422,7 +1422,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function( * Remove an input from this block. * @param {string} name The name of the input. * @param {boolean=} opt_quiet True to prevent error if input is not present. - * @throws {ReferenceError} if the input is not present and + * @throws {Error} if the input is not present and * opt_quiet is not true. */ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { @@ -1445,7 +1445,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) { } } if (!opt_quiet) { - throw ReferenceError('Input not found: ' + name); + throw Error('Input not found: ' + name); } }; diff --git a/core/block_svg.js b/core/block_svg.js index 526787c06..b95504cba 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1216,7 +1216,7 @@ Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) { * Remove an input from this block. * @param {string} name The name of the input. * @param {boolean=} opt_quiet True to prevent error if input is not present. - * @throws {ReferenceError} if the input is not present and + * @throws {Error} if the input is not present and * opt_quiet is not true. */ Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) { diff --git a/core/events_abstract.js b/core/events_abstract.js index 156353137..4fa10c82c 100644 --- a/core/events_abstract.js +++ b/core/events_abstract.js @@ -103,7 +103,7 @@ Blockly.Events.Abstract.prototype.getEventWorkspace_ = function() { var workspace = Blockly.Workspace.getById(this.workspaceId); if (!workspace) { throw Error('Workspace is null. Event must have been generated from real' + - ' Blockly events.'); + ' Blockly events.'); } return workspace; }; diff --git a/core/field.js b/core/field.js index a3123e38c..5c8744052 100644 --- a/core/field.js +++ b/core/field.js @@ -171,7 +171,7 @@ Blockly.Field.prototype.EDITABLE = true; */ Blockly.Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { - throw TypeError('Field already bound to a block.'); + throw Error('Field already bound to a block.'); } this.sourceBlock_ = block; }; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index b7ca8fdc0..6c4908871 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -541,7 +541,7 @@ Blockly.FieldDropdown.prototype.dispose = function() { */ Blockly.FieldDropdown.validateOptions_ = function(options) { if (!Array.isArray(options)) { - throw Error('FieldDropdown options must be an array.'); + throw TypeError('FieldDropdown options must be an array.'); } var foundError = false; for (var i = 0; i < options.length; ++i) { diff --git a/core/generator.js b/core/generator.js index 8c05e0483..f6f5e7a75 100644 --- a/core/generator.js +++ b/core/generator.js @@ -174,7 +174,7 @@ Blockly.Generator.prototype.blockToCode = function(block) { var func = this[block.type]; if (typeof func != 'function') { throw Error('Language "' + this.name_ + '" does not know how to generate ' + - ' code for block type "' + block.type + '".'); + ' code for block type "' + block.type + '".'); } // First argument to func.call is the value of 'this' in the generator. // Prior to 24 September 2013 'this' was the only way to access the block. @@ -184,7 +184,7 @@ Blockly.Generator.prototype.blockToCode = function(block) { if (Array.isArray(code)) { // Value blocks return tuples of code and operator order. if (!block.outputConnection) { - throw Error('Expecting string from statement block: ' + block.type); + throw TypeError('Expecting string from statement block: ' + block.type); } return [this.scrub_(block, code[0]), code[1]]; } else if (typeof code == 'string') { diff --git a/core/gesture.js b/core/gesture.js index bb2070ce6..2742384f3 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -652,7 +652,7 @@ Blockly.Gesture.prototype.handleRightClick = function(e) { Blockly.Gesture.prototype.handleWsStart = function(e, ws) { if (this.hasStarted_) { throw Error('Tried to call gesture.handleWsStart, ' + - 'but the gesture had already been started.'); + 'but the gesture had already been started.'); } this.setStartWorkspace_(ws); this.mostRecentEvent_ = e; @@ -668,7 +668,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { if (this.hasStarted_) { throw Error('Tried to call gesture.handleFlyoutStart, ' + - 'but the gesture had already been started.'); + 'but the gesture had already been started.'); } this.setStartFlyout_(flyout); this.handleWsStart(e, flyout.getWorkspace()); @@ -683,7 +683,7 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { Blockly.Gesture.prototype.handleBlockStart = function(e, block) { if (this.hasStarted_) { throw Error('Tried to call gesture.handleBlockStart, ' + - 'but the gesture had already been started.'); + 'but the gesture had already been started.'); } this.setStartBlock(block); this.mostRecentEvent_ = e; @@ -698,7 +698,7 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { if (this.hasStarted_) { throw Error('Tried to call gesture.handleBubbleStart, ' + - 'but the gesture had already been started.'); + 'but the gesture had already been started.'); } this.setStartBubble(bubble); this.mostRecentEvent_ = e; @@ -787,7 +787,7 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() { Blockly.Gesture.prototype.setStartField = function(field) { if (this.hasStarted_) { throw Error('Tried to call gesture.setStartField, ' + - 'but the gesture had already been started.'); + 'but the gesture had already been started.'); } if (!this.startField_) { this.startField_ = field; diff --git a/core/input.js b/core/input.js index 9ac772c6d..99c503356 100644 --- a/core/input.js +++ b/core/input.js @@ -135,7 +135,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { /** * Remove a field from this input. * @param {string} name The name of the field. - * @throws {ReferenceError} if the field is not present. + * @throws {Error} if the field is not present. */ Blockly.Input.prototype.removeField = function(name) { for (var i = 0, field; field = this.fieldRow[i]; i++) { @@ -150,7 +150,7 @@ Blockly.Input.prototype.removeField = function(name) { return; } } - throw ReferenceError('Field "%s" not found.', name); + throw Error('Field "%s" not found.', name); }; /** diff --git a/core/toolbox.js b/core/toolbox.js index 13d3dcfe8..9a9aeffee 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -287,7 +287,7 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) { if (this.tree_.blocks.length) { throw Error('Toolbox cannot have both blocks and categories ' + - 'in the root level.'); + 'in the root level.'); } // Fire a resize event since the toolbox may have changed width and height. diff --git a/core/variable_map.js b/core/variable_map.js index 963ad5f8c..5653f3569 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -177,8 +177,8 @@ Blockly.VariableMap.prototype.createVariable = function(name, if (variable) { if (opt_id && variable.getId() != opt_id) { throw Error('Variable "' + name + '" is already in use and its id is "' + - variable.getId() + '" which conflicts with the passed in ' + - 'id, "' + opt_id + '".'); + variable.getId() + '" which conflicts with the passed in ' + + 'id, "' + opt_id + '".'); } // The variable already exists and has the same ID. return variable; diff --git a/core/workspace.js b/core/workspace.js index 19823189f..2454e2ae9 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -213,7 +213,7 @@ Blockly.Workspace.prototype.addTopComment = function(comment) { Blockly.Workspace.prototype.removeTopComment = function(comment) { if (!Blockly.utils.arrayRemove(this.topComments_, comment)) { throw Error('Comment not present in workspace\'s list of top-most ' + - 'comments.'); + 'comments.'); } // Note: If the comment database starts to hold block comments, this may need // to move to a separate function. diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 6c45a0cba..f91d10876 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -136,7 +136,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation = function() { Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { if (!newSurface) { throw Error('Couldn\'t clear and hide the drag surface: missing ' + - 'new surface.'); + 'new surface.'); } var blockCanvas = this.SVG_.childNodes[0]; var bubbleCanvas = this.SVG_.childNodes[1]; @@ -144,7 +144,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { !Blockly.utils.hasClass(blockCanvas, 'blocklyBlockCanvas') || !Blockly.utils.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { throw Error('Couldn\'t clear and hide the drag surface. ' + - 'A node was missing.'); + 'A node was missing.'); } // If there is a previous sibling, put the blockCanvas back right afterwards, @@ -160,7 +160,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { // Hide the drag surface. this.SVG_.style.display = 'none'; if (this.SVG_.childNodes.length) { - throw TypeError('Drag surface was not cleared.'); + throw Error('Drag surface was not cleared.'); } Blockly.utils.setCssTransform(this.SVG_, ''); this.previousSibling_ = null; @@ -181,7 +181,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow = function( blockCanvas, bubbleCanvas, previousSibling, width, height, scale) { if (this.SVG_.childNodes.length) { - throw TypeError('Already dragging a block.'); + throw Error('Already dragging a block.'); } this.previousSibling_ = previousSibling; // Make sure the blocks and bubble canvas are scaled appropriately. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 8e32e29a9..cd9e51dff 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1880,7 +1880,7 @@ Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_ = function() { Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) { if (!this.scrollbar) { throw Error('Attempt to set top level workspace scroll without ' + - 'scrollbars.'); + 'scrollbars.'); } var metrics = this.getMetrics(); if (typeof xyRatio.x == 'number') { diff --git a/core/xml.js b/core/xml.js index ddb608e7b..8916478d6 100644 --- a/core/xml.js +++ b/core/xml.js @@ -460,8 +460,8 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { Blockly.Xml.domToVariables(xmlChild, workspace); } else { throw Error('\'variables\' tag must exist once before block and ' + - 'shadow tag elements in the workspace XML, but it was found in ' + - 'another location.'); + 'shadow tag elements in the workspace XML, but it was found in ' + + 'another location.'); } variablesFirst = false; } @@ -785,7 +785,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { } // Ensure this block doesn't have any variable inputs. if (block.getVarModels().length) { - throw ReferenceError('Shadow blocks cannot have variable references.'); + throw TypeError('Shadow blocks cannot have variable references.'); } block.setShadow(true); } @@ -815,9 +815,9 @@ Blockly.Xml.domToFieldVariable_ = function(workspace, xml, text, field) { // This should never happen :) if (type != null && type !== variable.type) { throw Error('Serialized variable type with id \'' + - variable.getId() + '\' had type ' + variable.type + ', and ' + - 'does not match variable field that references it: ' + - Blockly.Xml.domToText(xml) + '.'); + variable.getId() + '\' had type ' + variable.type + ', and ' + + 'does not match variable field that references it: ' + + Blockly.Xml.domToText(xml) + '.'); } field.setValue(variable.getId()); From ac2fa96d7f5688f7ebe7188bdf3989c3b7725f1d Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 17:10:12 -0700 Subject: [PATCH 25/78] Replace goog.dom.createDom for creating HTML --- core/field_textinput.js | 6 +++--- core/inject.js | 3 ++- core/toolbox.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 5398b9b3a..e1647ed1f 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -30,7 +30,6 @@ goog.require('Blockly.Field'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); @@ -193,7 +192,8 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { Blockly.WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_()); var div = Blockly.WidgetDiv.DIV; // Create the input. - var htmlInput = goog.dom.createDom('input', 'blocklyHtmlInput'); + var htmlInput = document.createElement('input'); + htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); var fontSize = (Blockly.FieldTextInput.FONTSIZE * this.workspace_.scale) + 'pt'; @@ -301,7 +301,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { Blockly.FieldTextInput.prototype.validate_ = function() { var valid = true; if (!Blockly.FieldTextInput.htmlInput_) { - throw TypeError('htmlInput not defined'); + throw Error('htmlInput not defined'); } var htmlInput = Blockly.FieldTextInput.htmlInput_; if (this.sourceBlock_) { diff --git a/core/inject.js b/core/inject.js index f88434762..46289275e 100644 --- a/core/inject.js +++ b/core/inject.js @@ -58,7 +58,8 @@ Blockly.inject = function(container, opt_options) { throw Error('Error: container is not in current document.'); } var options = new Blockly.Options(opt_options || {}); - var subContainer = goog.dom.createDom('div', 'injectionDiv'); + var subContainer = document.createElement('div'); + subContainer.className = 'injectionDiv'; container.appendChild(subContainer); var svg = Blockly.createDom_(subContainer, options); diff --git a/core/toolbox.js b/core/toolbox.js index 9a9aeffee..6546d4a06 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -156,7 +156,8 @@ Blockly.Toolbox.prototype.init = function() { * HTML container for the Toolbox menu. * @type {Element} */ - this.HtmlDiv = goog.dom.createDom('div', 'blocklyToolboxDiv'); + this.HtmlDiv = document.createElement('div'); + this.HtmlDiv.className = 'blocklyToolboxDiv'; this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR'); svg.parentNode.insertBefore(this.HtmlDiv, svg); From 9a3bd45b22437fa87499f245b677ab675d2a2ce4 Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Thu, 12 Jul 2018 15:34:32 -0700 Subject: [PATCH 26/78] Fix #1960 by collecting block info before icons are destroyed (#1970) The icons in rendered Blockly currently own the comment text. When a block was deleted the icons were being disposed of before the block info was recorded in the event, which meant the comment was lost. This adds some additional logic to block_svg to make sure the event is captured before the icons are removed. --- core/block_svg.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/block_svg.js b/core/block_svg.js index b95504cba..2638466c7 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -837,16 +837,27 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { this.warningTextDb_ = null; } + // If the block is rendered we need to record the event before disposing of + // the icons to prevent losing information. + // TODO (#1969): Remove event generation/firing once comments are fixed. + var deleteEvent; + if (Blockly.Events.isEnabled()) { + deleteEvent = new Blockly.Events.BlockDelete(this); + } Blockly.Events.disable(); try { var icons = this.getIcons(); for (var i = 0; i < icons.length; i++) { icons[i].dispose(); } + // TODO (#1969): Move out of disable block once comments are fixed. + Blockly.BlockSvg.superClass_.dispose.call(this, healStack); } finally { Blockly.Events.enable(); } - Blockly.BlockSvg.superClass_.dispose.call(this, healStack); + if (Blockly.Events.isEnabled() && deleteEvent) { + Blockly.Events.fire(deleteEvent); + } this.svgGroup_.parentNode.removeChild(this.svgGroup_); blockWorkspace.resizeContents(); From c4a0b649453ebf4e14dfa7b8a0c9a2c83cb22366 Mon Sep 17 00:00:00 2001 From: "translatewiki.net" Date: Mon, 16 Jul 2018 16:49:05 +0200 Subject: [PATCH 27/78] Localisation updates from https://translatewiki.net. --- msg/json/nb.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/msg/json/nb.json b/msg/json/nb.json index 9bad100a0..3c022999f 100644 --- a/msg/json/nb.json +++ b/msg/json/nb.json @@ -13,6 +13,7 @@ "DUPLICATE_BLOCK": "duplikat", "ADD_COMMENT": "Legg til kommentar", "REMOVE_COMMENT": "Fjern kommentar", + "DUPLICATE_COMMENT": "Dupliser kommentar", "EXTERNAL_INPUTS": "Eksterne kilder", "INLINE_INPUTS": "Interne kilder", "DELETE_BLOCK": "Slett blokk", @@ -32,9 +33,13 @@ "RENAME_VARIABLE": "Gi nytt navn til variabel…", "RENAME_VARIABLE_TITLE": "Endre navnet til alle '%1' variabler til:", "NEW_VARIABLE": "Opprett variabel…", + "NEW_STRING_VARIABLE": "Oppretter strengvariabel …", + "NEW_NUMBER_VARIABLE": "Oppretter tallvariabel …", + "NEW_COLOUR_VARIABLE": "Oppretter fargevariabel …", + "NEW_VARIABLE_TYPE_TITLE": "Ny variabeltype:", "NEW_VARIABLE_TITLE": "Nytt variabelnavn:", "VARIABLE_ALREADY_EXISTS": "En variabel med navn «%1» finnes allerede.", - "VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE": "En variabel med navn «%1» finnes allerede for en annen variabel av typen «%2».", + "VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE": "En variabel med navn «%1» finnes allerede for en annen type: «%2».", "DELETE_VARIABLE_CONFIRMATION": "Slett %1 bruk av variabelen «%2»?", "CANNOT_DELETE_VARIABLE_PROCEDURE": "Kan ikke slette variabelen «%1» fordi den er del av definisjonen for funksjonen «%2»", "DELETE_VARIABLE": "Slett variabelen «%1»", @@ -361,5 +366,6 @@ "PROCEDURES_HIGHLIGHT_DEF": "Marker funksjonsdefinisjonen", "PROCEDURES_CREATE_DO": "Opprett '%1'", "PROCEDURES_IFRETURN_TOOLTIP": "Hvis en verdi er sann, returner da en annen verdi.", - "PROCEDURES_IFRETURN_WARNING": "Advarsel: Denne blokken kan bare benyttes innenfor en funksjonsdefinisjon." + "PROCEDURES_IFRETURN_WARNING": "Advarsel: Denne blokken kan bare benyttes innenfor en funksjonsdefinisjon.", + "WORKSPACE_COMMENT_DEFAULT_TEXT": "Si noe …" } From 99ebefa1bfc68288479991d052993e2c9d1d351e Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Mon, 16 Jul 2018 10:18:40 -0700 Subject: [PATCH 28/78] Revert "Fix #1960 by collecting block info before icons are destroyed" (#1973) * Revert "Localisation updates from https://translatewiki.net." This reverts commit c4a0b649453ebf4e14dfa7b8a0c9a2c83cb22366. * Revert "Fix #1960 by collecting block info before icons are destroyed (#1970)" This reverts commit 9a3bd45b22437fa87499f245b677ab675d2a2ce4. --- core/block_svg.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 2638466c7..b95504cba 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -837,27 +837,16 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { this.warningTextDb_ = null; } - // If the block is rendered we need to record the event before disposing of - // the icons to prevent losing information. - // TODO (#1969): Remove event generation/firing once comments are fixed. - var deleteEvent; - if (Blockly.Events.isEnabled()) { - deleteEvent = new Blockly.Events.BlockDelete(this); - } Blockly.Events.disable(); try { var icons = this.getIcons(); for (var i = 0; i < icons.length; i++) { icons[i].dispose(); } - // TODO (#1969): Move out of disable block once comments are fixed. - Blockly.BlockSvg.superClass_.dispose.call(this, healStack); } finally { Blockly.Events.enable(); } - if (Blockly.Events.isEnabled() && deleteEvent) { - Blockly.Events.fire(deleteEvent); - } + Blockly.BlockSvg.superClass_.dispose.call(this, healStack); this.svgGroup_.parentNode.removeChild(this.svgGroup_); blockWorkspace.resizeContents(); From c8bfc888c83b2844fad8256335456f05854126a5 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 16 Jul 2018 16:33:44 -0700 Subject: [PATCH 29/78] Throw errors instead of strings. (#1974) Blocks and generators --- blocks/lists.js | 2 +- blocks/logic.js | 4 ++-- blocks/procedures.js | 2 +- generators/dart/lists.js | 10 +++++----- generators/dart/loops.js | 2 +- generators/dart/math.js | 4 ++-- generators/dart/text.js | 6 +++--- generators/javascript/lists.js | 10 +++++----- generators/javascript/loops.js | 2 +- generators/javascript/math.js | 6 +++--- generators/javascript/text.js | 6 +++--- generators/lua/lists.js | 2 +- generators/lua/loops.js | 2 +- generators/lua/math.js | 4 ++-- generators/lua/text.js | 6 +++--- generators/php/lists.js | 10 +++++----- generators/php/loops.js | 2 +- generators/php/math.js | 6 +++--- generators/php/text.js | 2 +- generators/python/lists.js | 10 +++++----- generators/python/loops.js | 2 +- generators/python/math.js | 4 ++-- generators/python/text.js | 6 +++--- 23 files changed, 55 insertions(+), 55 deletions(-) diff --git a/blocks/lists.js b/blocks/lists.js index b8d91c56a..79cae676f 100644 --- a/blocks/lists.js +++ b/blocks/lists.js @@ -819,7 +819,7 @@ Blockly.Blocks['lists_split'] = { } else if (mode == 'JOIN') { return Blockly.Msg['LISTS_SPLIT_TOOLTIP_JOIN']; } - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); }); }, /** diff --git a/blocks/logic.js b/blocks/logic.js index 0d8f72111..01f4e55b6 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -381,7 +381,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { elseStatementConnection = clauseBlock.statementConnection_; break; default: - throw 'Unknown block type.'; + throw TypeError('Unknown block type: ' + clauseBlock.type); } clauseBlock = clauseBlock.nextConnection && clauseBlock.nextConnection.targetBlock(); @@ -419,7 +419,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { inputDo && inputDo.connection.targetConnection; break; default: - throw 'Unknown block type.'; + throw TypeError('Unknown block type: ' + clauseBlock.type); } clauseBlock = clauseBlock.nextConnection && clauseBlock.nextConnection.targetBlock(); diff --git a/blocks/procedures.js b/blocks/procedures.js index 7241dcf50..562bde00f 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -627,7 +627,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { return; } if (paramIds.length != paramNames.length) { - throw 'Error: paramNames and paramIds must be the same length.'; + throw RangeError('paramNames and paramIds must be the same length.'); } this.setCollapsed(false); if (!this.quarkIds_) { diff --git a/generators/dart/lists.js b/generators/dart/lists.js index 42552713c..dd2a493e4 100644 --- a/generators/dart/lists.js +++ b/generators/dart/lists.js @@ -243,7 +243,7 @@ Blockly.Dart['lists_getIndex'] = function(block) { break; } } - throw 'Unhandled combination (lists_getIndex).'; + throw Error('Unhandled combination (lists_getIndex).'); }; Blockly.Dart['lists_setIndex'] = function(block) { @@ -323,7 +323,7 @@ Blockly.Dart['lists_setIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_setIndex).'; + throw Error('Unhandled combination (lists_setIndex).'); }; Blockly.Dart['lists_getSublist'] = function(block) { @@ -348,7 +348,7 @@ Blockly.Dart['lists_getSublist'] = function(block) { var at1 = '0'; break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } switch (where2) { case 'FROM_START': @@ -363,7 +363,7 @@ Blockly.Dart['lists_getSublist'] = function(block) { // There is no second index if LAST option is chosen. break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } if (where2 == 'LAST') { var code = list + '.sublist(' + at1 + ')'; @@ -445,7 +445,7 @@ Blockly.Dart['lists_split'] = function(block) { } var functionName = 'join'; } else { - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); } var code = input + '.' + functionName + '(' + delimiter + ')'; return [code, Blockly.Dart.ORDER_UNARY_POSTFIX]; diff --git a/generators/dart/loops.js b/generators/dart/loops.js index 0dd7c0ce5..6c83a2fd5 100644 --- a/generators/dart/loops.js +++ b/generators/dart/loops.js @@ -159,5 +159,5 @@ Blockly.Dart['controls_flow_statements'] = function(block) { case 'CONTINUE': return 'continue;\n'; } - throw 'Unknown flow statement.'; + throw Error('Unknown flow statement.'); }; diff --git a/generators/dart/math.js b/generators/dart/math.js index 867822beb..c37df0ea3 100644 --- a/generators/dart/math.js +++ b/generators/dart/math.js @@ -160,7 +160,7 @@ Blockly.Dart['math_single'] = function(block) { code = 'Math.atan(' + arg + ') / Math.PI * 180'; break; default: - throw 'Unknown math operator: ' + operator; + throw Error('Unknown math operator: ' + operator); } return [code, Blockly.Dart.ORDER_MULTIPLICATIVE]; }; @@ -426,7 +426,7 @@ Blockly.Dart['math_on_list'] = function(block) { code = functionName + '(' + list + ')'; break; default: - throw 'Unknown operator: ' + func; + throw Error('Unknown operator: ' + func); } return [code, Blockly.Dart.ORDER_UNARY_POSTFIX]; }; diff --git a/generators/dart/text.js b/generators/dart/text.js index 94c60f74b..589b1093b 100644 --- a/generators/dart/text.js +++ b/generators/dart/text.js @@ -136,7 +136,7 @@ Blockly.Dart['text_charAt'] = function(block) { code = functionName + '(' + text + ')'; return [code, Blockly.Dart.ORDER_UNARY_POSTFIX]; } - throw 'Unhandled option (text_charAt).'; + throw Error('Unhandled option (text_charAt).'); }; Blockly.Dart['text_getSubstring'] = function(block) { @@ -164,7 +164,7 @@ Blockly.Dart['text_getSubstring'] = function(block) { var at1 = '0'; break; default: - throw 'Unhandled option (text_getSubstring).'; + throw Error('Unhandled option (text_getSubstring).'); } switch (where2) { case 'FROM_START': @@ -178,7 +178,7 @@ Blockly.Dart['text_getSubstring'] = function(block) { case 'LAST': break; default: - throw 'Unhandled option (text_getSubstring).'; + throw Error('Unhandled option (text_getSubstring).'); } if (where2 == 'LAST') { var code = text + '.substring(' + at1 + ')'; diff --git a/generators/javascript/lists.js b/generators/javascript/lists.js index d9075953f..8ab563503 100644 --- a/generators/javascript/lists.js +++ b/generators/javascript/lists.js @@ -170,7 +170,7 @@ Blockly.JavaScript['lists_getIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_getIndex).'; + throw Error('Unhandled combination (lists_getIndex).'); }; Blockly.JavaScript['lists_setIndex'] = function(block) { @@ -247,7 +247,7 @@ Blockly.JavaScript['lists_setIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_setIndex).'; + throw Error('Unhandled combination (lists_setIndex).'); }; /** @@ -295,7 +295,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) { var at1 = '0'; break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } switch (where2) { case 'FROM_START': @@ -310,7 +310,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) { var at2 = list + '.length'; break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } code = list + '.slice(' + at1 + ', ' + at2 + ')'; } else { @@ -387,7 +387,7 @@ Blockly.JavaScript['lists_split'] = function(block) { } var functionName = 'join'; } else { - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); } var code = input + '.' + functionName + '(' + delimiter + ')'; return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL]; diff --git a/generators/javascript/loops.js b/generators/javascript/loops.js index 1a2ade593..416bbc8be 100644 --- a/generators/javascript/loops.js +++ b/generators/javascript/loops.js @@ -171,5 +171,5 @@ Blockly.JavaScript['controls_flow_statements'] = function(block) { case 'CONTINUE': return 'continue;\n'; } - throw 'Unknown flow statement.'; + throw Error('Unknown flow statement.'); }; diff --git a/generators/javascript/math.js b/generators/javascript/math.js index 0bd265af2..191e7af1e 100644 --- a/generators/javascript/math.js +++ b/generators/javascript/math.js @@ -32,7 +32,7 @@ goog.require('Blockly.JavaScript'); Blockly.JavaScript['math_number'] = function(block) { // Numeric value. var code = parseFloat(block.getFieldValue('NUM')); - var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC : + var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC : Blockly.JavaScript.ORDER_UNARY_NEGATION; return [code, order]; }; @@ -140,7 +140,7 @@ Blockly.JavaScript['math_single'] = function(block) { code = 'Math.atan(' + arg + ') / Math.PI * 180'; break; default: - throw 'Unknown math operator: ' + operator; + throw Error('Unknown math operator: ' + operator); } return [code, Blockly.JavaScript.ORDER_DIVISION]; }; @@ -357,7 +357,7 @@ Blockly.JavaScript['math_on_list'] = function(block) { code = functionName + '(' + list + ')'; break; default: - throw 'Unknown operator: ' + func; + throw Error('Unknown operator: ' + func); } return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL]; }; diff --git a/generators/javascript/text.js b/generators/javascript/text.js index 9e2a375a2..357ca3eb9 100644 --- a/generators/javascript/text.js +++ b/generators/javascript/text.js @@ -137,7 +137,7 @@ Blockly.JavaScript['text_charAt'] = function(block) { var code = functionName + '(' + text + ')'; return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL]; } - throw 'Unhandled option (text_charAt).'; + throw Error('Unhandled option (text_charAt).'); }; /** @@ -186,7 +186,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) { var at1 = '0'; break; default: - throw 'Unhandled option (text_getSubstring).'; + throw Error('Unhandled option (text_getSubstring).'); } switch (where2) { case 'FROM_START': @@ -201,7 +201,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) { var at2 = text + '.length'; break; default: - throw 'Unhandled option (text_getSubstring).'; + throw Error('Unhandled option (text_getSubstring).'); } code = text + '.slice(' + at1 + ', ' + at2 + ')'; } else { diff --git a/generators/lua/lists.js b/generators/lua/lists.js index 6b9fe006e..bdb89baf6 100644 --- a/generators/lua/lists.js +++ b/generators/lua/lists.js @@ -358,7 +358,7 @@ Blockly.Lua['lists_split'] = function(block) { } functionName = 'table.concat'; } else { - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); } var code = functionName + '(' + input + ', ' + delimiter + ')'; return [code, Blockly.Lua.ORDER_HIGH]; diff --git a/generators/lua/loops.js b/generators/lua/loops.js index 785398ff7..d671534a6 100644 --- a/generators/lua/loops.js +++ b/generators/lua/loops.js @@ -162,5 +162,5 @@ Blockly.Lua['controls_flow_statements'] = function(block) { case 'CONTINUE': return Blockly.Lua.CONTINUE_STATEMENT; } - throw 'Unknown flow statement.'; + throw Error('Unknown flow statement.'); }; diff --git a/generators/lua/math.js b/generators/lua/math.js index b60d023da..eefcee4ae 100644 --- a/generators/lua/math.js +++ b/generators/lua/math.js @@ -123,7 +123,7 @@ Blockly.Lua['math_single'] = function(block) { code = 'math.deg(math.atan(' + arg + '))'; break; default: - throw 'Unknown math operator: ' + operator; + throw Error('Unknown math operator: ' + operator); } return [code, Blockly.Lua.ORDER_HIGH]; }; @@ -383,7 +383,7 @@ Blockly.Lua['math_on_list'] = function(block) { break; default: - throw 'Unknown operator: ' + func; + throw Error('Unknown operator: ' + func); } return [functionName + '(' + list + ')', Blockly.Lua.ORDER_HIGH]; }; diff --git a/generators/lua/text.js b/generators/lua/text.js index 8a2ac914a..8f6c9467e 100644 --- a/generators/lua/text.js +++ b/generators/lua/text.js @@ -149,7 +149,7 @@ Blockly.Lua['text_charAt'] = function(block) { } else if (where == 'FROM_END') { var start = '-' + at; } else { - throw 'Unhandled option (text_charAt).'; + throw Error('Unhandled option (text_charAt).'); } } if (start.match(/^-?\w*$/)) { @@ -185,7 +185,7 @@ Blockly.Lua['text_getSubstring'] = function(block) { } else if (where1 == 'FROM_END') { var start = '-' + at1; } else { - throw 'Unhandled option (text_getSubstring)'; + throw Error('Unhandled option (text_getSubstring)'); } // Get end index. @@ -200,7 +200,7 @@ Blockly.Lua['text_getSubstring'] = function(block) { } else if (where2 == 'FROM_END') { var end = '-' + at2; } else { - throw 'Unhandled option (text_getSubstring)'; + throw Error('Unhandled option (text_getSubstring)'); } var code = 'string.sub(' + text + ', ' + start + ', ' + end + ')'; return [code, Blockly.Lua.ORDER_HIGH]; diff --git a/generators/php/lists.js b/generators/php/lists.js index 3fd261695..47262d6a5 100644 --- a/generators/php/lists.js +++ b/generators/php/lists.js @@ -255,7 +255,7 @@ Blockly.PHP['lists_getIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_getIndex).'; + throw Error('Unhandled combination (lists_getIndex).'); }; Blockly.PHP['lists_setIndex'] = function(block) { @@ -355,7 +355,7 @@ Blockly.PHP['lists_setIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_setIndex).'; + throw Error('Unhandled combination (lists_setIndex).'); }; Blockly.PHP['lists_getSublist'] = function(block) { @@ -383,7 +383,7 @@ Blockly.PHP['lists_getSublist'] = function(block) { var at1 = '0'; break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } switch (where2) { case 'FROM_START': @@ -416,7 +416,7 @@ Blockly.PHP['lists_getSublist'] = function(block) { } break; default: - throw 'Unhandled option (lists_getSublist).'; + throw Error('Unhandled option (lists_getSublist).'); } code = 'array_slice(' + list + ', ' + at1 + ', ' + length + ')'; } else { @@ -497,7 +497,7 @@ Blockly.PHP['lists_split'] = function(block) { } var functionName = 'implode'; } else { - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); } var code = functionName + '(' + value_delim + ', ' + value_input + ')'; return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; diff --git a/generators/php/loops.js b/generators/php/loops.js index f306b1053..b504740ba 100644 --- a/generators/php/loops.js +++ b/generators/php/loops.js @@ -160,5 +160,5 @@ Blockly.PHP['controls_flow_statements'] = function(block) { case 'CONTINUE': return 'continue;\n'; } - throw 'Unknown flow statement.'; + throw Error('Unknown flow statement.'); }; diff --git a/generators/php/math.js b/generators/php/math.js index ef9419603..5100d0f4b 100644 --- a/generators/php/math.js +++ b/generators/php/math.js @@ -32,7 +32,7 @@ goog.require('Blockly.PHP'); Blockly.PHP['math_number'] = function(block) { // Numeric value. var code = parseFloat(block.getFieldValue('NUM')); - var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC : + var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC : Blockly.PHP.ORDER_UNARY_NEGATION; if (code == Infinity) { code = 'INF'; @@ -139,7 +139,7 @@ Blockly.PHP['math_single'] = function(block) { code = 'atan(' + arg + ') / pi() * 180'; break; default: - throw 'Unknown math operator: ' + operator; + throw Error('Unknown math operator: ' + operator); } return [code, Blockly.PHP.ORDER_DIVISION]; }; @@ -321,7 +321,7 @@ Blockly.PHP['math_on_list'] = function(block) { code = functionName + '(' + list + ')'; break; default: - throw 'Unknown operator: ' + func; + throw Error('Unknown operator: ' + func); } return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; }; diff --git a/generators/php/text.js b/generators/php/text.js index 7903d31e7..4eeead148 100644 --- a/generators/php/text.js +++ b/generators/php/text.js @@ -152,7 +152,7 @@ Blockly.PHP['text_charAt'] = function(block) { code = functionName + '(' + text + ')'; return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; } - throw 'Unhandled option (text_charAt).'; + throw Error('Unhandled option (text_charAt).'); }; Blockly.PHP['text_getSubstring'] = function(block) { diff --git a/generators/python/lists.js b/generators/python/lists.js index 3d29acf22..657e44d1d 100644 --- a/generators/python/lists.js +++ b/generators/python/lists.js @@ -183,7 +183,7 @@ Blockly.Python['lists_getIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_getIndex).'; + throw Error('Unhandled combination (lists_getIndex).'); }; Blockly.Python['lists_setIndex'] = function(block) { @@ -254,7 +254,7 @@ Blockly.Python['lists_setIndex'] = function(block) { } break; } - throw 'Unhandled combination (lists_setIndex).'; + throw Error('Unhandled combination (lists_setIndex).'); }; Blockly.Python['lists_getSublist'] = function(block) { @@ -277,7 +277,7 @@ Blockly.Python['lists_getSublist'] = function(block) { var at1 = ''; break; default: - throw 'Unhandled option (lists_getSublist)'; + throw Error('Unhandled option (lists_getSublist)'); } switch (where2) { case 'FROM_START': @@ -298,7 +298,7 @@ Blockly.Python['lists_getSublist'] = function(block) { var at2 = ''; break; default: - throw 'Unhandled option (lists_getSublist)'; + throw Error('Unhandled option (lists_getSublist)'); } var code = list + '[' + at1 + ' : ' + at2 + ']'; return [code, Blockly.Python.ORDER_MEMBER]; @@ -349,7 +349,7 @@ Blockly.Python['lists_split'] = function(block) { Blockly.Python.ORDER_MEMBER) || '\'\''; var code = value_delim + '.join(' + value_input + ')'; } else { - throw 'Unknown mode: ' + mode; + throw Error('Unknown mode: ' + mode); } return [code, Blockly.Python.ORDER_FUNCTION_CALL]; }; diff --git a/generators/python/loops.js b/generators/python/loops.js index 3cb1ab900..918bcdfb5 100644 --- a/generators/python/loops.js +++ b/generators/python/loops.js @@ -207,5 +207,5 @@ Blockly.Python['controls_flow_statements'] = function(block) { case 'CONTINUE': return 'continue\n'; } - throw 'Unknown flow statement.'; + throw Error('Unknown flow statement.'); }; diff --git a/generators/python/math.js b/generators/python/math.js index a2595e00c..f1307d71a 100644 --- a/generators/python/math.js +++ b/generators/python/math.js @@ -147,7 +147,7 @@ Blockly.Python['math_single'] = function(block) { code = 'math.atan(' + arg + ') / math.pi * 180'; break; default: - throw 'Unknown math operator: ' + operator; + throw Error('Unknown math operator: ' + operator); } return [code, Blockly.Python.ORDER_MULTIPLICATIVE]; }; @@ -342,7 +342,7 @@ Blockly.Python['math_on_list'] = function(block) { code = 'random.choice(' + list + ')'; break; default: - throw 'Unknown operator: ' + func; + throw Error('Unknown operator: ' + func); } return [code, Blockly.Python.ORDER_FUNCTION_CALL]; }; diff --git a/generators/python/text.js b/generators/python/text.js index 0fefc77d9..2ff767b14 100644 --- a/generators/python/text.js +++ b/generators/python/text.js @@ -140,7 +140,7 @@ Blockly.Python['text_charAt'] = function(block) { code = functionName + '(' + text + ')'; return [code, Blockly.Python.ORDER_FUNCTION_CALL]; } - throw 'Unhandled option (text_charAt).'; + throw Error('Unhandled option (text_charAt).'); }; Blockly.Python['text_getSubstring'] = function(block) { @@ -163,7 +163,7 @@ Blockly.Python['text_getSubstring'] = function(block) { var at1 = ''; break; default: - throw 'Unhandled option (text_getSubstring)'; + throw Error('Unhandled option (text_getSubstring)'); } switch (where2) { case 'FROM_START': @@ -184,7 +184,7 @@ Blockly.Python['text_getSubstring'] = function(block) { var at2 = ''; break; default: - throw 'Unhandled option (text_getSubstring)'; + throw Error('Unhandled option (text_getSubstring)'); } var code = text + '[' + at1 + ' : ' + at2 + ']'; return [code, Blockly.Python.ORDER_MEMBER]; From 4860e34f51c75e4cab6d57a8d14b95bd9c8bbb22 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Mon, 16 Jul 2018 17:01:12 -0700 Subject: [PATCH 30/78] Removing goog.* uses from blocks/*.js files (#1975) * Removing goog.arrays.equals() in blocks/procedures.js, with minor refactor. * Replacing goog.dom.createDom() in blocks/procedures.js, blocks/variables.js, blocks/variables_dynamic.js, and blocks/loops.js. --- blocks/loops.js | 3 ++- blocks/procedures.js | 28 +++++++++++++--------------- blocks/variables.js | 6 ++++-- blocks/variables_dynamic.js | 6 ++++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/blocks/loops.js b/blocks/loops.js index 552886ce4..23ef5824b 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -268,8 +268,9 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = { option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName); var xmlField = Blockly.Variables.generateVariableFieldDom(variable); - var xmlBlock = goog.dom.createDom('block', null, xmlField); + var xmlBlock = document.createElement('block'); xmlBlock.setAttribute('type', 'variables_get'); + xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); } diff --git a/blocks/procedures.js b/blocks/procedures.js index 562bde00f..196205ce4 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -357,15 +357,16 @@ Blockly.Blocks['procedures_defnoreturn'] = { var option = {enabled: true}; var name = this.getFieldValue('NAME'); option.text = Blockly.Msg['PROCEDURES_CREATE_DO'].replace('%1', name); - var xmlMutation = goog.dom.createDom('mutation'); + var xmlMutation = document.createElement('mutation'); xmlMutation.setAttribute('name', name); for (var i = 0; i < this.arguments_.length; i++) { - var xmlArg = goog.dom.createDom('arg'); + var xmlArg = document.createElement('arg'); xmlArg.setAttribute('name', this.arguments_[i]); xmlMutation.appendChild(xmlArg); } - var xmlBlock = goog.dom.createDom('block', null, xmlMutation); + var xmlBlock = document.createElement('block'); xmlBlock.setAttribute('type', this.callType_); + xmlBlock.appendChild(xmlMutation); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); @@ -378,8 +379,9 @@ Blockly.Blocks['procedures_defnoreturn'] = { option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', name); var xmlField = Blockly.Variables.generateVariableFieldDom(argVar); - var xmlBlock = goog.dom.createDom('block', null, xmlField); + var xmlBlock = document.createElement('block'); xmlBlock.setAttribute('type', 'variables_get'); + xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); } @@ -621,7 +623,9 @@ Blockly.Blocks['procedures_callnoreturn'] = { // Reset the quarks (a mutator is about to open). return; } - if (goog.array.equals(this.arguments_, paramNames)) { + // Test arguments (arrays of strings) for changes. '\n' is not a valid + // argument name character, so it is a valid delimiter here. + if (paramNames.join('\n') == this.arguments_.join('\n')) { // No change. this.quarkIds_ = paramIds; return; @@ -633,13 +637,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { if (!this.quarkIds_) { // Initialize tracking for this block. this.quarkConnections_ = {}; - if (paramNames.join('\n') == this.arguments_.join('\n')) { - // No change to the parameters, allow quarkConnections_ to be - // populated with the existing connections. - this.quarkIds_ = paramIds; - } else { - this.quarkIds_ = []; - } + this.quarkIds_ = []; } // Switch off rendering while the block is rebuilt. var savedRendered = this.rendered; @@ -813,8 +811,8 @@ Blockly.Blocks['procedures_callnoreturn'] = { * * */ - var xml = goog.dom.createDom('xml'); - var block = goog.dom.createDom('block'); + var xml = document.createElement('xml'); + var block = document.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); @@ -823,7 +821,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { block.setAttribute('y', y); var mutation = this.mutationToDom(); block.appendChild(mutation); - var field = goog.dom.createDom('field'); + var field = document.createElement('field'); field.setAttribute('name', 'NAME'); field.appendChild(document.createTextNode(this.getProcedureCall())); block.appendChild(field); diff --git a/blocks/variables.js b/blocks/variables.js index 4d7b9f38d..7d0c8d36f 100644 --- a/blocks/variables.js +++ b/blocks/variables.js @@ -115,10 +115,12 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = { var option = {enabled: this.workspace.remainingCapacity() > 0}; var name = this.getField('VAR').getText(); option.text = contextMenuMsg.replace('%1', name); - var xmlField = goog.dom.createDom('field', null, name); + var xmlField = document.createElement('field'); xmlField.setAttribute('name', 'VAR'); - var xmlBlock = goog.dom.createDom('block', null, xmlField); + xmlField.appendChild(document.createTextNode(name)); + var xmlBlock = document.createElement('block'); xmlBlock.setAttribute('type', opposite_type); + xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); } diff --git a/blocks/variables_dynamic.js b/blocks/variables_dynamic.js index 87462b1b4..667cd5be7 100644 --- a/blocks/variables_dynamic.js +++ b/blocks/variables_dynamic.js @@ -113,10 +113,12 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI var option = {enabled: this.workspace.remainingCapacity() > 0}; var name = this.getField('VAR').getText(); option.text = contextMenuMsg.replace('%1', name); - var xmlField = goog.dom.createDom('field', null, name); + var xmlField = document.createElement('field'); xmlField.setAttribute('name', 'VAR'); - var xmlBlock = goog.dom.createDom('block', null, xmlField); + xmlField.appendChild(document.createTextNode(name)); + var xmlBlock = document.createElement('block'); xmlBlock.setAttribute('type', opposite_type); + xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); }, From 7d63b061bc811d12d02facc89c0b539b5aab34b3 Mon Sep 17 00:00:00 2001 From: Gokula Krishna Date: Tue, 17 Jul 2018 14:34:57 +0800 Subject: [PATCH 31/78] Match docs with code --- core/variables.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/variables.js b/core/variables.js index fe66eafc6..5754be083 100644 --- a/core/variables.js +++ b/core/variables.js @@ -106,8 +106,8 @@ Blockly.Variables.allDeveloperVariables = function(workspace) { var hash = {}; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; - if (block.getDeveloperVars) { - var devVars = block.getDeveloperVars(); + if (block.getDeveloperVariables) { + var devVars = block.getDeveloperVariables(); for (var j = 0; j < devVars.length; j++) { hash[devVars[j]] = devVars[j]; } From c815608fdf309e670ef2ad3df50a1284466eac51 Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Tue, 17 Jul 2018 09:35:53 -0700 Subject: [PATCH 32/78] Fix failing svg canvas test (#1977) Partial fix for #1976. This fixes the broken test by initializing the svg for blocks when they're created. --- tests/workspace_svg/workspace_svg_test.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/workspace_svg/workspace_svg_test.js b/tests/workspace_svg/workspace_svg_test.js index f5d924f5b..99387d797 100644 --- a/tests/workspace_svg/workspace_svg_test.js +++ b/tests/workspace_svg/workspace_svg_test.js @@ -24,6 +24,12 @@ function helper_createWorkspaceWithToolbox() { return Blockly.inject('blocklyDiv', {toolbox: toolbox}); } +function helper_createNewBlock(workspace, type) { + var block = workspace.newBlock(type); + block.initSvg(); + return block; +} + function test_createWorkspace() { var workspace = helper_createWorkspaceWithToolbox(); workspace.dispose(); @@ -48,15 +54,20 @@ function test_flatWorkspace() { var workspace = helper_createWorkspaceWithToolbox(); var blockA, blockB; try { - blockA = workspace.newBlock(''); + blockA = helper_createNewBlock(workspace, ''); assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length); assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length); - blockB = workspace.newBlock(''); + blockB = helper_createNewBlock(workspace, ''); assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length); assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length); assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length); - blockA.dispose(); + try { + blockA.dispose(); + } catch (e) { + fail('Failed to delete blockA ' + e); + } + assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length); assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length); From 49955bd9849d6ef8a783e3943a363eb4678fce00 Mon Sep 17 00:00:00 2001 From: "translatewiki.net" Date: Fri, 20 Jul 2018 14:59:28 +0200 Subject: [PATCH 33/78] Localisation updates from https://translatewiki.net. --- msg/json/uk.json | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/msg/json/uk.json b/msg/json/uk.json index b24f63cf0..f9e2d02ae 100644 --- a/msg/json/uk.json +++ b/msg/json/uk.json @@ -16,6 +16,7 @@ "DUPLICATE_BLOCK": "Дублювати", "ADD_COMMENT": "Додати коментар", "REMOVE_COMMENT": "Видалити коментар", + "DUPLICATE_COMMENT": "Дублювати примітку", "EXTERNAL_INPUTS": "Зовнішні входи", "INLINE_INPUTS": "Вбудовані входи", "DELETE_BLOCK": "Видалити блок", @@ -35,9 +36,15 @@ "RENAME_VARIABLE": "Перейменувати змінну...", "RENAME_VARIABLE_TITLE": "Перейменувати усі змінні \"%1\" до:", "NEW_VARIABLE": "Створити змінну...", + "NEW_STRING_VARIABLE": "Створити рядкову змінну...", + "NEW_NUMBER_VARIABLE": "Створити числову змінну...", + "NEW_COLOUR_VARIABLE": "Створити колірну змінну...", + "NEW_VARIABLE_TYPE_TITLE": "Тип нової змінної:", "NEW_VARIABLE_TITLE": "Нова назва змінної:", "VARIABLE_ALREADY_EXISTS": "Змінна з назвою '%1' вже існує.", + "VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE": "Змінна з назвою '%1' вже існує в іншому типі: '%2'.", "DELETE_VARIABLE_CONFIRMATION": "Вилучити %1 використання змінної '%2'?", + "CANNOT_DELETE_VARIABLE_PROCEDURE": "Неможливо видалити змінну '%1', тому що це частина визначення функції '%2'", "DELETE_VARIABLE": "Вилучити змінну '%1'", "COLOUR_PICKER_HELPURL": "https://uk.wikipedia.org/wiki/Колір", "COLOUR_PICKER_TOOLTIP": "Вибрати колір з палітри.", @@ -85,11 +92,16 @@ "IOS_OK": "Готово", "IOS_CANCEL": "Скасувати", "IOS_ERROR": "Помилка", + "IOS_PROCEDURES_INPUTS": "ВХОДИ", + "IOS_PROCEDURES_ADD_INPUT": "+ Додати вхідну змінну", + "IOS_PROCEDURES_ALLOW_STATEMENTS": "Дозволити оператори", + "IOS_PROCEDURES_DUPLICATE_INPUTS_ERROR": "У цієї функції є вхідні змінні, що дублюються.", "IOS_VARIABLES_ADD_VARIABLE": "+ Додати змінну", "IOS_VARIABLES_ADD_BUTTON": "Додати", "IOS_VARIABLES_RENAME_BUTTON": "Перейменувати", "IOS_VARIABLES_DELETE_BUTTON": "Видалити", "IOS_VARIABLES_VARIABLE_NAME": "Назва змінної", + "IOS_VARIABLES_EMPTY_NAME_ERROR": "Ви не можете використовувати порожню назву змінної.", "LOGIC_COMPARE_HELPURL": "https://uk.wikipedia.org/wiki/Нерівність", "LOGIC_COMPARE_TOOLTIP_EQ": "Повертає істину, якщо обидва входи рівні один одному.", "LOGIC_COMPARE_TOOLTIP_NEQ": "Повертає істину, якщо обидва входи не дорівнюють один одному.", @@ -204,6 +216,7 @@ "TEXT_INDEXOF_OPERATOR_FIRST": "знайти перше входження тексту", "TEXT_INDEXOF_OPERATOR_LAST": "знайти останнє входження тексту", "TEXT_CHARAT_HELPURL": "http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Farsubex.htm", + "TEXT_CHARAT_TITLE": "з тексту %1 %2", "TEXT_CHARAT_FROM_START": "отримати символ #", "TEXT_CHARAT_FROM_END": "отримати символ # з кінця", "TEXT_CHARAT_FIRST": "отримати перший символ", @@ -234,6 +247,12 @@ "TEXT_PROMPT_TYPE_NUMBER": "запит числа з повідомленням", "TEXT_PROMPT_TOOLTIP_NUMBER": "Запитати у користувача число.", "TEXT_PROMPT_TOOLTIP_TEXT": "Запитати у користувача деякий текст.", + "TEXT_COUNT_MESSAGE0": "кількість %1 в %2", + "TEXT_COUNT_TOOLTIP": "Підраховує, скільки разів деякий текст з'являється в іншому тексті.", + "TEXT_REPLACE_MESSAGE0": "замінити %1 на %2 в %3", + "TEXT_REPLACE_TOOLTIP": "Замінює всі входження деякого тексту іншим текстом.", + "TEXT_REVERSE_MESSAGE0": "розвернути %1", + "TEXT_REVERSE_TOOLTIP": "Змінює на протилежний порядок символів у тексті.", "LISTS_CREATE_EMPTY_HELPURL": "https://github.com/google/blockly/wiki/Lists#create-empty-list", "LISTS_CREATE_EMPTY_TITLE": "створити порожній список", "LISTS_CREATE_EMPTY_TOOLTIP": "Повертає список, довжиною 0, що не містить записів даних", @@ -307,6 +326,8 @@ "LISTS_SPLIT_WITH_DELIMITER": "з розділювачем", "LISTS_SPLIT_TOOLTIP_SPLIT": "Поділити текст на список текстів, розриваючи на кожному розділювачі.", "LISTS_SPLIT_TOOLTIP_JOIN": "Злити список текстів у єдиний текст, відокремивши розділювачами.", + "LISTS_REVERSE_MESSAGE0": "розвернути %1", + "LISTS_REVERSE_TOOLTIP": "Змінити порядок копії списку на зворотний.", "ORDINAL_NUMBER_SUFFIX": "-ий.", "VARIABLES_GET_TOOLTIP": "Повертає значення цієї змінної.", "VARIABLES_GET_CREATE_SET": "Створити 'встановити %1'", @@ -338,5 +359,6 @@ "PROCEDURES_CREATE_DO": "Створити \"%1\"", "PROCEDURES_IFRETURN_TOOLTIP": "Якщо значення істинне, то повернути друге значення.", "PROCEDURES_IFRETURN_HELPURL": "http://c2.com/cgi/wiki?GuardClause", - "PROCEDURES_IFRETURN_WARNING": "Попередження: цей блок може використовуватися лише в межах визначення функції." + "PROCEDURES_IFRETURN_WARNING": "Попередження: цей блок може використовуватися лише в межах визначення функції.", + "WORKSPACE_COMMENT_DEFAULT_TEXT": "Скажіть щось..." } From f42291ea64f5870e213f670ed3e5a94b64946444 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Fri, 20 Jul 2018 15:54:11 -0700 Subject: [PATCH 34/78] Do not escape % in python strings. (#1982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rebase of PR-1890, commit 793055… from Ellipsis753:patch-1 --- generators/python.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generators/python.js b/generators/python.js index 347a41c2f..1c25f7ba7 100644 --- a/generators/python.js +++ b/generators/python.js @@ -224,8 +224,7 @@ Blockly.Python.scrubNakedValue = function(line) { Blockly.Python.quote_ = function(string) { // Can't use goog.string.quote since % must also be escaped. string = string.replace(/\\/g, '\\\\') - .replace(/\n/g, '\\\n') - .replace(/\%/g, '\\%'); + .replace(/\n/g, '\\\n'); // Follow the CPython behaviour of repr() for a non-byte string. var quote = '\''; From eca22c9bd236dd848d8c98246617ee706a1a163b Mon Sep 17 00:00:00 2001 From: "translatewiki.net" Date: Mon, 23 Jul 2018 09:31:27 +0200 Subject: [PATCH 35/78] Localisation updates from https://translatewiki.net. --- msg/json/eu.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/msg/json/eu.json b/msg/json/eu.json index 885c6878a..fcce47228 100644 --- a/msg/json/eu.json +++ b/msg/json/eu.json @@ -5,7 +5,8 @@ "Asieriko", "Mikel Ibaiba", "Subi", - "RFenichel" + "RFenichel", + "Amaia" ] }, "VARIABLES_DEFAULT_NAME": "Elementua", @@ -13,10 +14,12 @@ "DUPLICATE_BLOCK": "Bikoiztu", "ADD_COMMENT": "Iruzkina gehitu", "REMOVE_COMMENT": "Iruzkina ezabatu", + "DUPLICATE_COMMENT": "Iruzkina bikoiztu", "EXTERNAL_INPUTS": "Kanpoko sarrerak", "DELETE_BLOCK": "Ezabatu blokea", "DELETE_X_BLOCKS": "Ezabatu %1 bloke", "DELETE_ALL_BLOCKS": "Ezabatu %1 blokeak?", + "CLEAN_UP": "Blokeak garbitu", "DISABLE_BLOCK": "Ezgaitu blokea", "ENABLE_BLOCK": "Gaitu blokea", "HELP": "Laguntza", @@ -26,6 +29,8 @@ "RENAME_VARIABLE": "Aldatu aldagaiaren izena...", "RENAME_VARIABLE_TITLE": "Aldatu '%1' aldagai guztien izenak eta izen hau eman:", "NEW_VARIABLE": "Aldagaia sortu...", + "NEW_NUMBER_VARIABLE": "Zenbaki aldagaia sortu...", + "NEW_COLOUR_VARIABLE": "Kolore aldagaia sortu...", "NEW_VARIABLE_TITLE": "Aldagai berriaren izena:", "VARIABLE_ALREADY_EXISTS": "%1 parametro izena dagoeneko existitzen da", "VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE": "%1 izeneko aldagaia dagoeneko existitzen da %2 motako beste aldagai batekin.", From 61803167d895fffb6c0e2a159ecb2899419b55df Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Mon, 23 Jul 2018 10:56:37 -0700 Subject: [PATCH 36/78] Add test for deleting a rendered block with a comment (#1984) Disabled for now as it fails due to #1960. --- tests/jsunit/event_test.js | 3 +- tests/workspace_svg/event_svg_test.js | 90 +++++++++++++++++++++++++++ tests/workspace_svg/index.html | 3 + 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tests/workspace_svg/event_svg_test.js diff --git a/tests/jsunit/event_test.js b/tests/jsunit/event_test.js index 8e88d651e..e297ee939 100644 --- a/tests/jsunit/event_test.js +++ b/tests/jsunit/event_test.js @@ -191,6 +191,7 @@ function test_blockDelete_constructor() { setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']); try { var block = createSimpleTestBlock(workspace); + block.setCommentText('test comment'); var event = new Blockly.Events.BlockDelete(block); checkDeleteEventValues(event, block, ['1'], 'delete'); } finally { @@ -810,4 +811,4 @@ function test_events_filter_nomerge_move() { } finally { eventTest_tearDownWithMockBlocks(); } -} +} \ No newline at end of file diff --git a/tests/workspace_svg/event_svg_test.js b/tests/workspace_svg/event_svg_test.js new file mode 100644 index 000000000..ae1055109 --- /dev/null +++ b/tests/workspace_svg/event_svg_test.js @@ -0,0 +1,90 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +goog.require('goog.testing'); +goog.require('goog.testing.MockControl'); + +function eventSvg_setUpMockBlocks() { + // TODO: Replace with defineGetVarBlock(); + Blockly.defineBlocksWithJsonArray([{ + 'type': 'field_variable_test_block', + 'message0': '%1', + 'args0': [ + { + 'type': 'field_variable', + 'name': 'VAR', + 'variable': 'item' + } + ], + }, + { + 'type': 'simple_test_block', + 'message0': 'simple test block', + 'output': null + }, + { + 'type': 'test_val_in', + 'message0': 'test in %1', + 'args0': [ + { + 'type': 'input_value', + 'name': 'NAME' + } + ] + }]); +} + +function eventSvg_tearDownMockBlocks() { + delete Blockly.Blocks['field_variable_test_block']; + delete Blockly.Blocks['simple_test_block']; + delete Blockly.Blocks['test_val_in']; +} + +function eventSvg_createWorkspaceWithToolbox() { + var toolbox = document.getElementById('toolbox-categories'); + return Blockly.inject('blocklyDiv', {toolbox: toolbox}); +} + +function eventSvg_createNewBlock(workspace, type) { + var block = workspace.newBlock(type); + block.initSvg(); + return block; +} + +function test_blockDelete_svgDispose() { + eventSvg_setUpMockBlocks(); + var workspace = eventSvg_createWorkspaceWithToolbox(); + Blockly.Events.fire = temporary_fireEvent; + temporary_fireEvent.firedEvents_ = []; + try { + var block = eventSvg_createNewBlock(workspace); + block.setCommentText('test comment'); + var event = new Blockly.Events.BlockDelete(block); + workspace.clearUndo(); + block.dispose(); + var firedEvents = workspace.undoStack_; + assertEquals('Delete event created by dispose matches constructed delete event', + Blockly.Xml.domToText(event.oldXml), Blockly.Xml.domToText(firedEvents[0].oldXml)); + } finally { + eventSvg_tearDownMockBlocks(); + workspace.dispose(); + } +} \ No newline at end of file diff --git a/tests/workspace_svg/index.html b/tests/workspace_svg/index.html index 65890169a..41d4a88e5 100644 --- a/tests/workspace_svg/index.html +++ b/tests/workspace_svg/index.html @@ -51,7 +51,10 @@ h1 {

Blockly Workspace testing

+ + +