google / google/closure-compiler
WHITESPACE_ONLY fails at runtime with goog.modules that export undefined typedefs
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I've got a typedef that I define as a module and export so I can use it in several places:
``` javascript
goog.module("aaa.bbb.DescribedError");
/**
* Typedef for standardised error description
*
* @typedef {
* !{
* isProgramError: (boolean),
* message: (!string),
* internal: (*)
* }
* }
*/
let DescribedError;
exports = DescribedError;
```
I don't want it in externs, because I don't need its naming to be preserved at runtime.
In WHITESPACE_ONLY, "Cannot read property '**$179591873$4$**' of undefined" at:
```
getOwnHashObject (vendor.dist.min.js:51953)
seal (vendor.dist.min.js:51974)
goog.loadModule (base.js:1067)
(anonymous function) (DescribedError.js:1)
```
because base.js is trying to do this when exports is `undefined`:
``` javascript
if (goog.moduleLoaderState_.declareLegacyNamespace) {
goog.constructNamespace_(moduleName, exports);
} else if (goog.SEAL_MODULE_EXPORTS && Object.seal) {
Object.seal(exports);
}
goog.loadedModules_[moduleName] = exports;
```
Is this a bug, or am I doing something nonsensical? Presumably there are other meaningful cases of goog.modules not exporting anything.
To workaround/fix:
``` javascript
let DescribedError = {};
```
(doesn't cause any warnings)
Contributor guide
Assessment
This issue has not been assessed yet.