Skip to content

Commit

Permalink
refactor!: Remove remaining use of `goog.module.declareLegacyNamespac…
Browse files Browse the repository at this point in the history
…e`. (#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.
  • Loading branch information
cpcallen committed Jun 30, 2022
1 parent 9797943 commit f947b3f
Show file tree
Hide file tree
Showing 76 changed files with 391 additions and 293 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"browser": true
},
"globals": {
"Blockly": true,
"goog": true,
"exports": true
},
Expand Down
1 change: 0 additions & 1 deletion blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

goog.module('Blockly.libraryBlocks');
goog.module.declareLegacyNamespace();

const colour = goog.require('Blockly.libraryBlocks.colour');
const lists = goog.require('Blockly.libraryBlocks.lists');
Expand Down
1 change: 0 additions & 1 deletion core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @namespace Blockly
*/
goog.module('Blockly');
goog.module.declareLegacyNamespace();

const ContextMenu = goog.require('Blockly.ContextMenu');
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
Expand Down
3 changes: 1 addition & 2 deletions generators/dart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -301,4 +300,4 @@ Dart.getAdjusted = function(block, atId, opt_delta, opt_negate,
return at;
};

exports = Dart;
exports.dartGenerator = Dart;
2 changes: 2 additions & 0 deletions generators/dart/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -23,3 +24,4 @@ goog.require('Blockly.Dart.texts');
goog.require('Blockly.Dart.variables');
goog.require('Blockly.Dart.variablesDynamic');

exports = moduleExports;
2 changes: 1 addition & 1 deletion generators/dart/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion generators/dart/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/dart/variables_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
3 changes: 1 addition & 2 deletions generators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -320,4 +319,4 @@ JavaScript.getAdjusted = function(
return at;
};

exports = JavaScript;
exports.javascriptGenerator = JavaScript;
2 changes: 2 additions & 0 deletions generators/javascript/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -23,3 +24,4 @@ goog.require('Blockly.JavaScript.texts');
goog.require('Blockly.JavaScript.variables');
goog.require('Blockly.JavaScript.variablesDynamic');

exports = moduleExports;
2 changes: 1 addition & 1 deletion generators/javascript/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


/**
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/variables_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
3 changes: 1 addition & 2 deletions generators/lua.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -204,4 +203,4 @@ Lua.scrub_ = function(block, code, opt_thisOnly) {
return commentCode + code + nextCode;
};

exports = Lua;
exports.luaGenerator = Lua;
2 changes: 2 additions & 0 deletions generators/lua/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -23,3 +24,4 @@ goog.require('Blockly.Lua.texts');
goog.require('Blockly.Lua.variables');
goog.require('Blockly.Lua.variablesDynamic');

exports = moduleExports;
2 changes: 1 addition & 1 deletion generators/lua/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


/**
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion generators/lua/variables_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
3 changes: 1 addition & 2 deletions generators/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -301,4 +300,4 @@ PHP.getAdjusted = function(block, atId, opt_delta, opt_negate, opt_order) {
return at;
};

exports = PHP;
exports.phpGenerator = PHP;
2 changes: 2 additions & 0 deletions generators/php/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -23,3 +24,4 @@ goog.require('Blockly.PHP.texts');
goog.require('Blockly.PHP.variables');
goog.require('Blockly.PHP.variablesDynamic');

exports = moduleExports;

0 comments on commit f947b3f

Please sign in to comment.