From 9a93ca486f556490294e4fc115db87c9428db040 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 17 Mar 2021 15:46:17 -0700 Subject: [PATCH] Fix advanced compilation tests for Q1 2021 release (#4709) --- core/input.js | 10 +++---- scripts/gulpfiles/build_tasks.js | 1 + tests/compile/main.js | 1 + tests/compile/test_blocks.js | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 tests/compile/test_blocks.js diff --git a/core/input.js b/core/input.js index 2c0186df3..f3e1ea440 100644 --- a/core/input.js +++ b/core/input.js @@ -21,7 +21,6 @@ goog.require('Blockly.inputTypes'); goog.requireType('Blockly.Block'); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.Field'); -goog.requireType('Blockly.FieldDropdown'); goog.requireType('Blockly.RenderedConnection'); @@ -122,17 +121,16 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { field.name = opt_name; field.setVisible(this.isVisible()); - var fieldDropdown = /** @type {Blockly.FieldDropdown} */ (field); - if (fieldDropdown.prefixField) { + if (field.prefixField) { // Add any prefix. - index = this.insertFieldAt(index, fieldDropdown.prefixField); + index = this.insertFieldAt(index, field.prefixField); } // Add the field to the field row. this.fieldRow.splice(index, 0, field); ++index; - if (fieldDropdown.suffixField) { + if (field.suffixField) { // Add any suffix. - index = this.insertFieldAt(index, fieldDropdown.suffixField); + index = this.insertFieldAt(index, field.suffixField); } if (this.sourceBlock_.rendered) { diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index e35f162d2..00644e9d9 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -447,6 +447,7 @@ function buildLangfiles(done) { function buildAdvancedCompilationTest() { const srcs = [ 'tests/compile/main.js', + 'tests/compile/test_blocks.js', 'core/**/**/*.js', 'blocks/*.js', 'generators/**/*.js']; diff --git a/tests/compile/main.js b/tests/compile/main.js index e4e6445e7..ae71831e7 100644 --- a/tests/compile/main.js +++ b/tests/compile/main.js @@ -14,6 +14,7 @@ goog.require('Blockly.VerticalFlyout'); goog.require('Blockly.Constants.Logic'); goog.require('Blockly.Constants.Loops'); goog.require('Blockly.Constants.Math'); +goog.require('Blockly.Constants.TestBlocks'); goog.require('Blockly.Constants.Text'); goog.require('Blockly.Constants.Lists'); goog.require('Blockly.Constants.Colour'); diff --git a/tests/compile/test_blocks.js b/tests/compile/test_blocks.js new file mode 100644 index 000000000..e5fface57 --- /dev/null +++ b/tests/compile/test_blocks.js @@ -0,0 +1,50 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Test blocks for advanced compilation. + */ +'use strict'; + +goog.provide('Blockly.Constants.TestBlocks'); + +goog.require('Blockly'); +goog.require('Blockly.Blocks'); + + +Blockly.defineBlocksWithJsonArray([ + { + 'type': 'test_style_hex1', + 'message0': 'Block color: Bright purple %1 %2 %3 %4', + 'args0': [ + { + 'type': 'field_input', + 'name': 'TEXT', + 'text': '#992aff', + }, + { + 'type': 'field_dropdown', + 'name': 'DROPDOWN', + 'options': [ + ['option', 'ONE'], + ['option', 'TWO'], + ], + }, + { + 'type': 'field_checkbox', + 'name': 'NAME', + 'checked': true, + }, + { + 'type': 'input_value', + 'name': 'NAME', + }, + ], + 'previousStatement': null, + 'nextStatement': null, + 'colour': '#992aff', + } +]);