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:
Christopher Allen
2022-06-30 19:53:32 +01:00
committed by GitHub
parent 9797943938
commit f947b3f4f6
76 changed files with 391 additions and 293 deletions

View File

@@ -11,7 +11,6 @@
'use strict';
goog.module('Blockly.Dart');
goog.module.declareLegacyNamespace();
const Variables = goog.require('Blockly.Variables');
const stringUtils = goog.require('Blockly.utils.string');
@@ -301,4 +300,4 @@ Dart.getAdjusted = function(block, atId, opt_delta, opt_negate,
return at;
};
exports = Dart;
exports.dartGenerator = Dart;

View File

@@ -13,6 +13,7 @@
goog.module('Blockly.Dart.all');
const moduleExports = goog.require('Blockly.Dart');
goog.require('Blockly.Dart.colour');
goog.require('Blockly.Dart.lists');
goog.require('Blockly.Dart.logic');
@@ -23,3 +24,4 @@ goog.require('Blockly.Dart.texts');
goog.require('Blockly.Dart.variables');
goog.require('Blockly.Dart.variablesDynamic');
exports = moduleExports;

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Dart.colour');
const Dart = goog.require('Blockly.Dart');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart.addReservedWords('Math');

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Dart.lists');
const Dart = goog.require('Blockly.Dart');
const {NameType} = goog.require('Blockly.Names');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart.addReservedWords('Math');

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Dart.logic');
const Dart = goog.require('Blockly.Dart');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart['controls_if'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Dart.loops');
const Dart = goog.require('Blockly.Dart');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Dart.math');
const Dart = goog.require('Blockly.Dart');
const {NameType} = goog.require('Blockly.Names');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart.addReservedWords('Math');

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Dart.procedures');
const Dart = goog.require('Blockly.Dart');
const {NameType} = goog.require('Blockly.Names');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart['procedures_defreturn'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Dart.texts');
const Dart = goog.require('Blockly.Dart');
const {NameType} = goog.require('Blockly.Names');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart.addReservedWords('Html,Math');

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Dart.variables');
const Dart = goog.require('Blockly.Dart');
const {NameType} = goog.require('Blockly.Names');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
Dart['variables_get'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Dart.variablesDynamic');
const Dart = goog.require('Blockly.Dart');
const {dartGenerator: Dart} = goog.require('Blockly.Dart');
/** @suppress {extraRequire} */
goog.require('Blockly.Dart.variables');

View File

@@ -11,7 +11,6 @@
'use strict';
goog.module('Blockly.JavaScript');
goog.module.declareLegacyNamespace();
const Variables = goog.require('Blockly.Variables');
const objectUtils = goog.require('Blockly.utils.object');
@@ -320,4 +319,4 @@ JavaScript.getAdjusted = function(
return at;
};
exports = JavaScript;
exports.javascriptGenerator = JavaScript;

View File

@@ -13,6 +13,7 @@
goog.module('Blockly.JavaScript.all');
const moduleExports = goog.require('Blockly.JavaScript');
goog.require('Blockly.JavaScript.colour');
goog.require('Blockly.JavaScript.lists');
goog.require('Blockly.JavaScript.logic');
@@ -23,3 +24,4 @@ goog.require('Blockly.JavaScript.texts');
goog.require('Blockly.JavaScript.variables');
goog.require('Blockly.JavaScript.variablesDynamic');
exports = moduleExports;

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.JavaScript.colour');
const JavaScript = goog.require('Blockly.JavaScript');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['colour_picker'] = function(block) {

View File

@@ -12,8 +12,8 @@
goog.module('Blockly.JavaScript.lists');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['lists_create_empty'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.JavaScript.logic');
const JavaScript = goog.require('Blockly.JavaScript');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['controls_if'] = function(block) {

View File

@@ -12,8 +12,8 @@
goog.module('Blockly.JavaScript.loops');
const stringUtils = goog.require('Blockly.utils.string');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['controls_repeat_ext'] = function(block) {

View File

@@ -12,8 +12,8 @@
goog.module('Blockly.JavaScript.math');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['math_number'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.JavaScript.procedures');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['procedures_defreturn'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.JavaScript.texts');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
/**

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.JavaScript.variables');
const JavaScript = goog.require('Blockly.JavaScript');
const {NameType} = goog.require('Blockly.Names');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
JavaScript['variables_get'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.JavaScript.variablesDynamic');
const JavaScript = goog.require('Blockly.JavaScript');
const {javascriptGenerator: JavaScript} = goog.require('Blockly.JavaScript');
/** @suppress {extraRequire} */
goog.require('Blockly.JavaScript.variables');

View File

@@ -12,7 +12,6 @@
'use strict';
goog.module('Blockly.Lua');
goog.module.declareLegacyNamespace();
const objectUtils = goog.require('Blockly.utils.object');
const stringUtils = goog.require('Blockly.utils.string');
@@ -204,4 +203,4 @@ Lua.scrub_ = function(block, code, opt_thisOnly) {
return commentCode + code + nextCode;
};
exports = Lua;
exports.luaGenerator = Lua;

View File

@@ -13,6 +13,7 @@
goog.module('Blockly.Lua.all');
const moduleExports = goog.require('Blockly.Lua');
goog.require('Blockly.Lua.colour');
goog.require('Blockly.Lua.lists');
goog.require('Blockly.Lua.logic');
@@ -23,3 +24,4 @@ goog.require('Blockly.Lua.texts');
goog.require('Blockly.Lua.variables');
goog.require('Blockly.Lua.variablesDynamic');
exports = moduleExports;

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Lua.colour');
const Lua = goog.require('Blockly.Lua');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['colour_picker'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Lua.lists');
const Lua = goog.require('Blockly.Lua');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['lists_create_empty'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Lua.logic');
const Lua = goog.require('Blockly.Lua');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['controls_if'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.Lua.loops');
const Lua = goog.require('Blockly.Lua');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
/**

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Lua.math');
const Lua = goog.require('Blockly.Lua');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['math_number'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Lua.procedures');
const Lua = goog.require('Blockly.Lua');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['procedures_defreturn'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Lua.texts');
const Lua = goog.require('Blockly.Lua');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['text'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Lua.variables');
const Lua = goog.require('Blockly.Lua');
const {NameType} = goog.require('Blockly.Names');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
Lua['variables_get'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Lua.variablesDynamic');
const Lua = goog.require('Blockly.Lua');
const {luaGenerator: Lua} = goog.require('Blockly.Lua');
/** @suppress {extraRequire} */
goog.require('Blockly.Lua.variables');

View File

@@ -11,7 +11,6 @@
'use strict';
goog.module('Blockly.PHP');
goog.module.declareLegacyNamespace();
const objectUtils = goog.require('Blockly.utils.object');
const stringUtils = goog.require('Blockly.utils.string');
@@ -301,4 +300,4 @@ PHP.getAdjusted = function(block, atId, opt_delta, opt_negate, opt_order) {
return at;
};
exports = PHP;
exports.phpGenerator = PHP;

View File

@@ -13,6 +13,7 @@
goog.module('Blockly.PHP.all');
const moduleExports = goog.require('Blockly.PHP');
goog.require('Blockly.PHP.colour');
goog.require('Blockly.PHP.lists');
goog.require('Blockly.PHP.logic');
@@ -23,3 +24,4 @@ goog.require('Blockly.PHP.texts');
goog.require('Blockly.PHP.variables');
goog.require('Blockly.PHP.variablesDynamic');
exports = moduleExports;

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.PHP.colour');
const PHP = goog.require('Blockly.PHP');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['colour_picker'] = function(block) {

View File

@@ -22,10 +22,9 @@
goog.module('Blockly.PHP.lists');
const PHP = goog.require('Blockly.PHP');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['lists_create_empty'] = function(block) {
// Create an empty list.

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.PHP.logic');
const PHP = goog.require('Blockly.PHP');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['controls_if'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.PHP.loops');
const PHP = goog.require('Blockly.PHP');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['controls_repeat_ext'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.PHP.math');
const PHP = goog.require('Blockly.PHP');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['math_number'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.PHP.procedures');
const PHP = goog.require('Blockly.PHP');
const Variables = goog.require('Blockly.Variables');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['procedures_defreturn'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.PHP.texts');
const PHP = goog.require('Blockly.PHP');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['text'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.PHP.variables');
const PHP = goog.require('Blockly.PHP');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
PHP['variables_get'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.PHP.variablesDynamic');
const PHP = goog.require('Blockly.PHP');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
/** @suppress {extraRequire} */
goog.require('Blockly.PHP.variables');

View File

@@ -11,7 +11,6 @@
'use strict';
goog.module('Blockly.Python');
goog.module.declareLegacyNamespace();
const stringUtils = goog.require('Blockly.utils.string');
const Variables = goog.require('Blockly.Variables');
@@ -331,4 +330,4 @@ Python.getAdjustedInt = function(block, atId, opt_delta, opt_negate) {
return at;
};
exports = Python;
exports.pythonGenerator = Python;

View File

@@ -13,6 +13,7 @@
goog.module('Blockly.Python.all');
const moduleExports = goog.require('Blockly.Python');
goog.require('Blockly.Python.colour');
goog.require('Blockly.Python.lists');
goog.require('Blockly.Python.logic');
@@ -23,3 +24,4 @@ goog.require('Blockly.Python.texts');
goog.require('Blockly.Python.variables');
goog.require('Blockly.Python.variablesDynamic');
exports = moduleExports;

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Python.colour');
const Python = goog.require('Blockly.Python');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['colour_picker'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.Python.lists');
const Python = goog.require('Blockly.Python');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['lists_create_empty'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Python.logic');
const Python = goog.require('Blockly.Python');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['controls_if'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.Python.loops');
const Python = goog.require('Blockly.Python');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['controls_repeat_ext'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Python.math');
const Python = goog.require('Blockly.Python');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
// If any new block imports any library, add that library name here.

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.Python.procedures');
const Python = goog.require('Blockly.Python');
const Variables = goog.require('Blockly.Variables');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['procedures_defreturn'] = function(block) {

View File

@@ -11,9 +11,9 @@
goog.module('Blockly.Python.texts');
const Python = goog.require('Blockly.Python');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['text'] = function(block) {

View File

@@ -11,8 +11,8 @@
goog.module('Blockly.Python.variables');
const Python = goog.require('Blockly.Python');
const {NameType} = goog.require('Blockly.Names');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
Python['variables_get'] = function(block) {

View File

@@ -11,7 +11,7 @@
goog.module('Blockly.Python.variablesDynamic');
const Python = goog.require('Blockly.Python');
const {pythonGenerator: Python} = goog.require('Blockly.Python');
/** @suppress {extraRequire} */
goog.require('Blockly.Python.variables');