Migrate to named exports
See original GitHub issueBackground
The JavaScript and TypeScript style guides specifically prohibit default exports for ES/TS Modules:
// Do not use default exports: export default class Foo { ... } // BAD! // Use named exports: export class Foo { ... } // Alternate style named exports: class Foo { ... } export {Foo};
For goog.module
modules, the JavaScript style guide does not specifically prohibit default exports (exports = MyClass;
), but it gives only examples of named exports. (It does give examples of goog.require
ing the default export, however.)
Proposal
Migrate all modules which have a default export to use only named exports, so
const MyClass = function(...) {...};
exports = MyClass
becomes
const MyClass = function(...) {...};
exports.MyClass = MyClass;
and the corresponding import is (simultaneously) changed from
const MyClass = goog.require('MyClass');
to
const {MyClass} = goog.require('MyClass');
Discussion
There’s nothing wrong with default exports in the short term, but this is something we will want to fix eventually as we continue the migration from goog.provide
-> goog.module
-> ES modules -> TypeScript. Issue #5073 records a number of cases where we will probably decide to fix this sooner rather than later. This bug is to ensure that “later” arrives eventually.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top GitHub Comments
I see. Good catch! I think we could still write a short temporary script to do this, but we would need something a tad more complex. Something that would save matches of module names that match the first step and use those in the second step. We’d need to save the
When the time comes, we can automate changing all this with the following commands (swapping out core for each directory we want to fix):