mirror of
https://github.com/google/blockly.git
synced 2026-01-06 08:30:13 +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
|
"browser": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"Blockly": true,
|
|
||||||
"goog": true,
|
"goog": true,
|
||||||
"exports": true
|
"exports": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.libraryBlocks');
|
goog.module('Blockly.libraryBlocks');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const colour = goog.require('Blockly.libraryBlocks.colour');
|
const colour = goog.require('Blockly.libraryBlocks.colour');
|
||||||
const lists = goog.require('Blockly.libraryBlocks.lists');
|
const lists = goog.require('Blockly.libraryBlocks.lists');
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
* @namespace Blockly
|
* @namespace Blockly
|
||||||
*/
|
*/
|
||||||
goog.module('Blockly');
|
goog.module('Blockly');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const ContextMenu = goog.require('Blockly.ContextMenu');
|
const ContextMenu = goog.require('Blockly.ContextMenu');
|
||||||
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
|
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.Dart');
|
goog.module('Blockly.Dart');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const Variables = goog.require('Blockly.Variables');
|
const Variables = goog.require('Blockly.Variables');
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
@@ -301,4 +300,4 @@ Dart.getAdjusted = function(block, atId, opt_delta, opt_negate,
|
|||||||
return at;
|
return at;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = Dart;
|
exports.dartGenerator = Dart;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.all');
|
goog.module('Blockly.Dart.all');
|
||||||
|
|
||||||
|
const moduleExports = goog.require('Blockly.Dart');
|
||||||
goog.require('Blockly.Dart.colour');
|
goog.require('Blockly.Dart.colour');
|
||||||
goog.require('Blockly.Dart.lists');
|
goog.require('Blockly.Dart.lists');
|
||||||
goog.require('Blockly.Dart.logic');
|
goog.require('Blockly.Dart.logic');
|
||||||
@@ -23,3 +24,4 @@ goog.require('Blockly.Dart.texts');
|
|||||||
goog.require('Blockly.Dart.variables');
|
goog.require('Blockly.Dart.variables');
|
||||||
goog.require('Blockly.Dart.variablesDynamic');
|
goog.require('Blockly.Dart.variablesDynamic');
|
||||||
|
|
||||||
|
exports = moduleExports;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.colour');
|
goog.module('Blockly.Dart.colour');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart.addReservedWords('Math');
|
Dart.addReservedWords('Math');
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.lists');
|
goog.module('Blockly.Dart.lists');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart.addReservedWords('Math');
|
Dart.addReservedWords('Math');
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.logic');
|
goog.module('Blockly.Dart.logic');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart['controls_if'] = function(block) {
|
Dart['controls_if'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.loops');
|
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 stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.math');
|
goog.module('Blockly.Dart.math');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart.addReservedWords('Math');
|
Dart.addReservedWords('Math');
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.procedures');
|
goog.module('Blockly.Dart.procedures');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart['procedures_defreturn'] = function(block) {
|
Dart['procedures_defreturn'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.texts');
|
goog.module('Blockly.Dart.texts');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart.addReservedWords('Html,Math');
|
Dart.addReservedWords('Html,Math');
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.variables');
|
goog.module('Blockly.Dart.variables');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
|
|
||||||
|
|
||||||
Dart['variables_get'] = function(block) {
|
Dart['variables_get'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Dart.variablesDynamic');
|
goog.module('Blockly.Dart.variablesDynamic');
|
||||||
|
|
||||||
const Dart = goog.require('Blockly.Dart');
|
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.Dart.variables');
|
goog.require('Blockly.Dart.variables');
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.JavaScript');
|
goog.module('Blockly.JavaScript');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const Variables = goog.require('Blockly.Variables');
|
const Variables = goog.require('Blockly.Variables');
|
||||||
const objectUtils = goog.require('Blockly.utils.object');
|
const objectUtils = goog.require('Blockly.utils.object');
|
||||||
@@ -320,4 +319,4 @@ JavaScript.getAdjusted = function(
|
|||||||
return at;
|
return at;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = JavaScript;
|
exports.javascriptGenerator = JavaScript;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.all');
|
goog.module('Blockly.JavaScript.all');
|
||||||
|
|
||||||
|
const moduleExports = goog.require('Blockly.JavaScript');
|
||||||
goog.require('Blockly.JavaScript.colour');
|
goog.require('Blockly.JavaScript.colour');
|
||||||
goog.require('Blockly.JavaScript.lists');
|
goog.require('Blockly.JavaScript.lists');
|
||||||
goog.require('Blockly.JavaScript.logic');
|
goog.require('Blockly.JavaScript.logic');
|
||||||
@@ -23,3 +24,4 @@ goog.require('Blockly.JavaScript.texts');
|
|||||||
goog.require('Blockly.JavaScript.variables');
|
goog.require('Blockly.JavaScript.variables');
|
||||||
goog.require('Blockly.JavaScript.variablesDynamic');
|
goog.require('Blockly.JavaScript.variablesDynamic');
|
||||||
|
|
||||||
|
exports = moduleExports;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.colour');
|
goog.module('Blockly.JavaScript.colour');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['colour_picker'] = function(block) {
|
JavaScript['colour_picker'] = function(block) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.lists');
|
goog.module('Blockly.JavaScript.lists');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['lists_create_empty'] = function(block) {
|
JavaScript['lists_create_empty'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.logic');
|
goog.module('Blockly.JavaScript.logic');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['controls_if'] = function(block) {
|
JavaScript['controls_if'] = function(block) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
goog.module('Blockly.JavaScript.loops');
|
goog.module('Blockly.JavaScript.loops');
|
||||||
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['controls_repeat_ext'] = function(block) {
|
JavaScript['controls_repeat_ext'] = function(block) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.math');
|
goog.module('Blockly.JavaScript.math');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['math_number'] = function(block) {
|
JavaScript['math_number'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.procedures');
|
goog.module('Blockly.JavaScript.procedures');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['procedures_defreturn'] = function(block) {
|
JavaScript['procedures_defreturn'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.texts');
|
goog.module('Blockly.JavaScript.texts');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.variables');
|
goog.module('Blockly.JavaScript.variables');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
|
|
||||||
|
|
||||||
JavaScript['variables_get'] = function(block) {
|
JavaScript['variables_get'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.JavaScript.variablesDynamic');
|
goog.module('Blockly.JavaScript.variablesDynamic');
|
||||||
|
|
||||||
const JavaScript = goog.require('Blockly.JavaScript');
|
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.JavaScript.variables');
|
goog.require('Blockly.JavaScript.variables');
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.Lua');
|
goog.module('Blockly.Lua');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const objectUtils = goog.require('Blockly.utils.object');
|
const objectUtils = goog.require('Blockly.utils.object');
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
@@ -204,4 +203,4 @@ Lua.scrub_ = function(block, code, opt_thisOnly) {
|
|||||||
return commentCode + code + nextCode;
|
return commentCode + code + nextCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = Lua;
|
exports.luaGenerator = Lua;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.all');
|
goog.module('Blockly.Lua.all');
|
||||||
|
|
||||||
|
const moduleExports = goog.require('Blockly.Lua');
|
||||||
goog.require('Blockly.Lua.colour');
|
goog.require('Blockly.Lua.colour');
|
||||||
goog.require('Blockly.Lua.lists');
|
goog.require('Blockly.Lua.lists');
|
||||||
goog.require('Blockly.Lua.logic');
|
goog.require('Blockly.Lua.logic');
|
||||||
@@ -23,3 +24,4 @@ goog.require('Blockly.Lua.texts');
|
|||||||
goog.require('Blockly.Lua.variables');
|
goog.require('Blockly.Lua.variables');
|
||||||
goog.require('Blockly.Lua.variablesDynamic');
|
goog.require('Blockly.Lua.variablesDynamic');
|
||||||
|
|
||||||
|
exports = moduleExports;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.colour');
|
goog.module('Blockly.Lua.colour');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['colour_picker'] = function(block) {
|
Lua['colour_picker'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.lists');
|
goog.module('Blockly.Lua.lists');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['lists_create_empty'] = function(block) {
|
Lua['lists_create_empty'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.logic');
|
goog.module('Blockly.Lua.logic');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['controls_if'] = function(block) {
|
Lua['controls_if'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.loops');
|
goog.module('Blockly.Lua.loops');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.math');
|
goog.module('Blockly.Lua.math');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['math_number'] = function(block) {
|
Lua['math_number'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.procedures');
|
goog.module('Blockly.Lua.procedures');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['procedures_defreturn'] = function(block) {
|
Lua['procedures_defreturn'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.texts');
|
goog.module('Blockly.Lua.texts');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['text'] = function(block) {
|
Lua['text'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.variables');
|
goog.module('Blockly.Lua.variables');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
|
|
||||||
|
|
||||||
Lua['variables_get'] = function(block) {
|
Lua['variables_get'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Lua.variablesDynamic');
|
goog.module('Blockly.Lua.variablesDynamic');
|
||||||
|
|
||||||
const Lua = goog.require('Blockly.Lua');
|
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.Lua.variables');
|
goog.require('Blockly.Lua.variables');
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.PHP');
|
goog.module('Blockly.PHP');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const objectUtils = goog.require('Blockly.utils.object');
|
const objectUtils = goog.require('Blockly.utils.object');
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
@@ -301,4 +300,4 @@ PHP.getAdjusted = function(block, atId, opt_delta, opt_negate, opt_order) {
|
|||||||
return at;
|
return at;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = PHP;
|
exports.phpGenerator = PHP;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.all');
|
goog.module('Blockly.PHP.all');
|
||||||
|
|
||||||
|
const moduleExports = goog.require('Blockly.PHP');
|
||||||
goog.require('Blockly.PHP.colour');
|
goog.require('Blockly.PHP.colour');
|
||||||
goog.require('Blockly.PHP.lists');
|
goog.require('Blockly.PHP.lists');
|
||||||
goog.require('Blockly.PHP.logic');
|
goog.require('Blockly.PHP.logic');
|
||||||
@@ -23,3 +24,4 @@ goog.require('Blockly.PHP.texts');
|
|||||||
goog.require('Blockly.PHP.variables');
|
goog.require('Blockly.PHP.variables');
|
||||||
goog.require('Blockly.PHP.variablesDynamic');
|
goog.require('Blockly.PHP.variablesDynamic');
|
||||||
|
|
||||||
|
exports = moduleExports;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.colour');
|
goog.module('Blockly.PHP.colour');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['colour_picker'] = function(block) {
|
PHP['colour_picker'] = function(block) {
|
||||||
|
|||||||
@@ -22,10 +22,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.lists');
|
goog.module('Blockly.PHP.lists');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
PHP['lists_create_empty'] = function(block) {
|
PHP['lists_create_empty'] = function(block) {
|
||||||
// Create an empty list.
|
// Create an empty list.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.logic');
|
goog.module('Blockly.PHP.logic');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['controls_if'] = function(block) {
|
PHP['controls_if'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.loops');
|
goog.module('Blockly.PHP.loops');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['controls_repeat_ext'] = function(block) {
|
PHP['controls_repeat_ext'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.math');
|
goog.module('Blockly.PHP.math');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['math_number'] = function(block) {
|
PHP['math_number'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.procedures');
|
goog.module('Blockly.PHP.procedures');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const Variables = goog.require('Blockly.Variables');
|
const Variables = goog.require('Blockly.Variables');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['procedures_defreturn'] = function(block) {
|
PHP['procedures_defreturn'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.texts');
|
goog.module('Blockly.PHP.texts');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['text'] = function(block) {
|
PHP['text'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.variables');
|
goog.module('Blockly.PHP.variables');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
|
|
||||||
|
|
||||||
PHP['variables_get'] = function(block) {
|
PHP['variables_get'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.PHP.variablesDynamic');
|
goog.module('Blockly.PHP.variablesDynamic');
|
||||||
|
|
||||||
const PHP = goog.require('Blockly.PHP');
|
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.PHP.variables');
|
goog.require('Blockly.PHP.variables');
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.module('Blockly.Python');
|
goog.module('Blockly.Python');
|
||||||
goog.module.declareLegacyNamespace();
|
|
||||||
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const Variables = goog.require('Blockly.Variables');
|
const Variables = goog.require('Blockly.Variables');
|
||||||
@@ -331,4 +330,4 @@ Python.getAdjustedInt = function(block, atId, opt_delta, opt_negate) {
|
|||||||
return at;
|
return at;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = Python;
|
exports.pythonGenerator = Python;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.all');
|
goog.module('Blockly.Python.all');
|
||||||
|
|
||||||
|
const moduleExports = goog.require('Blockly.Python');
|
||||||
goog.require('Blockly.Python.colour');
|
goog.require('Blockly.Python.colour');
|
||||||
goog.require('Blockly.Python.lists');
|
goog.require('Blockly.Python.lists');
|
||||||
goog.require('Blockly.Python.logic');
|
goog.require('Blockly.Python.logic');
|
||||||
@@ -23,3 +24,4 @@ goog.require('Blockly.Python.texts');
|
|||||||
goog.require('Blockly.Python.variables');
|
goog.require('Blockly.Python.variables');
|
||||||
goog.require('Blockly.Python.variablesDynamic');
|
goog.require('Blockly.Python.variablesDynamic');
|
||||||
|
|
||||||
|
exports = moduleExports;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.colour');
|
goog.module('Blockly.Python.colour');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['colour_picker'] = function(block) {
|
Python['colour_picker'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.lists');
|
goog.module('Blockly.Python.lists');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['lists_create_empty'] = function(block) {
|
Python['lists_create_empty'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.logic');
|
goog.module('Blockly.Python.logic');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['controls_if'] = function(block) {
|
Python['controls_if'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.loops');
|
goog.module('Blockly.Python.loops');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['controls_repeat_ext'] = function(block) {
|
Python['controls_repeat_ext'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.math');
|
goog.module('Blockly.Python.math');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
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.
|
// If any new block imports any library, add that library name here.
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.procedures');
|
goog.module('Blockly.Python.procedures');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const Variables = goog.require('Blockly.Variables');
|
const Variables = goog.require('Blockly.Variables');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['procedures_defreturn'] = function(block) {
|
Python['procedures_defreturn'] = function(block) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.texts');
|
goog.module('Blockly.Python.texts');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const stringUtils = goog.require('Blockly.utils.string');
|
const stringUtils = goog.require('Blockly.utils.string');
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['text'] = function(block) {
|
Python['text'] = function(block) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.variables');
|
goog.module('Blockly.Python.variables');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
|
||||||
const {NameType} = goog.require('Blockly.Names');
|
const {NameType} = goog.require('Blockly.Names');
|
||||||
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
|
|
||||||
|
|
||||||
Python['variables_get'] = function(block) {
|
Python['variables_get'] = function(block) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
goog.module('Blockly.Python.variablesDynamic');
|
goog.module('Blockly.Python.variablesDynamic');
|
||||||
|
|
||||||
const Python = goog.require('Blockly.Python');
|
const {pythonGenerator: Python} = goog.require('Blockly.Python');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.Python.variables');
|
goog.require('Blockly.Python.variables');
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,14 @@ const NAMESPACE_PROPERTY = '__namespace__';
|
|||||||
* will be written to.
|
* will be written to.
|
||||||
* - .entry: the source .js file which is the entrypoint for the
|
* - .entry: the source .js file which is the entrypoint for the
|
||||||
* chunk.
|
* 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
|
* - .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
|
* The function getChunkOptions will, after running
|
||||||
* closure-calculate-chunks, update each chunk to add the following
|
* closure-calculate-chunks, update each chunk to add the following
|
||||||
@@ -104,37 +110,49 @@ const chunks = [
|
|||||||
{
|
{
|
||||||
name: 'blockly',
|
name: 'blockly',
|
||||||
entry: path.join(CORE_DIR, 'blockly.js'),
|
entry: path.join(CORE_DIR, 'blockly.js'),
|
||||||
|
exports: 'module$exports$Blockly',
|
||||||
reexport: 'Blockly',
|
reexport: 'Blockly',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'blocks',
|
name: 'blocks',
|
||||||
entry: 'blocks/blocks.js',
|
entry: 'blocks/blocks.js',
|
||||||
|
exports: 'module$exports$Blockly$libraryBlocks',
|
||||||
reexport: 'Blockly.libraryBlocks',
|
reexport: 'Blockly.libraryBlocks',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'javascript',
|
name: 'javascript',
|
||||||
entry: 'generators/javascript/all.js',
|
entry: 'generators/javascript/all.js',
|
||||||
|
exports: 'module$exports$Blockly$JavaScript',
|
||||||
reexport: 'Blockly.JavaScript',
|
reexport: 'Blockly.JavaScript',
|
||||||
|
reexportOnly: 'javascriptGenerator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'python',
|
name: 'python',
|
||||||
entry: 'generators/python/all.js',
|
entry: 'generators/python/all.js',
|
||||||
|
exports: 'module$exports$Blockly$Python',
|
||||||
reexport: 'Blockly.Python',
|
reexport: 'Blockly.Python',
|
||||||
|
reexportOnly: 'pythonGenerator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'php',
|
name: 'php',
|
||||||
entry: 'generators/php/all.js',
|
entry: 'generators/php/all.js',
|
||||||
|
exports: 'module$exports$Blockly$PHP',
|
||||||
reexport: 'Blockly.PHP',
|
reexport: 'Blockly.PHP',
|
||||||
|
reexportOnly: 'phpGenerator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'lua',
|
name: 'lua',
|
||||||
entry: 'generators/lua/all.js',
|
entry: 'generators/lua/all.js',
|
||||||
|
exports: 'module$exports$Blockly$Lua',
|
||||||
reexport: 'Blockly.Lua',
|
reexport: 'Blockly.Lua',
|
||||||
|
reexportOnly: 'luaGenerator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'dart',
|
name: 'dart',
|
||||||
entry: 'generators/dart/all.js',
|
entry: 'generators/dart/all.js',
|
||||||
|
exports: 'module$exports$Blockly$Dart',
|
||||||
reexport: 'Blockly.Dart',
|
reexport: 'Blockly.Dart',
|
||||||
|
reexportOnly: 'dartGenerator',
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -311,7 +329,7 @@ function buildDeps(done) {
|
|||||||
execSync(`closure-make-deps ${testArgs} | grep 'tests/mocha' ` +
|
execSync(`closure-make-deps ${testArgs} | grep 'tests/mocha' ` +
|
||||||
`> '${TEST_DEPS_FILE}'`, {stdio: 'inherit'});
|
`> '${TEST_DEPS_FILE}'`, {stdio: 'inherit'});
|
||||||
done();
|
done();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task regenrates msg/json/en.js and msg/json/qqq.js from
|
* This task regenrates msg/json/en.js and msg/json/qqq.js from
|
||||||
@@ -341,7 +359,7 @@ this removal!
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task builds Blockly's lang files.
|
* This task builds Blockly's lang files.
|
||||||
@@ -367,7 +385,7 @@ function buildLangfiles(done) {
|
|||||||
execSync(createMessagesCmd, {stdio: 'inherit'});
|
execSync(createMessagesCmd, {stdio: 'inherit'});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper method to return an closure compiler chunk wrapper that
|
* A helper method to return an closure compiler chunk wrapper that
|
||||||
@@ -399,16 +417,20 @@ function chunkWrapper(chunk) {
|
|||||||
namespaceExpr = `${factoryArgs}.${NAMESPACE_PROPERTY}`;
|
namespaceExpr = `${factoryArgs}.${NAMESPACE_PROPERTY}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expression that evaluates the the value of the exports object for
|
// Code to assign the result of the factory function to the desired
|
||||||
// the specified chunk. For now we guess the name that is created
|
// export location when running in a browser. When
|
||||||
// by the module's goog.module.delcareLegacyNamespace call based on
|
// chunk.reexportOnly is set, this additionally does two other
|
||||||
// chunk.reexport.
|
// things:
|
||||||
const exportsExpression = `${NAMESPACE_VARIABLE}.${chunk.reexport}`;
|
// - It ensures that only the desired property of the exports object
|
||||||
// In near future we might try to guess the internally-generated
|
// is assigned to the specified reexport location.
|
||||||
// name for the ES module's exports object.
|
// - It ensures that the namesspace object is accessible via the
|
||||||
// const exportsExpression =
|
// selected sub-object, so that any dependent modules can obtain
|
||||||
// 'module$' + chunk.entry.replace(/\.m?js$/, '').replace(/\//g, '$');
|
// 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
|
// Note that when loading in a browser the base of the exported path
|
||||||
// (e.g. Blockly.blocks.all - see issue #5932) might not exist
|
// (e.g. Blockly.blocks.all - see issue #5932) might not exist
|
||||||
@@ -425,16 +447,16 @@ function chunkWrapper(chunk) {
|
|||||||
module.exports = factory(${cjsDepsExpr});
|
module.exports = factory(${cjsDepsExpr});
|
||||||
} else { // Browser
|
} else { // Browser
|
||||||
var factoryExports = factory(${browserDepsExpr});
|
var factoryExports = factory(${browserDepsExpr});
|
||||||
root.${chunk.reexport} = factoryExports;
|
${browserExportStatements}
|
||||||
}
|
}
|
||||||
}(this, function(${factoryArgs}) {
|
}(this, function(${factoryArgs}) {
|
||||||
var ${NAMESPACE_VARIABLE}=${namespaceExpr};
|
var ${NAMESPACE_VARIABLE}=${namespaceExpr};
|
||||||
%output%
|
%output%
|
||||||
${exportsExpression}.${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE};
|
${chunk.exports}.${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE};
|
||||||
return ${exportsExpression};
|
return ${chunk.exports};
|
||||||
}));
|
}));
|
||||||
`;
|
`;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get chunking options to pass to Closure Compiler by using
|
* 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
|
// declared by base_minimal.js, while if you compile against
|
||||||
// base.js instead you will discover that it uses @deprecated
|
// base.js instead you will discover that it uses @deprecated
|
||||||
// inherits, forwardDeclare etc.
|
// 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'],
|
define: ['COMPILED=true'],
|
||||||
};
|
};
|
||||||
if (argv.debug || argv.strict) {
|
if (argv.debug || argv.strict) {
|
||||||
@@ -594,7 +619,13 @@ function buildCompiled() {
|
|||||||
// Closure Compiler options.
|
// Closure Compiler options.
|
||||||
const packageJson = getPackageJson(); // For version number.
|
const packageJson = getPackageJson(); // For version number.
|
||||||
const options = {
|
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: chunkOptions.chunk,
|
||||||
chunk_wrapper: chunkOptions.chunk_wrapper,
|
chunk_wrapper: chunkOptions.chunk_wrapper,
|
||||||
rename_prefix_namespace: NAMESPACE_VARIABLE,
|
rename_prefix_namespace: NAMESPACE_VARIABLE,
|
||||||
@@ -611,7 +642,7 @@ function buildCompiled() {
|
|||||||
.pipe(
|
.pipe(
|
||||||
gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'}))
|
gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'}))
|
||||||
.pipe(gulp.dest(BUILD_DIR));
|
.pipe(gulp.dest(BUILD_DIR));
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task builds Blockly core, blocks and generators together and uses
|
* This task builds Blockly core, blocks and generators together and uses
|
||||||
@@ -671,7 +702,7 @@ function checkinBuilt() {
|
|||||||
`${BUILD_DIR}/*_compressed.js.map`,
|
`${BUILD_DIR}/*_compressed.js.map`,
|
||||||
`${BUILD_DIR}/msg/js/*.js`,
|
`${BUILD_DIR}/msg/js/*.js`,
|
||||||
], {base: BUILD_DIR}).pipe(gulp.dest('.'));
|
], {base: BUILD_DIR}).pipe(gulp.dest('.'));
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task cleans the build directory (by deleting it).
|
* This task cleans the build directory (by deleting it).
|
||||||
@@ -694,7 +725,7 @@ function format() {
|
|||||||
], {base: '.'})
|
], {base: '.'})
|
||||||
.pipe(clangFormatter.format('file', clangFormat))
|
.pipe(clangFormatter.format('file', clangFormat))
|
||||||
.pipe(gulp.dest('.'));
|
.pipe(gulp.dest('.'));
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
build: build,
|
build: build,
|
||||||
|
|||||||
@@ -287,8 +287,8 @@
|
|||||||
"./generators/javascript/loops.js",
|
"./generators/javascript/loops.js",
|
||||||
"./generators/javascript/logic.js",
|
"./generators/javascript/logic.js",
|
||||||
"./generators/javascript/lists.js",
|
"./generators/javascript/lists.js",
|
||||||
"./generators/javascript.js",
|
|
||||||
"./generators/javascript/colour.js",
|
"./generators/javascript/colour.js",
|
||||||
|
"./generators/javascript.js",
|
||||||
"./generators/javascript/all.js",
|
"./generators/javascript/all.js",
|
||||||
"./generators/python/variables_dynamic.js",
|
"./generators/python/variables_dynamic.js",
|
||||||
"./generators/python/variables.js",
|
"./generators/python/variables.js",
|
||||||
@@ -298,8 +298,8 @@
|
|||||||
"./generators/python/loops.js",
|
"./generators/python/loops.js",
|
||||||
"./generators/python/logic.js",
|
"./generators/python/logic.js",
|
||||||
"./generators/python/lists.js",
|
"./generators/python/lists.js",
|
||||||
"./generators/python.js",
|
|
||||||
"./generators/python/colour.js",
|
"./generators/python/colour.js",
|
||||||
|
"./generators/python.js",
|
||||||
"./generators/python/all.js",
|
"./generators/python/all.js",
|
||||||
"./generators/php/variables_dynamic.js",
|
"./generators/php/variables_dynamic.js",
|
||||||
"./generators/php/variables.js",
|
"./generators/php/variables.js",
|
||||||
@@ -309,8 +309,8 @@
|
|||||||
"./generators/php/loops.js",
|
"./generators/php/loops.js",
|
||||||
"./generators/php/logic.js",
|
"./generators/php/logic.js",
|
||||||
"./generators/php/lists.js",
|
"./generators/php/lists.js",
|
||||||
"./generators/php.js",
|
|
||||||
"./generators/php/colour.js",
|
"./generators/php/colour.js",
|
||||||
|
"./generators/php.js",
|
||||||
"./generators/php/all.js",
|
"./generators/php/all.js",
|
||||||
"./generators/lua/variables_dynamic.js",
|
"./generators/lua/variables_dynamic.js",
|
||||||
"./generators/lua/variables.js",
|
"./generators/lua/variables.js",
|
||||||
@@ -320,8 +320,8 @@
|
|||||||
"./generators/lua/loops.js",
|
"./generators/lua/loops.js",
|
||||||
"./generators/lua/logic.js",
|
"./generators/lua/logic.js",
|
||||||
"./generators/lua/lists.js",
|
"./generators/lua/lists.js",
|
||||||
"./generators/lua.js",
|
|
||||||
"./generators/lua/colour.js",
|
"./generators/lua/colour.js",
|
||||||
|
"./generators/lua.js",
|
||||||
"./generators/lua/all.js",
|
"./generators/lua/all.js",
|
||||||
"./generators/dart/variables_dynamic.js",
|
"./generators/dart/variables_dynamic.js",
|
||||||
"./generators/dart/variables.js",
|
"./generators/dart/variables.js",
|
||||||
@@ -331,8 +331,8 @@
|
|||||||
"./generators/dart/loops.js",
|
"./generators/dart/loops.js",
|
||||||
"./generators/dart/logic.js",
|
"./generators/dart/logic.js",
|
||||||
"./generators/dart/lists.js",
|
"./generators/dart/lists.js",
|
||||||
"./generators/dart.js",
|
|
||||||
"./generators/dart/colour.js",
|
"./generators/dart/colour.js",
|
||||||
|
"./generators/dart.js",
|
||||||
"./generators/dart/all.js"
|
"./generators/dart/all.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1341,6 +1341,31 @@
|
|||||||
{
|
{
|
||||||
'oldName': 'Blockly.utils.global',
|
'oldName': 'Blockly.utils.global',
|
||||||
'newPath': 'globalThis',
|
'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 */
|
/* eslint-disable-next-line no-undef */
|
||||||
for (const require of window.bootstrapInfo.requires) {
|
for (const require of window.bootstrapInfo.requires) {
|
||||||
goog.require(require);
|
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} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.libraryBlocks.texts');
|
goog.require('Blockly.libraryBlocks.texts');
|
||||||
/** @suppress {extraRequire} */
|
/** @suppress {extraRequire} */
|
||||||
goog.require('Blockly.libraryBlocks.testBlocks');
|
goog.require('testBlocks');
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('Blockly.libraryBlocks.testBlocks');
|
goog.module('testBlocks');
|
||||||
|
|
||||||
goog.require('Blockly');
|
const Blockly = goog.require('Blockly');
|
||||||
|
|
||||||
Blockly.defineBlocksWithJsonArray([
|
Blockly.defineBlocksWithJsonArray([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -170,31 +170,31 @@ function toXml() {
|
|||||||
|
|
||||||
function toJavaScript() {
|
function toJavaScript() {
|
||||||
var code = '\'use strict\';\n\n'
|
var code = '\'use strict\';\n\n'
|
||||||
code += Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
code += javascriptGenerator.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
outputCode = code;
|
outputCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPython() {
|
function toPython() {
|
||||||
var code = Blockly.Python.workspaceToCode(demoWorkspace);
|
var code = pythonGenerator.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
outputCode = code;
|
outputCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPhp() {
|
function toPhp() {
|
||||||
var code = Blockly.PHP.workspaceToCode(demoWorkspace);
|
var code = phpGenerator.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
outputCode = code;
|
outputCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toLua() {
|
function toLua() {
|
||||||
var code = Blockly.Lua.workspaceToCode(demoWorkspace);
|
var code = luaGenerator.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
outputCode = code;
|
outputCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDart() {
|
function toDart() {
|
||||||
var code = Blockly.Dart.workspaceToCode(demoWorkspace);
|
var code = dartGenerator.workspaceToCode(demoWorkspace);
|
||||||
setOutput(code);
|
setOutput(code);
|
||||||
outputCode = code;
|
outputCode = code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Blockly.Dart['unittest_main'] = function(block) {
|
dartGenerator['unittest_main'] = function(block) {
|
||||||
// Container for unit tests.
|
// Container for unit tests.
|
||||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Dart.provideFunction_(
|
var functionName = dartGenerator.provideFunction_(
|
||||||
'unittest_report',
|
'unittest_report',
|
||||||
[ 'String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
[ 'String ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||||
' // Create test report.',
|
' // Create test report.',
|
||||||
' List report = [];',
|
' List report = [];',
|
||||||
' StringBuffer summary = new StringBuffer();',
|
' StringBuffer summary = new StringBuffer();',
|
||||||
@@ -50,7 +50,7 @@ Blockly.Dart['unittest_main'] = function(block) {
|
|||||||
block.getFieldValue('SUITE_NAME') +
|
block.getFieldValue('SUITE_NAME') +
|
||||||
'\');\n';
|
'\');\n';
|
||||||
// Run tests (unindented).
|
// Run tests (unindented).
|
||||||
code += Blockly.Dart.statementToCode(block, 'DO')
|
code += dartGenerator.statementToCode(block, 'DO')
|
||||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||||
// Print the report to the console (that's where errors will go anyway).
|
// Print the report to the console (that's where errors will go anyway).
|
||||||
code += 'print(' + functionName + '());\n';
|
code += 'print(' + functionName + '());\n';
|
||||||
@@ -59,12 +59,12 @@ Blockly.Dart['unittest_main'] = function(block) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Dart['unittest_main'].defineAssert_ = function() {
|
dartGenerator['unittest_main'].defineAssert_ = function() {
|
||||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Dart.provideFunction_(
|
var functionName = dartGenerator.provideFunction_(
|
||||||
'unittest_assertequals',
|
'unittest_assertequals',
|
||||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
[ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(dynamic actual, dynamic expected, String message) {',
|
'(dynamic actual, dynamic expected, String message) {',
|
||||||
' // Asserts that a value equals another value.',
|
' // Asserts that a value equals another value.',
|
||||||
' if (' + resultsVar + ' == null) {',
|
' if (' + resultsVar + ' == null) {',
|
||||||
@@ -96,24 +96,24 @@ Blockly.Dart['unittest_main'].defineAssert_ = function() {
|
|||||||
return functionName;
|
return functionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Dart['unittest_assertequals'] = function(block) {
|
dartGenerator['unittest_assertequals'] = function(block) {
|
||||||
// Asserts that a value equals another value.
|
// Asserts that a value equals another value.
|
||||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
var message = dartGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Dart.ORDER_NONE) || '';
|
dartGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
var actual = dartGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Dart.ORDER_NONE) || 'null';
|
dartGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = Blockly.Dart.valueToCode(block, 'EXPECTED',
|
var expected = dartGenerator.valueToCode(block, 'EXPECTED',
|
||||||
Blockly.Dart.ORDER_NONE) || 'null';
|
dartGenerator.ORDER_NONE) || 'null';
|
||||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
return dartGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Dart['unittest_assertvalue'] = function(block) {
|
dartGenerator['unittest_assertvalue'] = function(block) {
|
||||||
// Asserts that a value is true, false, or null.
|
// Asserts that a value is true, false, or null.
|
||||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
var message = dartGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Dart.ORDER_NONE) || '';
|
dartGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
var actual = dartGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Dart.ORDER_NONE) || 'null';
|
dartGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = block.getFieldValue('EXPECTED');
|
var expected = block.getFieldValue('EXPECTED');
|
||||||
if (expected === 'TRUE') {
|
if (expected === 'TRUE') {
|
||||||
expected = 'true';
|
expected = 'true';
|
||||||
@@ -122,18 +122,18 @@ Blockly.Dart['unittest_assertvalue'] = function(block) {
|
|||||||
} else if (expected === 'NULL') {
|
} else if (expected === 'NULL') {
|
||||||
expected = 'null';
|
expected = 'null';
|
||||||
}
|
}
|
||||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
return dartGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Dart['unittest_fail'] = function(block) {
|
dartGenerator['unittest_fail'] = function(block) {
|
||||||
// Always assert an error.
|
// Always assert an error.
|
||||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var message = Blockly.Dart.quote_(block.getFieldValue('MESSAGE'));
|
var message = dartGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||||
var functionName = Blockly.Dart.provideFunction_(
|
var functionName = dartGenerator.provideFunction_(
|
||||||
'unittest_fail',
|
'unittest_fail',
|
||||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
[ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(String message) {',
|
'(String message) {',
|
||||||
' // Always assert an error.',
|
' // Always assert an error.',
|
||||||
' if (' + resultsVar + ' == null) {',
|
' if (' + resultsVar + ' == null) {',
|
||||||
@@ -144,20 +144,20 @@ Blockly.Dart['unittest_fail'] = function(block) {
|
|||||||
return functionName + '(' + message + ');\n';
|
return functionName + '(' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Dart['unittest_adjustindex'] = function(block) {
|
dartGenerator['unittest_adjustindex'] = function(block) {
|
||||||
var index = Blockly.Dart.valueToCode(block, 'INDEX',
|
var index = dartGenerator.valueToCode(block, 'INDEX',
|
||||||
Blockly.Dart.ORDER_ADDITIVE) || '0';
|
dartGenerator.ORDER_ADDITIVE) || '0';
|
||||||
// Adjust index if using one-based indexing.
|
// Adjust index if using one-based indexing.
|
||||||
if (block.workspace.options.oneBasedIndex) {
|
if (block.workspace.options.oneBasedIndex) {
|
||||||
if (Blockly.isNumber(index)) {
|
if (Blockly.isNumber(index)) {
|
||||||
// If the index is a naked number, adjust it right now.
|
// 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 {
|
} else {
|
||||||
// If the index is dynamic, adjust it in code.
|
// If the index is dynamic, adjust it in code.
|
||||||
index = index + ' + 1';
|
index = index + ' + 1';
|
||||||
}
|
}
|
||||||
} else if (Blockly.isNumber(index)) {
|
} 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';
|
'use strict';
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_main'] = function(block) {
|
javascriptGenerator['unittest_main'] = function(block) {
|
||||||
// Container for unit tests.
|
// Container for unit tests.
|
||||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = javascriptGenerator.provideFunction_(
|
||||||
'unittest_report',
|
'unittest_report',
|
||||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||||
' // Create test report.',
|
' // Create test report.',
|
||||||
' var report = [];',
|
' var report = [];',
|
||||||
' var summary = [];',
|
' var summary = [];',
|
||||||
@@ -51,7 +51,7 @@ Blockly.JavaScript['unittest_main'] = function(block) {
|
|||||||
block.getFieldValue('SUITE_NAME') +
|
block.getFieldValue('SUITE_NAME') +
|
||||||
'\')\n';
|
'\')\n';
|
||||||
// Run tests (unindented).
|
// Run tests (unindented).
|
||||||
code += Blockly.JavaScript.statementToCode(block, 'DO')
|
code += javascriptGenerator.statementToCode(block, 'DO')
|
||||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||||
// Send the report to the console (that's where errors will go anyway).
|
// Send the report to the console (that's where errors will go anyway).
|
||||||
code += 'console.log(' + functionName + '());\n';
|
code += 'console.log(' + functionName + '());\n';
|
||||||
@@ -60,12 +60,12 @@ Blockly.JavaScript['unittest_main'] = function(block) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
|
javascriptGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = javascriptGenerator.provideFunction_(
|
||||||
'assertEquals',
|
'assertEquals',
|
||||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(actual, expected, message) {',
|
'(actual, expected, message) {',
|
||||||
' // Asserts that a value equals another value.',
|
' // Asserts that a value equals another value.',
|
||||||
' if (!' + resultsVar + ') {',
|
' if (!' + resultsVar + ') {',
|
||||||
@@ -100,24 +100,24 @@ Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
|
|||||||
return functionName;
|
return functionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_assertequals'] = function(block) {
|
javascriptGenerator['unittest_assertequals'] = function(block) {
|
||||||
// Asserts that a value equals another value.
|
// Asserts that a value equals another value.
|
||||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
var message = javascriptGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.JavaScript.ORDER_NONE) || '';
|
javascriptGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
var actual = javascriptGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
javascriptGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = Blockly.JavaScript.valueToCode(block, 'EXPECTED',
|
var expected = javascriptGenerator.valueToCode(block, 'EXPECTED',
|
||||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
javascriptGenerator.ORDER_NONE) || 'null';
|
||||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
return javascriptGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_assertvalue'] = function(block) {
|
javascriptGenerator['unittest_assertvalue'] = function(block) {
|
||||||
// Asserts that a value is true, false, or null.
|
// Asserts that a value is true, false, or null.
|
||||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
var message = javascriptGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.JavaScript.ORDER_NONE) || '';
|
javascriptGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
var actual = javascriptGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
javascriptGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = block.getFieldValue('EXPECTED');
|
var expected = block.getFieldValue('EXPECTED');
|
||||||
if (expected === 'TRUE') {
|
if (expected === 'TRUE') {
|
||||||
expected = 'true';
|
expected = 'true';
|
||||||
@@ -126,18 +126,18 @@ Blockly.JavaScript['unittest_assertvalue'] = function(block) {
|
|||||||
} else if (expected === 'NULL') {
|
} else if (expected === 'NULL') {
|
||||||
expected = 'null';
|
expected = 'null';
|
||||||
}
|
}
|
||||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
return javascriptGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_fail'] = function(block) {
|
javascriptGenerator['unittest_fail'] = function(block) {
|
||||||
// Always assert an error.
|
// Always assert an error.
|
||||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var message = Blockly.JavaScript.quote_(block.getFieldValue('MESSAGE'));
|
var message = javascriptGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = javascriptGenerator.provideFunction_(
|
||||||
'unittest_fail',
|
'unittest_fail',
|
||||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(message) {',
|
'(message) {',
|
||||||
' // Always assert an error.',
|
' // Always assert an error.',
|
||||||
' if (!' + resultsVar + ') {',
|
' if (!' + resultsVar + ') {',
|
||||||
@@ -148,20 +148,20 @@ Blockly.JavaScript['unittest_fail'] = function(block) {
|
|||||||
return functionName + '(' + message + ');\n';
|
return functionName + '(' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.JavaScript['unittest_adjustindex'] = function(block) {
|
javascriptGenerator['unittest_adjustindex'] = function(block) {
|
||||||
var index = Blockly.JavaScript.valueToCode(block, 'INDEX',
|
var index = javascriptGenerator.valueToCode(block, 'INDEX',
|
||||||
Blockly.JavaScript.ORDER_ADDITION) || '0';
|
javascriptGenerator.ORDER_ADDITION) || '0';
|
||||||
// Adjust index if using one-based indexing.
|
// Adjust index if using one-based indexing.
|
||||||
if (block.workspace.options.oneBasedIndex) {
|
if (block.workspace.options.oneBasedIndex) {
|
||||||
if (Blockly.isNumber(index)) {
|
if (Blockly.isNumber(index)) {
|
||||||
// If the index is a naked number, adjust it right now.
|
// 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 {
|
} else {
|
||||||
// If the index is dynamic, adjust it in code.
|
// If the index is dynamic, adjust it in code.
|
||||||
index = index + ' + 1';
|
index = index + ' + 1';
|
||||||
}
|
}
|
||||||
} else if (Blockly.isNumber(index)) {
|
} 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';
|
'use strict';
|
||||||
|
|
||||||
Blockly.Lua['unittest_main'] = function(block) {
|
luaGenerator['unittest_main'] = function(block) {
|
||||||
// Container for unit tests.
|
// Container for unit tests.
|
||||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Lua.provideFunction_(
|
var functionName = luaGenerator.provideFunction_(
|
||||||
'unittest_report',
|
'unittest_report',
|
||||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '()',
|
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '()',
|
||||||
' -- Create test report.',
|
' -- Create test report.',
|
||||||
' local report = {}',
|
' local report = {}',
|
||||||
' local summary = {}',
|
' local summary = {}',
|
||||||
@@ -49,7 +49,7 @@ Blockly.Lua['unittest_main'] = function(block) {
|
|||||||
block.getFieldValue('SUITE_NAME') +
|
block.getFieldValue('SUITE_NAME') +
|
||||||
'\')\n';
|
'\')\n';
|
||||||
// Run tests (unindented).
|
// Run tests (unindented).
|
||||||
code += Blockly.Lua.statementToCode(block, 'DO')
|
code += luaGenerator.statementToCode(block, 'DO')
|
||||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||||
// Print the report.
|
// Print the report.
|
||||||
code += 'print(' + functionName + '())\n';
|
code += 'print(' + functionName + '())\n';
|
||||||
@@ -58,12 +58,12 @@ Blockly.Lua['unittest_main'] = function(block) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
|
luaGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Lua.provideFunction_(
|
var functionName = luaGenerator.provideFunction_(
|
||||||
'assertEquals',
|
'assertEquals',
|
||||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +
|
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(actual, expected, message)',
|
'(actual, expected, message)',
|
||||||
' -- Asserts that a value equals another value.',
|
' -- Asserts that a value equals another value.',
|
||||||
' assert(' + resultsVar + ' ~= nil, ' +
|
' assert(' + resultsVar + ' ~= nil, ' +
|
||||||
@@ -106,24 +106,24 @@ Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
|
|||||||
return functionName;
|
return functionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['unittest_assertequals'] = function(block) {
|
luaGenerator['unittest_assertequals'] = function(block) {
|
||||||
// Asserts that a value equals another value.
|
// Asserts that a value equals another value.
|
||||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
var message = luaGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Lua.ORDER_NONE) || '';
|
luaGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
var actual = luaGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
luaGenerator.ORDER_NONE) || 'nil';
|
||||||
var expected = Blockly.Lua.valueToCode(block, 'EXPECTED',
|
var expected = luaGenerator.valueToCode(block, 'EXPECTED',
|
||||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
luaGenerator.ORDER_NONE) || 'nil';
|
||||||
return Blockly.Lua['unittest_main'].defineAssert_() +
|
return luaGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['unittest_assertvalue'] = function(block) {
|
luaGenerator['unittest_assertvalue'] = function(block) {
|
||||||
// Asserts that a value is true, false, or null.
|
// Asserts that a value is true, false, or null.
|
||||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
var message = luaGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Lua.ORDER_NONE) || '';
|
luaGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
var actual = luaGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
luaGenerator.ORDER_NONE) || 'nil';
|
||||||
var expected = block.getFieldValue('EXPECTED');
|
var expected = block.getFieldValue('EXPECTED');
|
||||||
if (expected == 'TRUE') {
|
if (expected == 'TRUE') {
|
||||||
expected = 'true';
|
expected = 'true';
|
||||||
@@ -132,18 +132,18 @@ Blockly.Lua['unittest_assertvalue'] = function(block) {
|
|||||||
} else if (expected == 'NULL') {
|
} else if (expected == 'NULL') {
|
||||||
expected = 'nil';
|
expected = 'nil';
|
||||||
}
|
}
|
||||||
return Blockly.Lua.unittest_main.defineAssert_() +
|
return luaGenerator.unittest_main.defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['unittest_fail'] = function(block) {
|
luaGenerator['unittest_fail'] = function(block) {
|
||||||
// Always assert an error.
|
// Always assert an error.
|
||||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var message = Blockly.Lua.quote_(block.getFieldValue('MESSAGE'));
|
var message = luaGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||||
var functionName = Blockly.Lua.provideFunction_(
|
var functionName = luaGenerator.provideFunction_(
|
||||||
'unittest_fail',
|
'unittest_fail',
|
||||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(message)',
|
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message)',
|
||||||
' -- Always assert an error.',
|
' -- Always assert an error.',
|
||||||
' assert(' + resultsVar +
|
' assert(' + resultsVar +
|
||||||
' ~= nil, "Orphaned assert fail: " .. message)',
|
' ~= nil, "Orphaned assert fail: " .. message)',
|
||||||
@@ -153,13 +153,13 @@ Blockly.Lua['unittest_fail'] = function(block) {
|
|||||||
return functionName + '(' + message + ')\n';
|
return functionName + '(' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['unittest_adjustindex'] = function(block) {
|
luaGenerator['unittest_adjustindex'] = function(block) {
|
||||||
var index = Blockly.Lua.valueToCode(block, 'INDEX',
|
var index = luaGenerator.valueToCode(block, 'INDEX',
|
||||||
Blockly.Lua.ORDER_ADDITIVE) || '0';
|
luaGenerator.ORDER_ADDITIVE) || '0';
|
||||||
if (Blockly.isNumber(index)) {
|
if (Blockly.isNumber(index)) {
|
||||||
// If the index is a naked number, adjust it right now.
|
// 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.
|
// 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';
|
'use strict';
|
||||||
|
|
||||||
Blockly.PHP['unittest_main'] = function(block) {
|
phpGenerator['unittest_main'] = function(block) {
|
||||||
// Container for unit tests.
|
// Container for unit tests.
|
||||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.PHP.provideFunction_(
|
var functionName = phpGenerator.provideFunction_(
|
||||||
'unittest_report',
|
'unittest_report',
|
||||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
[ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||||
' global ' + resultsVar + ';',
|
' global ' + resultsVar + ';',
|
||||||
' // Create test report.',
|
' // Create test report.',
|
||||||
' $report = array();',
|
' $report = array();',
|
||||||
@@ -51,7 +51,7 @@ Blockly.PHP['unittest_main'] = function(block) {
|
|||||||
block.getFieldValue('SUITE_NAME') +
|
block.getFieldValue('SUITE_NAME') +
|
||||||
'\\n");\n';
|
'\\n");\n';
|
||||||
// Run tests (unindented).
|
// Run tests (unindented).
|
||||||
code += Blockly.PHP.statementToCode(block, 'DO')
|
code += phpGenerator.statementToCode(block, 'DO')
|
||||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||||
// Send the report to the console (that's where errors will go anyway).
|
// Send the report to the console (that's where errors will go anyway).
|
||||||
code += 'print(' + functionName + '());\n';
|
code += 'print(' + functionName + '());\n';
|
||||||
@@ -60,12 +60,12 @@ Blockly.PHP['unittest_main'] = function(block) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
|
phpGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.PHP.provideFunction_(
|
var functionName = phpGenerator.provideFunction_(
|
||||||
'assertEquals',
|
'assertEquals',
|
||||||
['function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
['function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'($actual, $expected, $message) {',
|
'($actual, $expected, $message) {',
|
||||||
' global ' + resultsVar + ';',
|
' global ' + resultsVar + ';',
|
||||||
' // Asserts that a value equals another value.',
|
' // Asserts that a value equals another value.',
|
||||||
@@ -86,24 +86,24 @@ Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
|
|||||||
return functionName;
|
return functionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.PHP['unittest_assertequals'] = function(block) {
|
phpGenerator['unittest_assertequals'] = function(block) {
|
||||||
// Asserts that a value equals another value.
|
// Asserts that a value equals another value.
|
||||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
var message = phpGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.PHP.ORDER_NONE) || '';
|
phpGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
var actual = phpGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.PHP.ORDER_NONE) || 'null';
|
phpGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = Blockly.PHP.valueToCode(block, 'EXPECTED',
|
var expected = phpGenerator.valueToCode(block, 'EXPECTED',
|
||||||
Blockly.PHP.ORDER_NONE) || 'null';
|
phpGenerator.ORDER_NONE) || 'null';
|
||||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
return phpGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.PHP['unittest_assertvalue'] = function(block) {
|
phpGenerator['unittest_assertvalue'] = function(block) {
|
||||||
// Asserts that a value is true, false, or null.
|
// Asserts that a value is true, false, or null.
|
||||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
var message = phpGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.PHP.ORDER_NONE) || '';
|
phpGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
var actual = phpGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.PHP.ORDER_NONE) || 'null';
|
phpGenerator.ORDER_NONE) || 'null';
|
||||||
var expected = block.getFieldValue('EXPECTED');
|
var expected = block.getFieldValue('EXPECTED');
|
||||||
if (expected == 'TRUE') {
|
if (expected == 'TRUE') {
|
||||||
expected = 'true';
|
expected = 'true';
|
||||||
@@ -112,18 +112,18 @@ Blockly.PHP['unittest_assertvalue'] = function(block) {
|
|||||||
} else if (expected == 'NULL') {
|
} else if (expected == 'NULL') {
|
||||||
expected = 'null';
|
expected = 'null';
|
||||||
}
|
}
|
||||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
return phpGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.PHP['unittest_fail'] = function(block) {
|
phpGenerator['unittest_fail'] = function(block) {
|
||||||
// Always assert an error.
|
// Always assert an error.
|
||||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE'));
|
var message = phpGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||||
var functionName = Blockly.PHP.provideFunction_(
|
var functionName = phpGenerator.provideFunction_(
|
||||||
'unittest_fail',
|
'unittest_fail',
|
||||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
[ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'($message) {',
|
'($message) {',
|
||||||
' global ' + resultsVar + ';',
|
' global ' + resultsVar + ';',
|
||||||
' // Always assert an error.',
|
' // Always assert an error.',
|
||||||
@@ -135,20 +135,20 @@ Blockly.PHP['unittest_fail'] = function(block) {
|
|||||||
return functionName + '(' + message + ');\n';
|
return functionName + '(' + message + ');\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.PHP['unittest_adjustindex'] = function(block) {
|
phpGenerator['unittest_adjustindex'] = function(block) {
|
||||||
var index = Blockly.PHP.valueToCode(block, 'INDEX',
|
var index = phpGenerator.valueToCode(block, 'INDEX',
|
||||||
Blockly.PHP.ORDER_ADDITION) || '0';
|
phpGenerator.ORDER_ADDITION) || '0';
|
||||||
// Adjust index if using one-based indexing.
|
// Adjust index if using one-based indexing.
|
||||||
if (block.workspace.options.oneBasedIndex) {
|
if (block.workspace.options.oneBasedIndex) {
|
||||||
if (Blockly.isNumber(index)) {
|
if (Blockly.isNumber(index)) {
|
||||||
// If the index is a naked number, adjust it right now.
|
// 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 {
|
} else {
|
||||||
// If the index is dynamic, adjust it in code.
|
// If the index is dynamic, adjust it in code.
|
||||||
index = index + ' + 1';
|
index = index + ' + 1';
|
||||||
}
|
}
|
||||||
} else if (Blockly.isNumber(index)) {
|
} 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';
|
'use strict';
|
||||||
|
|
||||||
Blockly.Python['unittest_main'] = function(block) {
|
pythonGenerator['unittest_main'] = function(block) {
|
||||||
// Container for unit tests.
|
// Container for unit tests.
|
||||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Python.provideFunction_(
|
var functionName = pythonGenerator.provideFunction_(
|
||||||
'unittest_report',
|
'unittest_report',
|
||||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():',
|
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '():',
|
||||||
' # Create test report.',
|
' # Create test report.',
|
||||||
' report = []',
|
' report = []',
|
||||||
' summary = []',
|
' summary = []',
|
||||||
@@ -47,7 +47,7 @@ Blockly.Python['unittest_main'] = function(block) {
|
|||||||
block.getFieldValue('SUITE_NAME') +
|
block.getFieldValue('SUITE_NAME') +
|
||||||
'\')\n';
|
'\')\n';
|
||||||
// Run tests (unindented).
|
// Run tests (unindented).
|
||||||
code += Blockly.Python.statementToCode(block, 'DO')
|
code += pythonGenerator.statementToCode(block, 'DO')
|
||||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||||
// Print the report.
|
// Print the report.
|
||||||
code += 'print(' + functionName + '())\n';
|
code += 'print(' + functionName + '())\n';
|
||||||
@@ -56,12 +56,12 @@ Blockly.Python['unittest_main'] = function(block) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Python['unittest_main'].defineAssert_ = function() {
|
pythonGenerator['unittest_main'].defineAssert_ = function() {
|
||||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var functionName = Blockly.Python.provideFunction_(
|
var functionName = pythonGenerator.provideFunction_(
|
||||||
'assertEquals',
|
'assertEquals',
|
||||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ +
|
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(actual, expected, message):',
|
'(actual, expected, message):',
|
||||||
' # Asserts that a value equals another value.',
|
' # Asserts that a value equals another value.',
|
||||||
' if ' + resultsVar + ' == None:',
|
' if ' + resultsVar + ' == None:',
|
||||||
@@ -74,24 +74,24 @@ Blockly.Python['unittest_main'].defineAssert_ = function() {
|
|||||||
return functionName;
|
return functionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Python['unittest_assertequals'] = function(block) {
|
pythonGenerator['unittest_assertequals'] = function(block) {
|
||||||
// Asserts that a value equals another value.
|
// Asserts that a value equals another value.
|
||||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
var message = pythonGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Python.ORDER_NONE) || '';
|
pythonGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
var actual = pythonGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Python.ORDER_NONE) || 'None';
|
pythonGenerator.ORDER_NONE) || 'None';
|
||||||
var expected = Blockly.Python.valueToCode(block, 'EXPECTED',
|
var expected = pythonGenerator.valueToCode(block, 'EXPECTED',
|
||||||
Blockly.Python.ORDER_NONE) || 'None';
|
pythonGenerator.ORDER_NONE) || 'None';
|
||||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
return pythonGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Python['unittest_assertvalue'] = function(block) {
|
pythonGenerator['unittest_assertvalue'] = function(block) {
|
||||||
// Asserts that a value is true, false, or null.
|
// Asserts that a value is true, false, or null.
|
||||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
var message = pythonGenerator.valueToCode(block, 'MESSAGE',
|
||||||
Blockly.Python.ORDER_NONE) || '';
|
pythonGenerator.ORDER_NONE) || '';
|
||||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
var actual = pythonGenerator.valueToCode(block, 'ACTUAL',
|
||||||
Blockly.Python.ORDER_NONE) || 'None';
|
pythonGenerator.ORDER_NONE) || 'None';
|
||||||
var expected = block.getFieldValue('EXPECTED');
|
var expected = block.getFieldValue('EXPECTED');
|
||||||
if (expected == 'TRUE') {
|
if (expected == 'TRUE') {
|
||||||
expected = 'True';
|
expected = 'True';
|
||||||
@@ -100,18 +100,18 @@ Blockly.Python['unittest_assertvalue'] = function(block) {
|
|||||||
} else if (expected == 'NULL') {
|
} else if (expected == 'NULL') {
|
||||||
expected = 'None';
|
expected = 'None';
|
||||||
}
|
}
|
||||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
return pythonGenerator['unittest_main'].defineAssert_() +
|
||||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Python['unittest_fail'] = function(block) {
|
pythonGenerator['unittest_fail'] = function(block) {
|
||||||
// Always assert an error.
|
// Always assert an error.
|
||||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||||
var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE'));
|
var message = pythonGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||||
var functionName = Blockly.Python.provideFunction_(
|
var functionName = pythonGenerator.provideFunction_(
|
||||||
'fail',
|
'fail',
|
||||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(message):',
|
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message):',
|
||||||
' # Always assert an error.',
|
' # Always assert an error.',
|
||||||
' if ' + resultsVar + ' == None:',
|
' if ' + resultsVar + ' == None:',
|
||||||
' raise Exception("Orphaned assert equals: " + message)',
|
' raise Exception("Orphaned assert equals: " + message)',
|
||||||
@@ -119,20 +119,20 @@ Blockly.Python['unittest_fail'] = function(block) {
|
|||||||
return functionName + '(' + message + ')\n';
|
return functionName + '(' + message + ')\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Python['unittest_adjustindex'] = function(block) {
|
pythonGenerator['unittest_adjustindex'] = function(block) {
|
||||||
var index = Blockly.Python.valueToCode(block, 'INDEX',
|
var index = pythonGenerator.valueToCode(block, 'INDEX',
|
||||||
Blockly.Python.ORDER_ADDITIVE) || '0';
|
pythonGenerator.ORDER_ADDITIVE) || '0';
|
||||||
// Adjust index if using one-based indexing.
|
// Adjust index if using one-based indexing.
|
||||||
if (block.workspace.options.oneBasedIndex) {
|
if (block.workspace.options.oneBasedIndex) {
|
||||||
if (Blockly.isNumber(index)) {
|
if (Blockly.isNumber(index)) {
|
||||||
// If the index is a naked number, adjust it right now.
|
// 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 {
|
} else {
|
||||||
// If the index is dynamic, adjust it in code.
|
// If the index is dynamic, adjust it in code.
|
||||||
index = index + ' + 1';
|
index = index + ' + 1';
|
||||||
}
|
}
|
||||||
} else if (Blockly.isNumber(index)) {
|
} 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>}
|
* @type {Array<CodeGenerationTestSuite>}
|
||||||
*/
|
*/
|
||||||
const testSuites = [
|
const testSuites = [
|
||||||
{title: 'Dart', generator: Blockly.Dart,
|
{title: 'Dart', generator: dartGenerator,
|
||||||
testCases: [
|
testCases: [
|
||||||
{title: 'Empty string', expectedCode: '\'\'',
|
{title: 'Empty string', expectedCode: '\'\'',
|
||||||
createBlock: createBlockFn('')},
|
createBlock: createBlockFn('')},
|
||||||
{title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' + \n\' bark bark bark\' + \'\\n\' + \n\' bark bar bark bark\' + \'\\n\' + \n\'\'',
|
{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')},
|
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||||
]},
|
]},
|
||||||
{title: 'JavaScript', generator: Blockly.JavaScript,
|
{title: 'JavaScript', generator: javascriptGenerator,
|
||||||
testCases: [
|
testCases: [
|
||||||
{title: 'Empty string', expectedCode: '\'\'',
|
{title: 'Empty string', expectedCode: '\'\'',
|
||||||
createBlock: createBlockFn('')},
|
createBlock: createBlockFn('')},
|
||||||
{title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' +\n\' bark bark bark\' + \'\\n\' +\n\' bark bar bark bark\' + \'\\n\' +\n\'\'',
|
{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')},
|
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||||
]},
|
]},
|
||||||
{title: 'Lua', generator: Blockly.Lua,
|
{title: 'Lua', generator: luaGenerator,
|
||||||
testCases: [
|
testCases: [
|
||||||
{title: 'Empty string', expectedCode: '\'\'',
|
{title: 'Empty string', expectedCode: '\'\'',
|
||||||
createBlock: createBlockFn('')},
|
createBlock: createBlockFn('')},
|
||||||
{title: 'String with newline', expectedCode: '\'bark bark\' .. \'\\n\' ..\n\' bark bark bark\' .. \'\\n\' ..\n\' bark bar bark bark\' .. \'\\n\' ..\n\'\'',
|
{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')},
|
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||||
]},
|
]},
|
||||||
{title: 'PHP', generator: Blockly.PHP,
|
{title: 'PHP', generator: phpGenerator,
|
||||||
testCases: [
|
testCases: [
|
||||||
{title: 'Empty string', expectedCode: '\'\'',
|
{title: 'Empty string', expectedCode: '\'\'',
|
||||||
createBlock: createBlockFn('')},
|
createBlock: createBlockFn('')},
|
||||||
{title: 'String with newline', expectedCode: '\'bark bark\' . "\\n" .\n\' bark bark bark\' . "\\n" .\n\' bark bar bark bark\' . "\\n" .\n\'\'',
|
{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')},
|
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||||
]},
|
]},
|
||||||
{title: 'Python', generator: Blockly.Python,
|
{title: 'Python', generator: pythonGenerator,
|
||||||
testCases: [
|
testCases: [
|
||||||
{title: 'Empty string', expectedCode: '\'\'',
|
{title: 'Empty string', expectedCode: '\'\'',
|
||||||
createBlock: createBlockFn('')},
|
createBlock: createBlockFn('')},
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
goog.module('Blockly.test.generator');
|
goog.module('Blockly.test.generator');
|
||||||
|
|
||||||
goog.require('Blockly.Dart');
|
const {dartGenerator} = goog.require('Blockly.Dart');
|
||||||
goog.require('Blockly.JavaScript');
|
const {javaScriptGenerator} = goog.require('Blockly.JavaScript');
|
||||||
goog.require('Blockly.Lua');
|
const {luaGenerator} = goog.require('Blockly.Lua');
|
||||||
goog.require('Blockly.PHP');
|
const {phpGenerator} = goog.require('Blockly.PHP');
|
||||||
goog.require('Blockly.Python');
|
const {pythonGenerator} = goog.require('Blockly.Python');
|
||||||
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
|
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
|
||||||
|
|
||||||
|
|
||||||
@@ -83,11 +83,11 @@ suite('Generator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const testCase = [
|
const testCase = [
|
||||||
[Blockly.Dart, 'Dart'],
|
[dartGenerator, 'Dart'],
|
||||||
[Blockly.JavaScript, 'JavaScript'],
|
[javascriptGenerator, 'JavaScript'],
|
||||||
[Blockly.Lua, 'Lua'],
|
[luaGenerator, 'Lua'],
|
||||||
[Blockly.PHP, 'PHP'],
|
[phpGenerator, 'PHP'],
|
||||||
[Blockly.Python, 'Python']];
|
[pythonGenerator, 'Python']];
|
||||||
|
|
||||||
suite('Trivial', function() {
|
suite('Trivial', function() {
|
||||||
testCase.forEach(function(testCase) {
|
testCase.forEach(function(testCase) {
|
||||||
|
|||||||
@@ -49,17 +49,17 @@ suite('InsertionMarkers', function() {
|
|||||||
});
|
});
|
||||||
suite('Code Generation', function() {
|
suite('Code Generation', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
Blockly.JavaScript['stack_block'] = function(block) {
|
javascriptGenerator['stack_block'] = function(block) {
|
||||||
return 'stack[' + block.id + '];\n';
|
return 'stack[' + block.id + '];\n';
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['row_block'] = function(block) {
|
javascriptGenerator['row_block'] = function(block) {
|
||||||
const value = Blockly.JavaScript
|
const value = javascriptGenerator
|
||||||
.valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE);
|
.valueToCode(block, 'INPUT', javascriptGenerator.ORDER_NONE);
|
||||||
const code = 'row[' + block.id + '](' + value + ')';
|
const code = 'row[' + block.id + '](' + value + ')';
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, javascriptGenerator.ORDER_NONE];
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['statement_block'] = function(block) {
|
javascriptGenerator['statement_block'] = function(block) {
|
||||||
return 'statement[' + block.id + ']{\n' + Blockly.JavaScript
|
return 'statement[' + block.id + ']{\n' + javascriptGenerator
|
||||||
.statementToCode(block, 'STATEMENT') + '};\n';
|
.statementToCode(block, 'STATEMENT') + '};\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -67,14 +67,14 @@ suite('InsertionMarkers', function() {
|
|||||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||||
const block = this.workspace.getBlockById('insertion');
|
const block = this.workspace.getBlockById('insertion');
|
||||||
block.isInsertionMarker_ = true;
|
block.isInsertionMarker_ = true;
|
||||||
const code = Blockly.JavaScript.workspaceToCode(this.workspace);
|
const code = javascriptGenerator.workspaceToCode(this.workspace);
|
||||||
chai.assert.equal(code, expectedCode);
|
chai.assert.equal(code, expectedCode);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
teardown(function() {
|
teardown(function() {
|
||||||
delete Blockly.JavaScript['stack_block'];
|
delete javascriptGenerator['stack_block'];
|
||||||
delete Blockly.JavaScript['row_block'];
|
delete javascriptGenerator['row_block'];
|
||||||
delete Blockly.JavaScript['statement_block'];
|
delete javascriptGenerator['statement_block'];
|
||||||
});
|
});
|
||||||
test('Marker Surrounds', function() {
|
test('Marker Surrounds', function() {
|
||||||
const xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
const assert = require('chai').assert;
|
const assert = require('chai').assert;
|
||||||
const Blockly = require('../../dist/');
|
const Blockly = require('../../dist/');
|
||||||
|
const {javascriptGenerator} = require('../../dist/javascript');
|
||||||
|
|
||||||
const xmlText = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
|
const xmlText = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
|
||||||
' <block type="text_print" x="37" y="63">\n' +
|
' <block type="text_print" x="37" y="63">\n' +
|
||||||
@@ -48,7 +49,7 @@ suite('Test Node.js', function() {
|
|||||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||||
|
|
||||||
// Convert code
|
// Convert code
|
||||||
const code = Blockly.JavaScript.workspaceToCode(workspace);
|
const code = javascriptGenerator.workspaceToCode(workspace);
|
||||||
|
|
||||||
// Check output
|
// Check output
|
||||||
assert.equal('window.alert(\'Hello from Blockly!\');', code.trim(), 'equal');
|
assert.equal('window.alert(\'Hello from Blockly!\');', code.trim(), 'equal');
|
||||||
|
|||||||
@@ -184,8 +184,15 @@ function load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toCode(lang) {
|
function toCode(lang) {
|
||||||
|
var generator = ({
|
||||||
|
'JavaScript': javascriptGenerator,
|
||||||
|
'Python': pythonGenerator,
|
||||||
|
'PHP': phpGenerator,
|
||||||
|
'Lua': luaGenerator,
|
||||||
|
'Dart': dartGenerator,
|
||||||
|
})[lang];
|
||||||
var output = document.getElementById('importExport');
|
var output = document.getElementById('importExport');
|
||||||
output.value = Blockly[lang].workspaceToCode(workspace);
|
output.value = generator.workspaceToCode(workspace);
|
||||||
taChange();
|
taChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user