-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Background
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.requireing the default export, however.)
Proposal
Migrate all modules which have a default export to use only named exports, so
const MyClass = function(...) {...};
exports = MyClassbecomes
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.