mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
refactor!: Remove remaining use of goog.module.declareLegacyNamespace. (#6254)
* fix(build): Minor corrections to build_tasks.js
- Use TSC_OUTPUT_DIR to find goog/goog.js when suppressing warnings.
- Remove unnecessary trailing semicolons.
* refactor(blocks): Remove declareLegacyNamespace
Remove the call to goog.module.declareLegacyNamespace from
Blockly.libraryBlocks. This entails:
- Changes to the UMD wrapper to be able to find the exports object.
- Changes to tests/bootstrap_helper.js to save the exports object
in the libraryBlocks global variable.
- As a precaution, renaming the tests/compile/test_blocks.js module
so that goog.provide does not touch Blockly or
Blockly.libraryBlocks, which may not exist / be writable.
* feat(build): Add support named exports from chunks
We need to convert the generators to named exports. For backwards
compatibility we still want e.g. Blockly.JavaScript to point at
the generator object when the chunk is loaded using a script tag.
Modify chunkWrapper to honour a .reexportOnly property in the
chunks table and generate suitable additional code in the UMD
wrapper.
* refactor(generators): Migrate JavaScript generator to named export
- Export the JavaScript generator object as javascriptGenerator
from the Blockly.JavaScript module(generators/javascript.js).
- Modify the Blockly.JavaScript.all module
(generators/javascript/all.js) to reexport the exports from
Blockly.JavaScript.
- Update chunk configuration so the generator object remains
available as Blockly.JavaScript when loading
javascript_compressed.js via a <script> tag.
(N.B. it is otherwise necessary to destructure the require
/ import.)
- Modify bootstrap_helper.js to store that export as
window.javascriptGenerator for use in test code.
- Modify test code to use javascriptGenerator instead of
Blockly.JavaScript.
- Modify .eslintrc.json so that javascriptGenerator is allowed
as a global in test/. (Also restrict use of Blockly global
to test/.)
N.B. that demo code in demos/code/code.js uses <script> tag
loading and so will continue to access Blockly.JavaScript.
* refactor(generators): Migrate Lua generator to named export
* refactor(generators): Migrate PHP generator to named export
* refactor(generators): Migrate Python generator to named export
* refactor(generators): Remove declareLegacyNamespace calls
Remove the goog.module.declareLegacyNamespace calls from the
generators.
This turns out to have the unexpected side-effect of causing the
compiler to rename the core/blockly.js exports object from
$.Blockly to just Blockly in blockly_compressed.js - presumably
because it no longer needs to be accessed in any subsequent chunk
because they no longer add properties to it. This requires
some changes (mainly simplification) to the chunkWrapper function
in build_tasks.js.
* refactor(core): Remove declareLegacyNamespace from blockly.js
So easy to do _now_: just need to:
- Make sure the UMD wrapper for the first chunk knows where the
exports object is.
- Use that same value to set the Blockly.VERSION @define.
- Have bootstrap_helper.js set window.Blockly to the exports
object.
- Fix tests/compile/test_blocks.js to not assume a Blockly
global variable, by converting it to a goog.module so we
can use a named require.
This commit is contained in:
committed by
GitHub
parent
9797943938
commit
f947b3f4f6
@@ -78,7 +78,6 @@
|
||||
"browser": true
|
||||
},
|
||||
"globals": {
|
||||
"Blockly": true,
|
||||
"goog": true,
|
||||
"exports": true
|
||||
},
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* @namespace Blockly
|
||||
*/
|
||||
goog.module('Blockly');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
const ContextMenu = goog.require('Blockly.ContextMenu');
|
||||
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
10
tests/.eslintrc.json
Normal file
10
tests/.eslintrc.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"globals": {
|
||||
"Blockly": true,
|
||||
"dartGenerator": true,
|
||||
"javascriptGenerator": true,
|
||||
"luaGenerator": true,
|
||||
"phpGenerator": true,
|
||||
"pythonGenerator": true
|
||||
}
|
||||
}
|
||||
23
tests/bootstrap_helper.js
vendored
23
tests/bootstrap_helper.js
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.libraryBlocks.testBlocks');
|
||||
goog.module('testBlocks');
|
||||
|
||||
goog.require('Blockly');
|
||||
const Blockly = goog.require('Blockly');
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
@@ -123,35 +123,35 @@ suite('Multiline Input Fields', function() {
|
||||
* @type {Array<CodeGenerationTestSuite>}
|
||||
*/
|
||||
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('')},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
const assert = require('chai').assert;
|
||||
const Blockly = require('../../dist/');
|
||||
const {javascriptGenerator} = require('../../dist/javascript');
|
||||
|
||||
const xmlText = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
|
||||
' <block type="text_print" x="37" y="63">\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');
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user