diff --git a/.eslintrc.json b/.eslintrc.json index 5a98b4b43..77c488785 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -78,7 +78,6 @@ "browser": true }, "globals": { - "Blockly": true, "goog": true, "exports": true }, diff --git a/blocks/blocks.js b/blocks/blocks.js index f6758c2c5..57d72f598 100644 --- a/blocks/blocks.js +++ b/blocks/blocks.js @@ -11,7 +11,6 @@ 'use strict'; goog.module('Blockly.libraryBlocks'); -goog.module.declareLegacyNamespace(); const colour = goog.require('Blockly.libraryBlocks.colour'); const lists = goog.require('Blockly.libraryBlocks.lists'); diff --git a/core/blockly.js b/core/blockly.js index 391e123ed..64b643510 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -14,7 +14,6 @@ * @namespace Blockly */ goog.module('Blockly'); -goog.module.declareLegacyNamespace(); const ContextMenu = goog.require('Blockly.ContextMenu'); const ContextMenuItems = goog.require('Blockly.ContextMenuItems'); diff --git a/generators/dart.js b/generators/dart.js index d9e873a6e..dacbcd2a5 100644 --- a/generators/dart.js +++ b/generators/dart.js @@ -11,7 +11,6 @@ 'use strict'; goog.module('Blockly.Dart'); -goog.module.declareLegacyNamespace(); const Variables = goog.require('Blockly.Variables'); const stringUtils = goog.require('Blockly.utils.string'); @@ -301,4 +300,4 @@ Dart.getAdjusted = function(block, atId, opt_delta, opt_negate, return at; }; -exports = Dart; +exports.dartGenerator = Dart; diff --git a/generators/dart/all.js b/generators/dart/all.js index f250f7c27..ffd726a26 100644 --- a/generators/dart/all.js +++ b/generators/dart/all.js @@ -13,6 +13,7 @@ goog.module('Blockly.Dart.all'); +const moduleExports = goog.require('Blockly.Dart'); goog.require('Blockly.Dart.colour'); goog.require('Blockly.Dart.lists'); goog.require('Blockly.Dart.logic'); @@ -23,3 +24,4 @@ goog.require('Blockly.Dart.texts'); goog.require('Blockly.Dart.variables'); goog.require('Blockly.Dart.variablesDynamic'); +exports = moduleExports; diff --git a/generators/dart/colour.js b/generators/dart/colour.js index 96aeaea51..324fe65c4 100644 --- a/generators/dart/colour.js +++ b/generators/dart/colour.js @@ -11,7 +11,7 @@ goog.module('Blockly.Dart.colour'); -const Dart = goog.require('Blockly.Dart'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart.addReservedWords('Math'); diff --git a/generators/dart/lists.js b/generators/dart/lists.js index 493cd7a83..28fc9bd89 100644 --- a/generators/dart/lists.js +++ b/generators/dart/lists.js @@ -11,8 +11,8 @@ goog.module('Blockly.Dart.lists'); -const Dart = goog.require('Blockly.Dart'); const {NameType} = goog.require('Blockly.Names'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart.addReservedWords('Math'); diff --git a/generators/dart/logic.js b/generators/dart/logic.js index 56cdaef6c..4fa117987 100644 --- a/generators/dart/logic.js +++ b/generators/dart/logic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Dart.logic'); -const Dart = goog.require('Blockly.Dart'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart['controls_if'] = function(block) { diff --git a/generators/dart/loops.js b/generators/dart/loops.js index 0360737b8..ce66c2d33 100644 --- a/generators/dart/loops.js +++ b/generators/dart/loops.js @@ -11,7 +11,7 @@ goog.module('Blockly.Dart.loops'); -const Dart = goog.require('Blockly.Dart'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); diff --git a/generators/dart/math.js b/generators/dart/math.js index 24c42c2ae..81580c213 100644 --- a/generators/dart/math.js +++ b/generators/dart/math.js @@ -11,8 +11,8 @@ goog.module('Blockly.Dart.math'); -const Dart = goog.require('Blockly.Dart'); const {NameType} = goog.require('Blockly.Names'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart.addReservedWords('Math'); diff --git a/generators/dart/procedures.js b/generators/dart/procedures.js index 1427c0c4e..bf877277e 100644 --- a/generators/dart/procedures.js +++ b/generators/dart/procedures.js @@ -11,8 +11,8 @@ goog.module('Blockly.Dart.procedures'); -const Dart = goog.require('Blockly.Dart'); const {NameType} = goog.require('Blockly.Names'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart['procedures_defreturn'] = function(block) { diff --git a/generators/dart/text.js b/generators/dart/text.js index 5dfb372b0..b611f0d8b 100644 --- a/generators/dart/text.js +++ b/generators/dart/text.js @@ -11,8 +11,8 @@ goog.module('Blockly.Dart.texts'); -const Dart = goog.require('Blockly.Dart'); const {NameType} = goog.require('Blockly.Names'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart.addReservedWords('Html,Math'); diff --git a/generators/dart/variables.js b/generators/dart/variables.js index 38ab39bb4..33e314764 100644 --- a/generators/dart/variables.js +++ b/generators/dart/variables.js @@ -11,8 +11,8 @@ goog.module('Blockly.Dart.variables'); -const Dart = goog.require('Blockly.Dart'); const {NameType} = goog.require('Blockly.Names'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); Dart['variables_get'] = function(block) { diff --git a/generators/dart/variables_dynamic.js b/generators/dart/variables_dynamic.js index 1eac6ed67..50bfdb620 100644 --- a/generators/dart/variables_dynamic.js +++ b/generators/dart/variables_dynamic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Dart.variablesDynamic'); -const Dart = goog.require('Blockly.Dart'); +const {dartGenerator: Dart} = goog.require('Blockly.Dart'); /** @suppress {extraRequire} */ goog.require('Blockly.Dart.variables'); diff --git a/generators/javascript.js b/generators/javascript.js index 74b0fc8a2..75220f760 100644 --- a/generators/javascript.js +++ b/generators/javascript.js @@ -11,7 +11,6 @@ 'use strict'; goog.module('Blockly.JavaScript'); -goog.module.declareLegacyNamespace(); const Variables = goog.require('Blockly.Variables'); const objectUtils = goog.require('Blockly.utils.object'); @@ -320,4 +319,4 @@ JavaScript.getAdjusted = function( return at; }; -exports = JavaScript; +exports.javascriptGenerator = JavaScript; diff --git a/generators/javascript/all.js b/generators/javascript/all.js index 05eca0040..1ffbd3de8 100644 --- a/generators/javascript/all.js +++ b/generators/javascript/all.js @@ -13,6 +13,7 @@ goog.module('Blockly.JavaScript.all'); +const moduleExports = goog.require('Blockly.JavaScript'); goog.require('Blockly.JavaScript.colour'); goog.require('Blockly.JavaScript.lists'); goog.require('Blockly.JavaScript.logic'); @@ -23,3 +24,4 @@ goog.require('Blockly.JavaScript.texts'); goog.require('Blockly.JavaScript.variables'); goog.require('Blockly.JavaScript.variablesDynamic'); +exports = moduleExports; diff --git a/generators/javascript/colour.js b/generators/javascript/colour.js index a2cc64a5a..944a4bb1a 100644 --- a/generators/javascript/colour.js +++ b/generators/javascript/colour.js @@ -11,7 +11,7 @@ goog.module('Blockly.JavaScript.colour'); -const JavaScript = goog.require('Blockly.JavaScript'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['colour_picker'] = function(block) { diff --git a/generators/javascript/lists.js b/generators/javascript/lists.js index e9fbc3598..a614f2a0c 100644 --- a/generators/javascript/lists.js +++ b/generators/javascript/lists.js @@ -12,8 +12,8 @@ goog.module('Blockly.JavaScript.lists'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['lists_create_empty'] = function(block) { diff --git a/generators/javascript/logic.js b/generators/javascript/logic.js index 582d557de..0933b0d7c 100644 --- a/generators/javascript/logic.js +++ b/generators/javascript/logic.js @@ -11,7 +11,7 @@ goog.module('Blockly.JavaScript.logic'); -const JavaScript = goog.require('Blockly.JavaScript'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['controls_if'] = function(block) { diff --git a/generators/javascript/loops.js b/generators/javascript/loops.js index 0626f37e4..dd710cbeb 100644 --- a/generators/javascript/loops.js +++ b/generators/javascript/loops.js @@ -12,8 +12,8 @@ goog.module('Blockly.JavaScript.loops'); const stringUtils = goog.require('Blockly.utils.string'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['controls_repeat_ext'] = function(block) { diff --git a/generators/javascript/math.js b/generators/javascript/math.js index 39d768843..ba4a1a129 100644 --- a/generators/javascript/math.js +++ b/generators/javascript/math.js @@ -12,8 +12,8 @@ goog.module('Blockly.JavaScript.math'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['math_number'] = function(block) { diff --git a/generators/javascript/procedures.js b/generators/javascript/procedures.js index 214e6e196..e47e490f4 100644 --- a/generators/javascript/procedures.js +++ b/generators/javascript/procedures.js @@ -11,8 +11,8 @@ goog.module('Blockly.JavaScript.procedures'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['procedures_defreturn'] = function(block) { diff --git a/generators/javascript/text.js b/generators/javascript/text.js index d619b697f..270c51368 100644 --- a/generators/javascript/text.js +++ b/generators/javascript/text.js @@ -11,8 +11,8 @@ goog.module('Blockly.JavaScript.texts'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); /** diff --git a/generators/javascript/variables.js b/generators/javascript/variables.js index bbb993f16..8ade01244 100644 --- a/generators/javascript/variables.js +++ b/generators/javascript/variables.js @@ -11,8 +11,8 @@ goog.module('Blockly.JavaScript.variables'); -const JavaScript = goog.require('Blockly.JavaScript'); const {NameType} = goog.require('Blockly.Names'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); JavaScript['variables_get'] = function(block) { diff --git a/generators/javascript/variables_dynamic.js b/generators/javascript/variables_dynamic.js index 877c4e1ec..c84dfe58d 100644 --- a/generators/javascript/variables_dynamic.js +++ b/generators/javascript/variables_dynamic.js @@ -11,7 +11,7 @@ goog.module('Blockly.JavaScript.variablesDynamic'); -const JavaScript = goog.require('Blockly.JavaScript'); +const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript'); /** @suppress {extraRequire} */ goog.require('Blockly.JavaScript.variables'); diff --git a/generators/lua.js b/generators/lua.js index 8828f1ae9..bf12f95a2 100644 --- a/generators/lua.js +++ b/generators/lua.js @@ -12,7 +12,6 @@ 'use strict'; goog.module('Blockly.Lua'); -goog.module.declareLegacyNamespace(); const objectUtils = goog.require('Blockly.utils.object'); const stringUtils = goog.require('Blockly.utils.string'); @@ -204,4 +203,4 @@ Lua.scrub_ = function(block, code, opt_thisOnly) { return commentCode + code + nextCode; }; -exports = Lua; +exports.luaGenerator = Lua; diff --git a/generators/lua/all.js b/generators/lua/all.js index af4662de5..7f3bc7581 100644 --- a/generators/lua/all.js +++ b/generators/lua/all.js @@ -13,6 +13,7 @@ goog.module('Blockly.Lua.all'); +const moduleExports = goog.require('Blockly.Lua'); goog.require('Blockly.Lua.colour'); goog.require('Blockly.Lua.lists'); goog.require('Blockly.Lua.logic'); @@ -23,3 +24,4 @@ goog.require('Blockly.Lua.texts'); goog.require('Blockly.Lua.variables'); goog.require('Blockly.Lua.variablesDynamic'); +exports = moduleExports; diff --git a/generators/lua/colour.js b/generators/lua/colour.js index 96660fdbe..be3825ae5 100644 --- a/generators/lua/colour.js +++ b/generators/lua/colour.js @@ -11,7 +11,7 @@ goog.module('Blockly.Lua.colour'); -const Lua = goog.require('Blockly.Lua'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['colour_picker'] = function(block) { diff --git a/generators/lua/lists.js b/generators/lua/lists.js index 5ebea97c4..b67f9033c 100644 --- a/generators/lua/lists.js +++ b/generators/lua/lists.js @@ -11,8 +11,8 @@ goog.module('Blockly.Lua.lists'); -const Lua = goog.require('Blockly.Lua'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['lists_create_empty'] = function(block) { diff --git a/generators/lua/logic.js b/generators/lua/logic.js index d4104295a..53adbeb2b 100644 --- a/generators/lua/logic.js +++ b/generators/lua/logic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Lua.logic'); -const Lua = goog.require('Blockly.Lua'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['controls_if'] = function(block) { diff --git a/generators/lua/loops.js b/generators/lua/loops.js index 37561c1b6..525f1a7d3 100644 --- a/generators/lua/loops.js +++ b/generators/lua/loops.js @@ -11,9 +11,9 @@ goog.module('Blockly.Lua.loops'); -const Lua = goog.require('Blockly.Lua'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); /** diff --git a/generators/lua/math.js b/generators/lua/math.js index b17821a33..e14243ed3 100644 --- a/generators/lua/math.js +++ b/generators/lua/math.js @@ -11,8 +11,8 @@ goog.module('Blockly.Lua.math'); -const Lua = goog.require('Blockly.Lua'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['math_number'] = function(block) { diff --git a/generators/lua/procedures.js b/generators/lua/procedures.js index 4ff548185..a204855a7 100644 --- a/generators/lua/procedures.js +++ b/generators/lua/procedures.js @@ -11,8 +11,8 @@ goog.module('Blockly.Lua.procedures'); -const Lua = goog.require('Blockly.Lua'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['procedures_defreturn'] = function(block) { diff --git a/generators/lua/text.js b/generators/lua/text.js index 74fe842d8..9dcc08b3b 100644 --- a/generators/lua/text.js +++ b/generators/lua/text.js @@ -11,8 +11,8 @@ goog.module('Blockly.Lua.texts'); -const Lua = goog.require('Blockly.Lua'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['text'] = function(block) { diff --git a/generators/lua/variables.js b/generators/lua/variables.js index a57e60112..8fa590945 100644 --- a/generators/lua/variables.js +++ b/generators/lua/variables.js @@ -11,8 +11,8 @@ goog.module('Blockly.Lua.variables'); -const Lua = goog.require('Blockly.Lua'); const {NameType} = goog.require('Blockly.Names'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); Lua['variables_get'] = function(block) { diff --git a/generators/lua/variables_dynamic.js b/generators/lua/variables_dynamic.js index b15859aa7..78a92a354 100644 --- a/generators/lua/variables_dynamic.js +++ b/generators/lua/variables_dynamic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Lua.variablesDynamic'); -const Lua = goog.require('Blockly.Lua'); +const {luaGenerator: Lua} = goog.require('Blockly.Lua'); /** @suppress {extraRequire} */ goog.require('Blockly.Lua.variables'); diff --git a/generators/php.js b/generators/php.js index 703396a9a..748141491 100644 --- a/generators/php.js +++ b/generators/php.js @@ -11,7 +11,6 @@ 'use strict'; goog.module('Blockly.PHP'); -goog.module.declareLegacyNamespace(); const objectUtils = goog.require('Blockly.utils.object'); const stringUtils = goog.require('Blockly.utils.string'); @@ -301,4 +300,4 @@ PHP.getAdjusted = function(block, atId, opt_delta, opt_negate, opt_order) { return at; }; -exports = PHP; +exports.phpGenerator = PHP; diff --git a/generators/php/all.js b/generators/php/all.js index 7d2c7658a..4f707814b 100644 --- a/generators/php/all.js +++ b/generators/php/all.js @@ -13,6 +13,7 @@ goog.module('Blockly.PHP.all'); +const moduleExports = goog.require('Blockly.PHP'); goog.require('Blockly.PHP.colour'); goog.require('Blockly.PHP.lists'); goog.require('Blockly.PHP.logic'); @@ -23,3 +24,4 @@ goog.require('Blockly.PHP.texts'); goog.require('Blockly.PHP.variables'); goog.require('Blockly.PHP.variablesDynamic'); +exports = moduleExports; diff --git a/generators/php/colour.js b/generators/php/colour.js index bbd2fd9d7..09ac78bbb 100644 --- a/generators/php/colour.js +++ b/generators/php/colour.js @@ -11,7 +11,7 @@ goog.module('Blockly.PHP.colour'); -const PHP = goog.require('Blockly.PHP'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['colour_picker'] = function(block) { diff --git a/generators/php/lists.js b/generators/php/lists.js index 1c39a1ab6..95da17e69 100644 --- a/generators/php/lists.js +++ b/generators/php/lists.js @@ -22,10 +22,9 @@ goog.module('Blockly.PHP.lists'); -const PHP = goog.require('Blockly.PHP'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); - +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['lists_create_empty'] = function(block) { // Create an empty list. diff --git a/generators/php/logic.js b/generators/php/logic.js index a7f6c7062..40bd33459 100644 --- a/generators/php/logic.js +++ b/generators/php/logic.js @@ -11,7 +11,7 @@ goog.module('Blockly.PHP.logic'); -const PHP = goog.require('Blockly.PHP'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['controls_if'] = function(block) { diff --git a/generators/php/loops.js b/generators/php/loops.js index 6803c24d6..b90e0f04e 100644 --- a/generators/php/loops.js +++ b/generators/php/loops.js @@ -11,9 +11,9 @@ goog.module('Blockly.PHP.loops'); -const PHP = goog.require('Blockly.PHP'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['controls_repeat_ext'] = function(block) { diff --git a/generators/php/math.js b/generators/php/math.js index 6c8c5ffb4..972f4286f 100644 --- a/generators/php/math.js +++ b/generators/php/math.js @@ -11,8 +11,8 @@ goog.module('Blockly.PHP.math'); -const PHP = goog.require('Blockly.PHP'); const {NameType} = goog.require('Blockly.Names'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['math_number'] = function(block) { diff --git a/generators/php/procedures.js b/generators/php/procedures.js index 812e97053..fc8e45dd9 100644 --- a/generators/php/procedures.js +++ b/generators/php/procedures.js @@ -11,9 +11,9 @@ goog.module('Blockly.PHP.procedures'); -const PHP = goog.require('Blockly.PHP'); const Variables = goog.require('Blockly.Variables'); const {NameType} = goog.require('Blockly.Names'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['procedures_defreturn'] = function(block) { diff --git a/generators/php/text.js b/generators/php/text.js index bc62a95cf..4b0998863 100644 --- a/generators/php/text.js +++ b/generators/php/text.js @@ -11,8 +11,8 @@ goog.module('Blockly.PHP.texts'); -const PHP = goog.require('Blockly.PHP'); const {NameType} = goog.require('Blockly.Names'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['text'] = function(block) { diff --git a/generators/php/variables.js b/generators/php/variables.js index 1a9da02e9..b919f266b 100644 --- a/generators/php/variables.js +++ b/generators/php/variables.js @@ -11,8 +11,8 @@ goog.module('Blockly.PHP.variables'); -const PHP = goog.require('Blockly.PHP'); const {NameType} = goog.require('Blockly.Names'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); PHP['variables_get'] = function(block) { diff --git a/generators/php/variables_dynamic.js b/generators/php/variables_dynamic.js index 889052360..f4d71f481 100644 --- a/generators/php/variables_dynamic.js +++ b/generators/php/variables_dynamic.js @@ -11,7 +11,7 @@ goog.module('Blockly.PHP.variablesDynamic'); -const PHP = goog.require('Blockly.PHP'); +const {phpGenerator: PHP} = goog.require('Blockly.PHP'); /** @suppress {extraRequire} */ goog.require('Blockly.PHP.variables'); diff --git a/generators/python.js b/generators/python.js index b676bb83a..dd00ff2cd 100644 --- a/generators/python.js +++ b/generators/python.js @@ -11,7 +11,6 @@ 'use strict'; goog.module('Blockly.Python'); -goog.module.declareLegacyNamespace(); const stringUtils = goog.require('Blockly.utils.string'); const Variables = goog.require('Blockly.Variables'); @@ -331,4 +330,4 @@ Python.getAdjustedInt = function(block, atId, opt_delta, opt_negate) { return at; }; -exports = Python; +exports.pythonGenerator = Python; diff --git a/generators/python/all.js b/generators/python/all.js index 0c3bfbb47..b6727dc46 100644 --- a/generators/python/all.js +++ b/generators/python/all.js @@ -13,6 +13,7 @@ goog.module('Blockly.Python.all'); +const moduleExports = goog.require('Blockly.Python'); goog.require('Blockly.Python.colour'); goog.require('Blockly.Python.lists'); goog.require('Blockly.Python.logic'); @@ -23,3 +24,4 @@ goog.require('Blockly.Python.texts'); goog.require('Blockly.Python.variables'); goog.require('Blockly.Python.variablesDynamic'); +exports = moduleExports; diff --git a/generators/python/colour.js b/generators/python/colour.js index 454ac65e7..1cbc33747 100644 --- a/generators/python/colour.js +++ b/generators/python/colour.js @@ -11,7 +11,7 @@ goog.module('Blockly.Python.colour'); -const Python = goog.require('Blockly.Python'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['colour_picker'] = function(block) { diff --git a/generators/python/lists.js b/generators/python/lists.js index 7026162ae..e09127cfa 100644 --- a/generators/python/lists.js +++ b/generators/python/lists.js @@ -11,9 +11,9 @@ goog.module('Blockly.Python.lists'); -const Python = goog.require('Blockly.Python'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['lists_create_empty'] = function(block) { diff --git a/generators/python/logic.js b/generators/python/logic.js index 18dd9c53e..ca6ab2d02 100644 --- a/generators/python/logic.js +++ b/generators/python/logic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Python.logic'); -const Python = goog.require('Blockly.Python'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['controls_if'] = function(block) { diff --git a/generators/python/loops.js b/generators/python/loops.js index b3c267f86..929b904c6 100644 --- a/generators/python/loops.js +++ b/generators/python/loops.js @@ -11,9 +11,9 @@ goog.module('Blockly.Python.loops'); -const Python = goog.require('Blockly.Python'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['controls_repeat_ext'] = function(block) { diff --git a/generators/python/math.js b/generators/python/math.js index ca23c1770..077f1acdd 100644 --- a/generators/python/math.js +++ b/generators/python/math.js @@ -11,8 +11,8 @@ goog.module('Blockly.Python.math'); -const Python = goog.require('Blockly.Python'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); // If any new block imports any library, add that library name here. diff --git a/generators/python/procedures.js b/generators/python/procedures.js index b95becd3d..d3737566f 100644 --- a/generators/python/procedures.js +++ b/generators/python/procedures.js @@ -11,9 +11,9 @@ goog.module('Blockly.Python.procedures'); -const Python = goog.require('Blockly.Python'); const Variables = goog.require('Blockly.Variables'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['procedures_defreturn'] = function(block) { diff --git a/generators/python/text.js b/generators/python/text.js index a097cbee2..3a378091c 100644 --- a/generators/python/text.js +++ b/generators/python/text.js @@ -11,9 +11,9 @@ goog.module('Blockly.Python.texts'); -const Python = goog.require('Blockly.Python'); const stringUtils = goog.require('Blockly.utils.string'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['text'] = function(block) { diff --git a/generators/python/variables.js b/generators/python/variables.js index 107beda0d..7abce6b42 100644 --- a/generators/python/variables.js +++ b/generators/python/variables.js @@ -11,8 +11,8 @@ goog.module('Blockly.Python.variables'); -const Python = goog.require('Blockly.Python'); const {NameType} = goog.require('Blockly.Names'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); Python['variables_get'] = function(block) { diff --git a/generators/python/variables_dynamic.js b/generators/python/variables_dynamic.js index 738b383fe..b2632eece 100644 --- a/generators/python/variables_dynamic.js +++ b/generators/python/variables_dynamic.js @@ -11,7 +11,7 @@ goog.module('Blockly.Python.variablesDynamic'); -const Python = goog.require('Blockly.Python'); +const {pythonGenerator: Python} = goog.require('Blockly.Python'); /** @suppress {extraRequire} */ goog.require('Blockly.Python.variables'); diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index 3e709f940..1bbdb03fe 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -87,8 +87,14 @@ const NAMESPACE_PROPERTY = '__namespace__'; * will be written to. * - .entry: the source .js file which is the entrypoint for the * chunk. + * - .exports: an expression evaluating to the exports/Module object + * of module that is the chunk's entrypoint / top level module. * - .reexport: if running in a browser, save the chunk's exports - * object at this location in the global namespace. + * object (or a single export of it; see reexportOnly, below) at + * this location in the global namespace. + * - .reexportOnly: if reexporting and this property is set, + * save only the correspondingly-named export. Otherwise + * save the whole export object. * * The function getChunkOptions will, after running * closure-calculate-chunks, update each chunk to add the following @@ -104,37 +110,49 @@ const chunks = [ { name: 'blockly', entry: path.join(CORE_DIR, 'blockly.js'), + exports: 'module$exports$Blockly', reexport: 'Blockly', }, { name: 'blocks', entry: 'blocks/blocks.js', + exports: 'module$exports$Blockly$libraryBlocks', reexport: 'Blockly.libraryBlocks', }, { name: 'javascript', entry: 'generators/javascript/all.js', + exports: 'module$exports$Blockly$JavaScript', reexport: 'Blockly.JavaScript', + reexportOnly: 'javascriptGenerator', }, { name: 'python', entry: 'generators/python/all.js', + exports: 'module$exports$Blockly$Python', reexport: 'Blockly.Python', + reexportOnly: 'pythonGenerator', }, { name: 'php', entry: 'generators/php/all.js', + exports: 'module$exports$Blockly$PHP', reexport: 'Blockly.PHP', + reexportOnly: 'phpGenerator', }, { name: 'lua', entry: 'generators/lua/all.js', + exports: 'module$exports$Blockly$Lua', reexport: 'Blockly.Lua', + reexportOnly: 'luaGenerator', }, { name: 'dart', entry: 'generators/dart/all.js', + exports: 'module$exports$Blockly$Dart', reexport: 'Blockly.Dart', + reexportOnly: 'dartGenerator', } ]; @@ -311,7 +329,7 @@ function buildDeps(done) { execSync(`closure-make-deps ${testArgs} | grep 'tests/mocha' ` + `> '${TEST_DEPS_FILE}'`, {stdio: 'inherit'}); done(); -}; +} /** * This task regenrates msg/json/en.js and msg/json/qqq.js from @@ -341,7 +359,7 @@ this removal! `); done(); -}; +} /** * This task builds Blockly's lang files. @@ -367,7 +385,7 @@ function buildLangfiles(done) { execSync(createMessagesCmd, {stdio: 'inherit'}); done(); -}; +} /** * A helper method to return an closure compiler chunk wrapper that @@ -399,16 +417,20 @@ function chunkWrapper(chunk) { namespaceExpr = `${factoryArgs}.${NAMESPACE_PROPERTY}`; } - // Expression that evaluates the the value of the exports object for - // the specified chunk. For now we guess the name that is created - // by the module's goog.module.delcareLegacyNamespace call based on - // chunk.reexport. - const exportsExpression = `${NAMESPACE_VARIABLE}.${chunk.reexport}`; - // In near future we might try to guess the internally-generated - // name for the ES module's exports object. - // const exportsExpression = - // 'module$' + chunk.entry.replace(/\.m?js$/, '').replace(/\//g, '$'); - + // Code to assign the result of the factory function to the desired + // export location when running in a browser. When + // chunk.reexportOnly is set, this additionally does two other + // things: + // - It ensures that only the desired property of the exports object + // is assigned to the specified reexport location. + // - It ensures that the namesspace object is accessible via the + // selected sub-object, so that any dependent modules can obtain + // it. + const browserExportStatements = chunk.reexportOnly ? + `root.${chunk.reexport} = factoryExports.${chunk.reexportOnly};\n` + + ` root.${chunk.reexport}.${NAMESPACE_PROPERTY} = ` + + `factoryExports.${NAMESPACE_PROPERTY};` : + `root.${chunk.reexport} = factoryExports;`; // Note that when loading in a browser the base of the exported path // (e.g. Blockly.blocks.all - see issue #5932) might not exist @@ -425,16 +447,16 @@ function chunkWrapper(chunk) { module.exports = factory(${cjsDepsExpr}); } else { // Browser var factoryExports = factory(${browserDepsExpr}); - root.${chunk.reexport} = factoryExports; + ${browserExportStatements} } }(this, function(${factoryArgs}) { var ${NAMESPACE_VARIABLE}=${namespaceExpr}; %output% -${exportsExpression}.${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE}; -return ${exportsExpression}; +${chunk.exports}.${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE}; +return ${chunk.exports}; })); `; -}; +} /** * Get chunking options to pass to Closure Compiler by using @@ -566,7 +588,10 @@ function compile(options) { // declared by base_minimal.js, while if you compile against // base.js instead you will discover that it uses @deprecated // inherits, forwardDeclare etc. - hide_warnings_for: ['node_modules', 'build/src/closure/goog/goog.js'], + hide_warnings_for: [ + 'node_modules', + path.join(TSC_OUTPUT_DIR, 'closure', 'goog', 'goog.js'), + ], define: ['COMPILED=true'], }; if (argv.debug || argv.strict) { @@ -594,7 +619,13 @@ function buildCompiled() { // Closure Compiler options. const packageJson = getPackageJson(); // For version number. const options = { - define: 'Blockly.VERSION="' + packageJson.version + '"', + // The documentation for @define claims you can't use it on a + // non-global, but the closure compiler turns everything in to a + // global - you just have to know what the new name is! With + // declareLegacyNamespace this was very straightforward. Without + // it, we have to rely on implmentation details. See + // https://github.com/google/closure-compiler/issues/1601#issuecomment-483452226 + define: `${chunks[0].exports}.VERSION='${packageJson.version}'`, chunk: chunkOptions.chunk, chunk_wrapper: chunkOptions.chunk_wrapper, rename_prefix_namespace: NAMESPACE_VARIABLE, @@ -611,7 +642,7 @@ function buildCompiled() { .pipe( gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'})) .pipe(gulp.dest(BUILD_DIR)); -}; +} /** * This task builds Blockly core, blocks and generators together and uses @@ -671,7 +702,7 @@ function checkinBuilt() { `${BUILD_DIR}/*_compressed.js.map`, `${BUILD_DIR}/msg/js/*.js`, ], {base: BUILD_DIR}).pipe(gulp.dest('.')); -}; +} /** * This task cleans the build directory (by deleting it). @@ -694,7 +725,7 @@ function format() { ], {base: '.'}) .pipe(clangFormatter.format('file', clangFormat)) .pipe(gulp.dest('.')); -}; +} module.exports = { build: build, diff --git a/scripts/gulpfiles/chunks.json b/scripts/gulpfiles/chunks.json index d35ed7089..468afc789 100644 --- a/scripts/gulpfiles/chunks.json +++ b/scripts/gulpfiles/chunks.json @@ -287,8 +287,8 @@ "./generators/javascript/loops.js", "./generators/javascript/logic.js", "./generators/javascript/lists.js", - "./generators/javascript.js", "./generators/javascript/colour.js", + "./generators/javascript.js", "./generators/javascript/all.js", "./generators/python/variables_dynamic.js", "./generators/python/variables.js", @@ -298,8 +298,8 @@ "./generators/python/loops.js", "./generators/python/logic.js", "./generators/python/lists.js", - "./generators/python.js", "./generators/python/colour.js", + "./generators/python.js", "./generators/python/all.js", "./generators/php/variables_dynamic.js", "./generators/php/variables.js", @@ -309,8 +309,8 @@ "./generators/php/loops.js", "./generators/php/logic.js", "./generators/php/lists.js", - "./generators/php.js", "./generators/php/colour.js", + "./generators/php.js", "./generators/php/all.js", "./generators/lua/variables_dynamic.js", "./generators/lua/variables.js", @@ -320,8 +320,8 @@ "./generators/lua/loops.js", "./generators/lua/logic.js", "./generators/lua/lists.js", - "./generators/lua.js", "./generators/lua/colour.js", + "./generators/lua.js", "./generators/lua/all.js", "./generators/dart/variables_dynamic.js", "./generators/dart/variables.js", @@ -331,8 +331,8 @@ "./generators/dart/loops.js", "./generators/dart/logic.js", "./generators/dart/lists.js", - "./generators/dart.js", "./generators/dart/colour.js", + "./generators/dart.js", "./generators/dart/all.js" ] } diff --git a/scripts/migration/renamings.json5 b/scripts/migration/renamings.json5 index b1e9ef208..0b3ae71b1 100644 --- a/scripts/migration/renamings.json5 +++ b/scripts/migration/renamings.json5 @@ -1341,6 +1341,31 @@ { 'oldName': 'Blockly.utils.global', 'newPath': 'globalThis', - } + }, + { + oldName: 'Blockly.Dart', + newExport: 'dartGenerator', + newPath: 'Blockly.Dart', + }, + { + oldName: 'Blockly.JavaScript', + newExport: 'javascriptGenerator', + newPath: 'Blockly.JavaScript', + }, + { + oldName: 'Blockly.Lua', + newExport: 'luaGenerator', + newPath: 'Blockly.Lua', + }, + { + oldName: 'Blockly.PHP', + newExport: 'phpGenerator', + newPath: 'Blockly.php', + }, + { + oldName: 'Blockly.Python', + newExport: 'pythonGenerator', + newPath: 'Blockly.Python', + }, ], } diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json new file mode 100644 index 000000000..d60a0bd41 --- /dev/null +++ b/tests/.eslintrc.json @@ -0,0 +1,10 @@ +{ + "globals": { + "Blockly": true, + "dartGenerator": true, + "javascriptGenerator": true, + "luaGenerator": true, + "phpGenerator": true, + "pythonGenerator": true + } +} diff --git a/tests/bootstrap_helper.js b/tests/bootstrap_helper.js index ba61ff2ea..e9e7cd68a 100644 --- a/tests/bootstrap_helper.js +++ b/tests/bootstrap_helper.js @@ -17,4 +17,27 @@ /* eslint-disable-next-line no-undef */ for (const require of window.bootstrapInfo.requires) { goog.require(require); + + // If require is a top-level chunk, create a global variable for it. + // This replaces the goog.module.declareLegacyNamespace calls that + // previously existed in each chunk entrypoint. + const exportName = { + 'Blockly.Dart': 'dartGenerator', + 'Blockly.Dart.all': 'dartGenerator', + 'Blockly.JavaScript': 'javascriptGenerator', + 'Blockly.JavaScript.all': 'javascriptGenerator', + 'Blockly.Lua': 'luaGenerator', + 'Blockly.Lua.all': 'luaGenerator', + 'Blockly.PHP': 'phpGenerator', + 'Blockly.PHP.all': 'phpGenerator', + 'Blockly.Python': 'pythonGenerator', + 'Blockly.Python.all': 'pythonGenerator', + }[require]; + if (exportName) { + window[exportName] = goog.module.get(require)[exportName]; + } else if (require === 'Blockly') { + window.Blockly = goog.module.get(require); + } else if (require === 'Blockly.libraryBlocks') { + window.libraryBlocks = goog.module.get(require); + } } diff --git a/tests/compile/main.js b/tests/compile/main.js index b5d20a770..644befef3 100644 --- a/tests/compile/main.js +++ b/tests/compile/main.js @@ -25,7 +25,7 @@ goog.require('Blockly.libraryBlocks.math'); /** @suppress {extraRequire} */ goog.require('Blockly.libraryBlocks.texts'); /** @suppress {extraRequire} */ -goog.require('Blockly.libraryBlocks.testBlocks'); +goog.require('testBlocks'); function init() { diff --git a/tests/compile/test_blocks.js b/tests/compile/test_blocks.js index 2b8cc6621..8dbbe1c06 100644 --- a/tests/compile/test_blocks.js +++ b/tests/compile/test_blocks.js @@ -9,9 +9,9 @@ */ 'use strict'; -goog.provide('Blockly.libraryBlocks.testBlocks'); +goog.module('testBlocks'); -goog.require('Blockly'); +const Blockly = goog.require('Blockly'); Blockly.defineBlocksWithJsonArray([ { diff --git a/tests/generators/index.html b/tests/generators/index.html index 69badeed1..18455ca70 100644 --- a/tests/generators/index.html +++ b/tests/generators/index.html @@ -170,31 +170,31 @@ function toXml() { function toJavaScript() { var code = '\'use strict\';\n\n' - code += Blockly.JavaScript.workspaceToCode(demoWorkspace); + code += javascriptGenerator.workspaceToCode(demoWorkspace); setOutput(code); outputCode = code; } function toPython() { - var code = Blockly.Python.workspaceToCode(demoWorkspace); + var code = pythonGenerator.workspaceToCode(demoWorkspace); setOutput(code); outputCode = code; } function toPhp() { - var code = Blockly.PHP.workspaceToCode(demoWorkspace); + var code = phpGenerator.workspaceToCode(demoWorkspace); setOutput(code); outputCode = code; } function toLua() { - var code = Blockly.Lua.workspaceToCode(demoWorkspace); + var code = luaGenerator.workspaceToCode(demoWorkspace); setOutput(code); outputCode = code; } function toDart() { - var code = Blockly.Dart.workspaceToCode(demoWorkspace); + var code = dartGenerator.workspaceToCode(demoWorkspace); setOutput(code); outputCode = code; } diff --git a/tests/generators/unittest_dart.js b/tests/generators/unittest_dart.js index 65a348aba..61f6caaa1 100644 --- a/tests/generators/unittest_dart.js +++ b/tests/generators/unittest_dart.js @@ -9,13 +9,13 @@ */ 'use strict'; -Blockly.Dart['unittest_main'] = function(block) { +dartGenerator['unittest_main'] = function(block) { // Container for unit tests. - var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults', + var resultsVar = dartGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Dart.provideFunction_( + var functionName = dartGenerator.provideFunction_( 'unittest_report', - [ 'String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {', + [ 'String ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {', ' // Create test report.', ' List report = [];', ' StringBuffer summary = new StringBuffer();', @@ -50,7 +50,7 @@ Blockly.Dart['unittest_main'] = function(block) { block.getFieldValue('SUITE_NAME') + '\');\n'; // Run tests (unindented). - code += Blockly.Dart.statementToCode(block, 'DO') + code += dartGenerator.statementToCode(block, 'DO') .replace(/^ /, '').replace(/\n /g, '\n'); // Print the report to the console (that's where errors will go anyway). code += 'print(' + functionName + '());\n'; @@ -59,12 +59,12 @@ Blockly.Dart['unittest_main'] = function(block) { return code; }; -Blockly.Dart['unittest_main'].defineAssert_ = function() { - var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults', +dartGenerator['unittest_main'].defineAssert_ = function() { + var resultsVar = dartGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Dart.provideFunction_( + var functionName = dartGenerator.provideFunction_( 'unittest_assertequals', - [ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + + [ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(dynamic actual, dynamic expected, String message) {', ' // Asserts that a value equals another value.', ' if (' + resultsVar + ' == null) {', @@ -96,24 +96,24 @@ Blockly.Dart['unittest_main'].defineAssert_ = function() { return functionName; }; -Blockly.Dart['unittest_assertequals'] = function(block) { +dartGenerator['unittest_assertequals'] = function(block) { // Asserts that a value equals another value. - var message = Blockly.Dart.valueToCode(block, 'MESSAGE', - Blockly.Dart.ORDER_NONE) || ''; - var actual = Blockly.Dart.valueToCode(block, 'ACTUAL', - Blockly.Dart.ORDER_NONE) || 'null'; - var expected = Blockly.Dart.valueToCode(block, 'EXPECTED', - Blockly.Dart.ORDER_NONE) || 'null'; - return Blockly.Dart['unittest_main'].defineAssert_() + + var message = dartGenerator.valueToCode(block, 'MESSAGE', + dartGenerator.ORDER_NONE) || ''; + var actual = dartGenerator.valueToCode(block, 'ACTUAL', + dartGenerator.ORDER_NONE) || 'null'; + var expected = dartGenerator.valueToCode(block, 'EXPECTED', + dartGenerator.ORDER_NONE) || 'null'; + return dartGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.Dart['unittest_assertvalue'] = function(block) { +dartGenerator['unittest_assertvalue'] = function(block) { // Asserts that a value is true, false, or null. - var message = Blockly.Dart.valueToCode(block, 'MESSAGE', - Blockly.Dart.ORDER_NONE) || ''; - var actual = Blockly.Dart.valueToCode(block, 'ACTUAL', - Blockly.Dart.ORDER_NONE) || 'null'; + var message = dartGenerator.valueToCode(block, 'MESSAGE', + dartGenerator.ORDER_NONE) || ''; + var actual = dartGenerator.valueToCode(block, 'ACTUAL', + dartGenerator.ORDER_NONE) || 'null'; var expected = block.getFieldValue('EXPECTED'); if (expected === 'TRUE') { expected = 'true'; @@ -122,18 +122,18 @@ Blockly.Dart['unittest_assertvalue'] = function(block) { } else if (expected === 'NULL') { expected = 'null'; } - return Blockly.Dart['unittest_main'].defineAssert_() + + return dartGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.Dart['unittest_fail'] = function(block) { +dartGenerator['unittest_fail'] = function(block) { // Always assert an error. - var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults', + var resultsVar = dartGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var message = Blockly.Dart.quote_(block.getFieldValue('MESSAGE')); - var functionName = Blockly.Dart.provideFunction_( + var message = dartGenerator.quote_(block.getFieldValue('MESSAGE')); + var functionName = dartGenerator.provideFunction_( 'unittest_fail', - [ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + + [ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(String message) {', ' // Always assert an error.', ' if (' + resultsVar + ' == null) {', @@ -144,20 +144,20 @@ Blockly.Dart['unittest_fail'] = function(block) { return functionName + '(' + message + ');\n'; }; -Blockly.Dart['unittest_adjustindex'] = function(block) { - var index = Blockly.Dart.valueToCode(block, 'INDEX', - Blockly.Dart.ORDER_ADDITIVE) || '0'; +dartGenerator['unittest_adjustindex'] = function(block) { + var index = dartGenerator.valueToCode(block, 'INDEX', + dartGenerator.ORDER_ADDITIVE) || '0'; // Adjust index if using one-based indexing. if (block.workspace.options.oneBasedIndex) { if (Blockly.isNumber(index)) { // If the index is a naked number, adjust it right now. - return [Number(index) + 1, Blockly.Dart.ORDER_ATOMIC]; + return [Number(index) + 1, dartGenerator.ORDER_ATOMIC]; } else { // If the index is dynamic, adjust it in code. index = index + ' + 1'; } } else if (Blockly.isNumber(index)) { - return [index, Blockly.Dart.ORDER_ATOMIC]; + return [index, dartGenerator.ORDER_ATOMIC]; } - return [index, Blockly.Dart.ORDER_ADDITIVE]; + return [index, dartGenerator.ORDER_ADDITIVE]; }; diff --git a/tests/generators/unittest_javascript.js b/tests/generators/unittest_javascript.js index df48642df..6e083f7a5 100644 --- a/tests/generators/unittest_javascript.js +++ b/tests/generators/unittest_javascript.js @@ -9,13 +9,13 @@ */ 'use strict'; -Blockly.JavaScript['unittest_main'] = function(block) { +javascriptGenerator['unittest_main'] = function(block) { // Container for unit tests. - var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults', + var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.JavaScript.provideFunction_( + var functionName = javascriptGenerator.provideFunction_( 'unittest_report', - [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {', + [ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {', ' // Create test report.', ' var report = [];', ' var summary = [];', @@ -51,7 +51,7 @@ Blockly.JavaScript['unittest_main'] = function(block) { block.getFieldValue('SUITE_NAME') + '\')\n'; // Run tests (unindented). - code += Blockly.JavaScript.statementToCode(block, 'DO') + code += javascriptGenerator.statementToCode(block, 'DO') .replace(/^ /, '').replace(/\n /g, '\n'); // Send the report to the console (that's where errors will go anyway). code += 'console.log(' + functionName + '());\n'; @@ -60,12 +60,12 @@ Blockly.JavaScript['unittest_main'] = function(block) { return code; }; -Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) { - var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults', +javascriptGenerator['unittest_main'].defineAssert_ = function(block) { + var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.JavaScript.provideFunction_( + var functionName = javascriptGenerator.provideFunction_( 'assertEquals', - [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + + [ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(actual, expected, message) {', ' // Asserts that a value equals another value.', ' if (!' + resultsVar + ') {', @@ -100,24 +100,24 @@ Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) { return functionName; }; -Blockly.JavaScript['unittest_assertequals'] = function(block) { +javascriptGenerator['unittest_assertequals'] = function(block) { // Asserts that a value equals another value. - var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', - Blockly.JavaScript.ORDER_NONE) || ''; - var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL', - Blockly.JavaScript.ORDER_NONE) || 'null'; - var expected = Blockly.JavaScript.valueToCode(block, 'EXPECTED', - Blockly.JavaScript.ORDER_NONE) || 'null'; - return Blockly.JavaScript['unittest_main'].defineAssert_() + + var message = javascriptGenerator.valueToCode(block, 'MESSAGE', + javascriptGenerator.ORDER_NONE) || ''; + var actual = javascriptGenerator.valueToCode(block, 'ACTUAL', + javascriptGenerator.ORDER_NONE) || 'null'; + var expected = javascriptGenerator.valueToCode(block, 'EXPECTED', + javascriptGenerator.ORDER_NONE) || 'null'; + return javascriptGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.JavaScript['unittest_assertvalue'] = function(block) { +javascriptGenerator['unittest_assertvalue'] = function(block) { // Asserts that a value is true, false, or null. - var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', - Blockly.JavaScript.ORDER_NONE) || ''; - var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL', - Blockly.JavaScript.ORDER_NONE) || 'null'; + var message = javascriptGenerator.valueToCode(block, 'MESSAGE', + javascriptGenerator.ORDER_NONE) || ''; + var actual = javascriptGenerator.valueToCode(block, 'ACTUAL', + javascriptGenerator.ORDER_NONE) || 'null'; var expected = block.getFieldValue('EXPECTED'); if (expected === 'TRUE') { expected = 'true'; @@ -126,18 +126,18 @@ Blockly.JavaScript['unittest_assertvalue'] = function(block) { } else if (expected === 'NULL') { expected = 'null'; } - return Blockly.JavaScript['unittest_main'].defineAssert_() + + return javascriptGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.JavaScript['unittest_fail'] = function(block) { +javascriptGenerator['unittest_fail'] = function(block) { // Always assert an error. - var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults', + var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var message = Blockly.JavaScript.quote_(block.getFieldValue('MESSAGE')); - var functionName = Blockly.JavaScript.provideFunction_( + var message = javascriptGenerator.quote_(block.getFieldValue('MESSAGE')); + var functionName = javascriptGenerator.provideFunction_( 'unittest_fail', - [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + + [ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message) {', ' // Always assert an error.', ' if (!' + resultsVar + ') {', @@ -148,20 +148,20 @@ Blockly.JavaScript['unittest_fail'] = function(block) { return functionName + '(' + message + ');\n'; }; -Blockly.JavaScript['unittest_adjustindex'] = function(block) { - var index = Blockly.JavaScript.valueToCode(block, 'INDEX', - Blockly.JavaScript.ORDER_ADDITION) || '0'; +javascriptGenerator['unittest_adjustindex'] = function(block) { + var index = javascriptGenerator.valueToCode(block, 'INDEX', + javascriptGenerator.ORDER_ADDITION) || '0'; // Adjust index if using one-based indexing. if (block.workspace.options.oneBasedIndex) { if (Blockly.isNumber(index)) { // If the index is a naked number, adjust it right now. - return [Number(index) + 1, Blockly.JavaScript.ORDER_ATOMIC]; + return [Number(index) + 1, javascriptGenerator.ORDER_ATOMIC]; } else { // If the index is dynamic, adjust it in code. index = index + ' + 1'; } } else if (Blockly.isNumber(index)) { - return [index, Blockly.JavaScript.ORDER_ATOMIC]; + return [index, javascriptGenerator.ORDER_ATOMIC]; } - return [index, Blockly.JavaScript.ORDER_ADDITION]; + return [index, javascriptGenerator.ORDER_ADDITION]; }; diff --git a/tests/generators/unittest_lua.js b/tests/generators/unittest_lua.js index 06b21744d..40447616a 100644 --- a/tests/generators/unittest_lua.js +++ b/tests/generators/unittest_lua.js @@ -9,13 +9,13 @@ */ 'use strict'; -Blockly.Lua['unittest_main'] = function(block) { +luaGenerator['unittest_main'] = function(block) { // Container for unit tests. - var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults', + var resultsVar = luaGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Lua.provideFunction_( + var functionName = luaGenerator.provideFunction_( 'unittest_report', - ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '()', + ['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '()', ' -- Create test report.', ' local report = {}', ' local summary = {}', @@ -49,7 +49,7 @@ Blockly.Lua['unittest_main'] = function(block) { block.getFieldValue('SUITE_NAME') + '\')\n'; // Run tests (unindented). - code += Blockly.Lua.statementToCode(block, 'DO') + code += luaGenerator.statementToCode(block, 'DO') .replace(/^ /, '').replace(/\n /g, '\n'); // Print the report. code += 'print(' + functionName + '())\n'; @@ -58,12 +58,12 @@ Blockly.Lua['unittest_main'] = function(block) { return code; }; -Blockly.Lua['unittest_main'].defineAssert_ = function(block) { - var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults', +luaGenerator['unittest_main'].defineAssert_ = function(block) { + var resultsVar = luaGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Lua.provideFunction_( + var functionName = luaGenerator.provideFunction_( 'assertEquals', - ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + + ['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(actual, expected, message)', ' -- Asserts that a value equals another value.', ' assert(' + resultsVar + ' ~= nil, ' + @@ -106,24 +106,24 @@ Blockly.Lua['unittest_main'].defineAssert_ = function(block) { return functionName; }; -Blockly.Lua['unittest_assertequals'] = function(block) { +luaGenerator['unittest_assertequals'] = function(block) { // Asserts that a value equals another value. - var message = Blockly.Lua.valueToCode(block, 'MESSAGE', - Blockly.Lua.ORDER_NONE) || ''; - var actual = Blockly.Lua.valueToCode(block, 'ACTUAL', - Blockly.Lua.ORDER_NONE) || 'nil'; - var expected = Blockly.Lua.valueToCode(block, 'EXPECTED', - Blockly.Lua.ORDER_NONE) || 'nil'; - return Blockly.Lua['unittest_main'].defineAssert_() + + var message = luaGenerator.valueToCode(block, 'MESSAGE', + luaGenerator.ORDER_NONE) || ''; + var actual = luaGenerator.valueToCode(block, 'ACTUAL', + luaGenerator.ORDER_NONE) || 'nil'; + var expected = luaGenerator.valueToCode(block, 'EXPECTED', + luaGenerator.ORDER_NONE) || 'nil'; + return luaGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ')\n'; }; -Blockly.Lua['unittest_assertvalue'] = function(block) { +luaGenerator['unittest_assertvalue'] = function(block) { // Asserts that a value is true, false, or null. - var message = Blockly.Lua.valueToCode(block, 'MESSAGE', - Blockly.Lua.ORDER_NONE) || ''; - var actual = Blockly.Lua.valueToCode(block, 'ACTUAL', - Blockly.Lua.ORDER_NONE) || 'nil'; + var message = luaGenerator.valueToCode(block, 'MESSAGE', + luaGenerator.ORDER_NONE) || ''; + var actual = luaGenerator.valueToCode(block, 'ACTUAL', + luaGenerator.ORDER_NONE) || 'nil'; var expected = block.getFieldValue('EXPECTED'); if (expected == 'TRUE') { expected = 'true'; @@ -132,18 +132,18 @@ Blockly.Lua['unittest_assertvalue'] = function(block) { } else if (expected == 'NULL') { expected = 'nil'; } - return Blockly.Lua.unittest_main.defineAssert_() + + return luaGenerator.unittest_main.defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ')\n'; }; -Blockly.Lua['unittest_fail'] = function(block) { +luaGenerator['unittest_fail'] = function(block) { // Always assert an error. - var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults', + var resultsVar = luaGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var message = Blockly.Lua.quote_(block.getFieldValue('MESSAGE')); - var functionName = Blockly.Lua.provideFunction_( + var message = luaGenerator.quote_(block.getFieldValue('MESSAGE')); + var functionName = luaGenerator.provideFunction_( 'unittest_fail', - ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(message)', + ['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message)', ' -- Always assert an error.', ' assert(' + resultsVar + ' ~= nil, "Orphaned assert fail: " .. message)', @@ -153,13 +153,13 @@ Blockly.Lua['unittest_fail'] = function(block) { return functionName + '(' + message + ')\n'; }; -Blockly.Lua['unittest_adjustindex'] = function(block) { - var index = Blockly.Lua.valueToCode(block, 'INDEX', - Blockly.Lua.ORDER_ADDITIVE) || '0'; +luaGenerator['unittest_adjustindex'] = function(block) { + var index = luaGenerator.valueToCode(block, 'INDEX', + luaGenerator.ORDER_ADDITIVE) || '0'; if (Blockly.isNumber(index)) { // If the index is a naked number, adjust it right now. - return [Number(index) + 1, Blockly.Lua.ORDER_ATOMIC]; + return [Number(index) + 1, luaGenerator.ORDER_ATOMIC]; } // If the index is dynamic, adjust it in code. - return [index + ' + 1', Blockly.Lua.ORDER_ADDITIVE]; + return [index + ' + 1', luaGenerator.ORDER_ADDITIVE]; }; diff --git a/tests/generators/unittest_php.js b/tests/generators/unittest_php.js index eba709ce0..f8ffa6993 100644 --- a/tests/generators/unittest_php.js +++ b/tests/generators/unittest_php.js @@ -9,13 +9,13 @@ */ 'use strict'; -Blockly.PHP['unittest_main'] = function(block) { +phpGenerator['unittest_main'] = function(block) { // Container for unit tests. - var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults', + var resultsVar = phpGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.PHP.provideFunction_( + var functionName = phpGenerator.provideFunction_( 'unittest_report', - [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {', + [ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {', ' global ' + resultsVar + ';', ' // Create test report.', ' $report = array();', @@ -51,7 +51,7 @@ Blockly.PHP['unittest_main'] = function(block) { block.getFieldValue('SUITE_NAME') + '\\n");\n'; // Run tests (unindented). - code += Blockly.PHP.statementToCode(block, 'DO') + code += phpGenerator.statementToCode(block, 'DO') .replace(/^ /, '').replace(/\n /g, '\n'); // Send the report to the console (that's where errors will go anyway). code += 'print(' + functionName + '());\n'; @@ -60,12 +60,12 @@ Blockly.PHP['unittest_main'] = function(block) { return code; }; -Blockly.PHP['unittest_main'].defineAssert_ = function(block) { - var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults', +phpGenerator['unittest_main'].defineAssert_ = function(block) { + var resultsVar = phpGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.PHP.provideFunction_( + var functionName = phpGenerator.provideFunction_( 'assertEquals', - ['function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + + ['function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ + '($actual, $expected, $message) {', ' global ' + resultsVar + ';', ' // Asserts that a value equals another value.', @@ -86,24 +86,24 @@ Blockly.PHP['unittest_main'].defineAssert_ = function(block) { return functionName; }; -Blockly.PHP['unittest_assertequals'] = function(block) { +phpGenerator['unittest_assertequals'] = function(block) { // Asserts that a value equals another value. - var message = Blockly.PHP.valueToCode(block, 'MESSAGE', - Blockly.PHP.ORDER_NONE) || ''; - var actual = Blockly.PHP.valueToCode(block, 'ACTUAL', - Blockly.PHP.ORDER_NONE) || 'null'; - var expected = Blockly.PHP.valueToCode(block, 'EXPECTED', - Blockly.PHP.ORDER_NONE) || 'null'; - return Blockly.PHP['unittest_main'].defineAssert_() + + var message = phpGenerator.valueToCode(block, 'MESSAGE', + phpGenerator.ORDER_NONE) || ''; + var actual = phpGenerator.valueToCode(block, 'ACTUAL', + phpGenerator.ORDER_NONE) || 'null'; + var expected = phpGenerator.valueToCode(block, 'EXPECTED', + phpGenerator.ORDER_NONE) || 'null'; + return phpGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.PHP['unittest_assertvalue'] = function(block) { +phpGenerator['unittest_assertvalue'] = function(block) { // Asserts that a value is true, false, or null. - var message = Blockly.PHP.valueToCode(block, 'MESSAGE', - Blockly.PHP.ORDER_NONE) || ''; - var actual = Blockly.PHP.valueToCode(block, 'ACTUAL', - Blockly.PHP.ORDER_NONE) || 'null'; + var message = phpGenerator.valueToCode(block, 'MESSAGE', + phpGenerator.ORDER_NONE) || ''; + var actual = phpGenerator.valueToCode(block, 'ACTUAL', + phpGenerator.ORDER_NONE) || 'null'; var expected = block.getFieldValue('EXPECTED'); if (expected == 'TRUE') { expected = 'true'; @@ -112,18 +112,18 @@ Blockly.PHP['unittest_assertvalue'] = function(block) { } else if (expected == 'NULL') { expected = 'null'; } - return Blockly.PHP['unittest_main'].defineAssert_() + + return phpGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ');\n'; }; -Blockly.PHP['unittest_fail'] = function(block) { +phpGenerator['unittest_fail'] = function(block) { // Always assert an error. - var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults', + var resultsVar = phpGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE')); - var functionName = Blockly.PHP.provideFunction_( + var message = phpGenerator.quote_(block.getFieldValue('MESSAGE')); + var functionName = phpGenerator.provideFunction_( 'unittest_fail', - [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + + [ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ + '($message) {', ' global ' + resultsVar + ';', ' // Always assert an error.', @@ -135,20 +135,20 @@ Blockly.PHP['unittest_fail'] = function(block) { return functionName + '(' + message + ');\n'; }; -Blockly.PHP['unittest_adjustindex'] = function(block) { - var index = Blockly.PHP.valueToCode(block, 'INDEX', - Blockly.PHP.ORDER_ADDITION) || '0'; +phpGenerator['unittest_adjustindex'] = function(block) { + var index = phpGenerator.valueToCode(block, 'INDEX', + phpGenerator.ORDER_ADDITION) || '0'; // Adjust index if using one-based indexing. if (block.workspace.options.oneBasedIndex) { if (Blockly.isNumber(index)) { // If the index is a naked number, adjust it right now. - return [Number(index) + 1, Blockly.PHP.ORDER_ATOMIC]; + return [Number(index) + 1, phpGenerator.ORDER_ATOMIC]; } else { // If the index is dynamic, adjust it in code. index = index + ' + 1'; } } else if (Blockly.isNumber(index)) { - return [index, Blockly.PHP.ORDER_ATOMIC]; + return [index, phpGenerator.ORDER_ATOMIC]; } - return [index, Blockly.PHP.ORDER_ADDITION]; + return [index, phpGenerator.ORDER_ADDITION]; }; diff --git a/tests/generators/unittest_python.js b/tests/generators/unittest_python.js index 073211d62..63d787c88 100644 --- a/tests/generators/unittest_python.js +++ b/tests/generators/unittest_python.js @@ -9,13 +9,13 @@ */ 'use strict'; -Blockly.Python['unittest_main'] = function(block) { +pythonGenerator['unittest_main'] = function(block) { // Container for unit tests. - var resultsVar = Blockly.Python.nameDB_.getName('unittestResults', + var resultsVar = pythonGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Python.provideFunction_( + var functionName = pythonGenerator.provideFunction_( 'unittest_report', - ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():', + ['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '():', ' # Create test report.', ' report = []', ' summary = []', @@ -47,7 +47,7 @@ Blockly.Python['unittest_main'] = function(block) { block.getFieldValue('SUITE_NAME') + '\')\n'; // Run tests (unindented). - code += Blockly.Python.statementToCode(block, 'DO') + code += pythonGenerator.statementToCode(block, 'DO') .replace(/^ /, '').replace(/\n /g, '\n'); // Print the report. code += 'print(' + functionName + '())\n'; @@ -56,12 +56,12 @@ Blockly.Python['unittest_main'] = function(block) { return code; }; -Blockly.Python['unittest_main'].defineAssert_ = function() { - var resultsVar = Blockly.Python.nameDB_.getName('unittestResults', +pythonGenerator['unittest_main'].defineAssert_ = function() { + var resultsVar = pythonGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var functionName = Blockly.Python.provideFunction_( + var functionName = pythonGenerator.provideFunction_( 'assertEquals', - ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + + ['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(actual, expected, message):', ' # Asserts that a value equals another value.', ' if ' + resultsVar + ' == None:', @@ -74,24 +74,24 @@ Blockly.Python['unittest_main'].defineAssert_ = function() { return functionName; }; -Blockly.Python['unittest_assertequals'] = function(block) { +pythonGenerator['unittest_assertequals'] = function(block) { // Asserts that a value equals another value. - var message = Blockly.Python.valueToCode(block, 'MESSAGE', - Blockly.Python.ORDER_NONE) || ''; - var actual = Blockly.Python.valueToCode(block, 'ACTUAL', - Blockly.Python.ORDER_NONE) || 'None'; - var expected = Blockly.Python.valueToCode(block, 'EXPECTED', - Blockly.Python.ORDER_NONE) || 'None'; - return Blockly.Python['unittest_main'].defineAssert_() + + var message = pythonGenerator.valueToCode(block, 'MESSAGE', + pythonGenerator.ORDER_NONE) || ''; + var actual = pythonGenerator.valueToCode(block, 'ACTUAL', + pythonGenerator.ORDER_NONE) || 'None'; + var expected = pythonGenerator.valueToCode(block, 'EXPECTED', + pythonGenerator.ORDER_NONE) || 'None'; + return pythonGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ')\n'; }; -Blockly.Python['unittest_assertvalue'] = function(block) { +pythonGenerator['unittest_assertvalue'] = function(block) { // Asserts that a value is true, false, or null. - var message = Blockly.Python.valueToCode(block, 'MESSAGE', - Blockly.Python.ORDER_NONE) || ''; - var actual = Blockly.Python.valueToCode(block, 'ACTUAL', - Blockly.Python.ORDER_NONE) || 'None'; + var message = pythonGenerator.valueToCode(block, 'MESSAGE', + pythonGenerator.ORDER_NONE) || ''; + var actual = pythonGenerator.valueToCode(block, 'ACTUAL', + pythonGenerator.ORDER_NONE) || 'None'; var expected = block.getFieldValue('EXPECTED'); if (expected == 'TRUE') { expected = 'True'; @@ -100,18 +100,18 @@ Blockly.Python['unittest_assertvalue'] = function(block) { } else if (expected == 'NULL') { expected = 'None'; } - return Blockly.Python['unittest_main'].defineAssert_() + + return pythonGenerator['unittest_main'].defineAssert_() + '(' + actual + ', ' + expected + ', ' + message + ')\n'; }; -Blockly.Python['unittest_fail'] = function(block) { +pythonGenerator['unittest_fail'] = function(block) { // Always assert an error. - var resultsVar = Blockly.Python.nameDB_.getName('unittestResults', + var resultsVar = pythonGenerator.nameDB_.getName('unittestResults', Blockly.Names.DEVELOPER_VARIABLE_TYPE); - var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE')); - var functionName = Blockly.Python.provideFunction_( + var message = pythonGenerator.quote_(block.getFieldValue('MESSAGE')); + var functionName = pythonGenerator.provideFunction_( 'fail', - ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(message):', + ['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message):', ' # Always assert an error.', ' if ' + resultsVar + ' == None:', ' raise Exception("Orphaned assert equals: " + message)', @@ -119,20 +119,20 @@ Blockly.Python['unittest_fail'] = function(block) { return functionName + '(' + message + ')\n'; }; -Blockly.Python['unittest_adjustindex'] = function(block) { - var index = Blockly.Python.valueToCode(block, 'INDEX', - Blockly.Python.ORDER_ADDITIVE) || '0'; +pythonGenerator['unittest_adjustindex'] = function(block) { + var index = pythonGenerator.valueToCode(block, 'INDEX', + pythonGenerator.ORDER_ADDITIVE) || '0'; // Adjust index if using one-based indexing. if (block.workspace.options.oneBasedIndex) { if (Blockly.isNumber(index)) { // If the index is a naked number, adjust it right now. - return [Number(index) + 1, Blockly.Python.ORDER_ATOMIC]; + return [Number(index) + 1, pythonGenerator.ORDER_ATOMIC]; } else { // If the index is dynamic, adjust it in code. index = index + ' + 1'; } } else if (Blockly.isNumber(index)) { - return [index, Blockly.Python.ORDER_ATOMIC]; + return [index, pythonGenerator.ORDER_ATOMIC]; } - return [index, Blockly.Python.ORDER_ADDITIVE]; + return [index, pythonGenerator.ORDER_ADDITIVE]; }; diff --git a/tests/mocha/field_multilineinput_test.js b/tests/mocha/field_multilineinput_test.js index 6096384fe..a94a1b945 100644 --- a/tests/mocha/field_multilineinput_test.js +++ b/tests/mocha/field_multilineinput_test.js @@ -123,35 +123,35 @@ suite('Multiline Input Fields', function() { * @type {Array} */ const testSuites = [ - {title: 'Dart', generator: Blockly.Dart, + {title: 'Dart', generator: dartGenerator, testCases: [ {title: 'Empty string', expectedCode: '\'\'', createBlock: createBlockFn('')}, {title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' + \n\' bark bark bark\' + \'\\n\' + \n\' bark bar bark bark\' + \'\\n\' + \n\'\'', createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')}, ]}, - {title: 'JavaScript', generator: Blockly.JavaScript, + {title: 'JavaScript', generator: javascriptGenerator, testCases: [ {title: 'Empty string', expectedCode: '\'\'', createBlock: createBlockFn('')}, {title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' +\n\' bark bark bark\' + \'\\n\' +\n\' bark bar bark bark\' + \'\\n\' +\n\'\'', createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')}, ]}, - {title: 'Lua', generator: Blockly.Lua, + {title: 'Lua', generator: luaGenerator, testCases: [ {title: 'Empty string', expectedCode: '\'\'', createBlock: createBlockFn('')}, {title: 'String with newline', expectedCode: '\'bark bark\' .. \'\\n\' ..\n\' bark bark bark\' .. \'\\n\' ..\n\' bark bar bark bark\' .. \'\\n\' ..\n\'\'', createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')}, ]}, - {title: 'PHP', generator: Blockly.PHP, + {title: 'PHP', generator: phpGenerator, testCases: [ {title: 'Empty string', expectedCode: '\'\'', createBlock: createBlockFn('')}, {title: 'String with newline', expectedCode: '\'bark bark\' . "\\n" .\n\' bark bark bark\' . "\\n" .\n\' bark bar bark bark\' . "\\n" .\n\'\'', createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')}, ]}, - {title: 'Python', generator: Blockly.Python, + {title: 'Python', generator: pythonGenerator, testCases: [ {title: 'Empty string', expectedCode: '\'\'', createBlock: createBlockFn('')}, diff --git a/tests/mocha/generator_test.js b/tests/mocha/generator_test.js index 4167d44f6..3fd2fa24b 100644 --- a/tests/mocha/generator_test.js +++ b/tests/mocha/generator_test.js @@ -6,11 +6,11 @@ goog.module('Blockly.test.generator'); -goog.require('Blockly.Dart'); -goog.require('Blockly.JavaScript'); -goog.require('Blockly.Lua'); -goog.require('Blockly.PHP'); -goog.require('Blockly.Python'); +const {dartGenerator} = goog.require('Blockly.Dart'); +const {javaScriptGenerator} = goog.require('Blockly.JavaScript'); +const {luaGenerator} = goog.require('Blockly.Lua'); +const {phpGenerator} = goog.require('Blockly.PHP'); +const {pythonGenerator} = goog.require('Blockly.Python'); const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown'); @@ -83,11 +83,11 @@ suite('Generator', function() { }); const testCase = [ - [Blockly.Dart, 'Dart'], - [Blockly.JavaScript, 'JavaScript'], - [Blockly.Lua, 'Lua'], - [Blockly.PHP, 'PHP'], - [Blockly.Python, 'Python']]; + [dartGenerator, 'Dart'], + [javascriptGenerator, 'JavaScript'], + [luaGenerator, 'Lua'], + [phpGenerator, 'PHP'], + [pythonGenerator, 'Python']]; suite('Trivial', function() { testCase.forEach(function(testCase) { diff --git a/tests/mocha/insertion_marker_test.js b/tests/mocha/insertion_marker_test.js index 53958b55b..909212f9e 100644 --- a/tests/mocha/insertion_marker_test.js +++ b/tests/mocha/insertion_marker_test.js @@ -49,17 +49,17 @@ suite('InsertionMarkers', function() { }); suite('Code Generation', function() { setup(function() { - Blockly.JavaScript['stack_block'] = function(block) { + javascriptGenerator['stack_block'] = function(block) { return 'stack[' + block.id + '];\n'; }; - Blockly.JavaScript['row_block'] = function(block) { - const value = Blockly.JavaScript - .valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE); + javascriptGenerator['row_block'] = function(block) { + const value = javascriptGenerator + .valueToCode(block, 'INPUT', javascriptGenerator.ORDER_NONE); const code = 'row[' + block.id + '](' + value + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; + return [code, javascriptGenerator.ORDER_NONE]; }; - Blockly.JavaScript['statement_block'] = function(block) { - return 'statement[' + block.id + ']{\n' + Blockly.JavaScript + javascriptGenerator['statement_block'] = function(block) { + return 'statement[' + block.id + ']{\n' + javascriptGenerator .statementToCode(block, 'STATEMENT') + '};\n'; }; @@ -67,14 +67,14 @@ suite('InsertionMarkers', function() { Blockly.Xml.domToWorkspace(xml, this.workspace); const block = this.workspace.getBlockById('insertion'); block.isInsertionMarker_ = true; - const code = Blockly.JavaScript.workspaceToCode(this.workspace); + const code = javascriptGenerator.workspaceToCode(this.workspace); chai.assert.equal(code, expectedCode); }; }); teardown(function() { - delete Blockly.JavaScript['stack_block']; - delete Blockly.JavaScript['row_block']; - delete Blockly.JavaScript['statement_block']; + delete javascriptGenerator['stack_block']; + delete javascriptGenerator['row_block']; + delete javascriptGenerator['statement_block']; }); test('Marker Surrounds', function() { const xml = Blockly.Xml.textToDom( diff --git a/tests/node/run_node_test.js b/tests/node/run_node_test.js index 69d095d51..bea22c32b 100644 --- a/tests/node/run_node_test.js +++ b/tests/node/run_node_test.js @@ -10,6 +10,7 @@ const assert = require('chai').assert; const Blockly = require('../../dist/'); +const {javascriptGenerator} = require('../../dist/javascript'); const xmlText = '\n' + ' \n' + @@ -48,7 +49,7 @@ suite('Test Node.js', function() { Blockly.Xml.domToWorkspace(xml, workspace); // Convert code - const code = Blockly.JavaScript.workspaceToCode(workspace); + const code = javascriptGenerator.workspaceToCode(workspace); // Check output assert.equal('window.alert(\'Hello from Blockly!\');', code.trim(), 'equal'); diff --git a/tests/playground.html b/tests/playground.html index 142eef3fb..89f836055 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -184,8 +184,15 @@ function load() { } function toCode(lang) { + var generator = ({ + 'JavaScript': javascriptGenerator, + 'Python': pythonGenerator, + 'PHP': phpGenerator, + 'Lua': luaGenerator, + 'Dart': dartGenerator, + })[lang]; var output = document.getElementById('importExport'); - output.value = Blockly[lang].workspaceToCode(workspace); + output.value = generator.workspaceToCode(workspace); taChange(); }