Skip to content

Convert to ES Modules #5904

@rachel-fenichel

Description

@rachel-fenichel

Closure compiler documentation:

The specific steps that we need to take, pulled from the closure documentation:
Migrating Closure modules with named exports
For Closure modules that use named exports we recommend migrating files in place over 3 changes.

  1. Edit the implementation file to be an ES module that calls goog.declareModuleId with the old Closure module name (i.e. the old argument to goog.module). This should allow other files to continue using goog.require on the Closure namespace. (Be sure to import Closure's goog.js file rather than use the global goog symbol!)
  2. Edit all ES module files that are using goog.require on the module namespace to instead use ES import.
  3. Remove the call to goog.declareModuleId in the migrated file once it is not being referenced by any goog.module or goog.provide files.

Reasons to migrate

  • (As I understand it) the Typescript compiler cannot pick up and use the correct types for imports in the form of const {Foo} = goog.require('Blockly.Foo').
  • Tsickle assumes that the input files are ES modules.
  • Tsickle relies on correct parsing by the typescript compiler, and chokes when the compiler chokes.
  • The closure compiler understands ES modules, so in theory this change can be done without involving the typescript compiler--meeting my goal of being able to compiler with the closure compiler up until we've fully debugged our typescript compilation flow.

Metadata

Metadata

Labels

internalExternal contributions not accepted

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions