Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to ES Modules #5904

Closed
Tracked by #5857
rachel-fenichel opened this issue Jan 29, 2022 · 4 comments
Closed
Tracked by #5857

Convert to ES Modules #5904

rachel-fenichel opened this issue Jan 29, 2022 · 4 comments
Assignees
Labels
internal External contributions not accepted

Comments

@rachel-fenichel
Copy link
Collaborator

rachel-fenichel commented Jan 29, 2022

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.
@rachel-fenichel rachel-fenichel changed the title Convert goog.require to standard import syntax. Convert to es modules Jan 29, 2022
@rachel-fenichel rachel-fenichel changed the title Convert to es modules Convert to es6 modules Jan 29, 2022
@cpcallen cpcallen changed the title Convert to es6 modules Convert to ES Modules Jan 31, 2022
@cpcallen
Copy link
Contributor

cpcallen commented Jan 31, 2022

Title tweaked: although they were introduced in ES6, they are more widely referred to simply as "ES modules" rather than "ES6 modules". (Various useful features like dynamic import() have also been added more recently.)

@cpcallen
Copy link
Contributor

  1. (Be sure to import Closure's goog.js file rather than use the global goog symbol!)

Have you verified that this is necessary?

@rachel-fenichel
Copy link
Collaborator Author

We may be able to skip directly to TypeScript, in which case we can close this entirely. @gonfunko is currently investigating this.

@cpcallen
Copy link
Contributor

This was done (for core/) as part of the TypeScript conversion. Will track conversion of blocks/ and generators/ along with their conversion to TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal External contributions not accepted
Projects
None yet
Development

No branches or pull requests

3 participants