chore(generators): Migrate generators to ES Modules (#7103)

* feat(j2ts): Add support for migrating renaming imports

  Convert
      const {foo: bar} = require(/*...*/);
  into
      import {foo as bar} from /*...*/;
              ^^^^^^^^^^

  Also fix a bug that caused relative paths to ESM in the same
  directory to be missing a leading "./".

* fix(build): Fix trivial error exports for generators

  The UMD wrapper was inadvertently exporting the contents of (e.g.)
  the Blockly.JavaScript closure module rather than the intended
  export of Blockly.JavaScript.all module - which went unnoticed
  because the latter just reexported the former - but we are
  about to convert the former to ESM.

* chore(generators): Migrate language generators to ESM

  Migrate the main language generators in generators/*.js to ESM.

  This was done by running js2ts on the files, renaming them back
  to .js, and commenting out "import type" statements, which are
  legal TS but not needed in JS (at least if you are not actually
  letting Closure Compiler do type checking, which we are not.)

* chore(generators): Migrate block generators to ESM

  Migrate generators/*/*.js (except all.js) to ESM.

  This was done by running js2ts on the files, renaming them back
  to .js, and removing now-spurious @suppress {extraRequire}
  directives.

* chores(generators): Migrate generator chunk entrypoints to ESM

  This was done by running js2ts on the files, renaming them back
  to .js, and manually fixing the export statements.

  An additional change to the chunk exports configuration in
  build_tasks.js was necessary in order for the UMD wrapper to
  find the new module object, which is given a different name
  than the old exports object.
This commit is contained in:
Christopher Allen
2023-05-19 23:09:37 +01:00
committed by GitHub
parent 3ce3d45116
commit 4d2201a427
57 changed files with 299 additions and 309 deletions

View File

@@ -9,19 +9,18 @@
* blocks. This is the entrypoint for php_compressed.js.
* @suppress {extraRequire}
*/
'use strict';
goog.module('Blockly.PHP.all');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.all');
const moduleExports = goog.require('Blockly.PHP');
goog.require('Blockly.PHP.colour');
goog.require('Blockly.PHP.lists');
goog.require('Blockly.PHP.logic');
goog.require('Blockly.PHP.loops');
goog.require('Blockly.PHP.math');
goog.require('Blockly.PHP.procedures');
goog.require('Blockly.PHP.texts');
goog.require('Blockly.PHP.variables');
goog.require('Blockly.PHP.variablesDynamic');
import './colour.js';
import './lists.js';
import './logic.js';
import './loops.js';
import './math.js';
import './procedures.js';
import './text.js';
import './variables.js';
import './variables_dynamic.js';
exports = moduleExports;
export * from '../php.js';

View File

@@ -7,11 +7,11 @@
/**
* @fileoverview Generating PHP for colour blocks.
*/
'use strict';
goog.module('Blockly.PHP.colour');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.colour');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import {phpGenerator as PHP} from '../php.js';
PHP['colour_picker'] = function(block) {

View File

@@ -18,13 +18,13 @@
* PHP (because only variables can be passed by reference).
* ex: end(true ? list1 : list2)
*/
'use strict';
goog.module('Blockly.PHP.lists');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.lists');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import * as stringUtils from '../../core/utils/string.js';
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['lists_create_empty'] = function(block) {
// Create an empty list.

View File

@@ -7,11 +7,11 @@
/**
* @fileoverview Generating PHP for logic blocks.
*/
'use strict';
goog.module('Blockly.PHP.logic');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.logic');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import {phpGenerator as PHP} from '../php.js';
PHP['controls_if'] = function(block) {

View File

@@ -7,13 +7,13 @@
/**
* @fileoverview Generating PHP for loop blocks.
*/
'use strict';
goog.module('Blockly.PHP.loops');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.loops');
const stringUtils = goog.require('Blockly.utils.string');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import * as stringUtils from '../../core/utils/string.js';
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['controls_repeat_ext'] = function(block) {

View File

@@ -7,12 +7,12 @@
/**
* @fileoverview Generating PHP for math blocks.
*/
'use strict';
goog.module('Blockly.PHP.math');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.math');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['math_number'] = function(block) {

View File

@@ -7,13 +7,13 @@
/**
* @fileoverview Generating PHP for procedure blocks.
*/
'use strict';
goog.module('Blockly.PHP.procedures');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.procedures');
const Variables = goog.require('Blockly.Variables');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import * as Variables from '../../core/variables.js';
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['procedures_defreturn'] = function(block) {

View File

@@ -7,12 +7,12 @@
/**
* @fileoverview Generating PHP for text blocks.
*/
'use strict';
goog.module('Blockly.PHP.texts');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.texts');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['text'] = function(block) {

View File

@@ -7,12 +7,12 @@
/**
* @fileoverview Generating PHP for variable blocks.
*/
'use strict';
goog.module('Blockly.PHP.variables');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.variables');
const {NameType} = goog.require('Blockly.Names');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
import {NameType} from '../../core/names.js';
import {phpGenerator as PHP} from '../php.js';
PHP['variables_get'] = function(block) {

View File

@@ -7,13 +7,12 @@
/**
* @fileoverview Generating PHP for dynamic variable blocks.
*/
'use strict';
goog.module('Blockly.PHP.variablesDynamic');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.PHP.variablesDynamic');
const {phpGenerator: PHP} = goog.require('Blockly.PHP');
/** @suppress {extraRequire} */
goog.require('Blockly.PHP.variables');
import {phpGenerator as PHP} from '../php.js';
import './variables.js';
// PHP is dynamically typed.