google / google/closure-compiler
Warn when @export is used in a CommonJS or ES6 Module
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I'm working with full compilation, es6_strict to es5_strict. I'm also using --output_wrapper to be sure what's exported and what's not.
First sample:
``` js
goog.module('foo.bar.Baz');
goog.module.declareLegacyNamespace();
/** @export */
exports.someMethod = () => {console.log('boo');};
```
This exports `foo.bar.Baz.someMethod` as expected. (Without the legacy namespace, it is `module$exports$foo$bar$Baz.someMethod`, which makes me think I'm doing something wrong.)
Now the same thing with classes:
``` js
goog.module('foo.bar.Baz');
goog.module.declareLegacyNamespace();
/** @export */
class Baz {
/** @export */
static someMethod() {console.log('boo');}
}
exports = Baz;
```
This exports `module$contents$foo$bar$Baz_Baz.someMethod`. I was expecting the same result as above, since both the class and the method are exported and it also uses the legacy namespace. (Without the legacy namespace, it is similar, `module$exports$foo$bar$Baz.someMethod`.)
---
To be honest I'm not sure if the problem is with JSCompiler or my expectations. Basically I need to compile a Closure library with modules, and export some methods with pretty names, to be used by external, non-Closure code.
As you can see above, there's one constellation that works (legacy namespace + @export + directly exported method without ES6 classes). I'd like to at least know if that is intended and something I can rely on in the future. It would be nice if it also worked with ES6 class static methods because I feel like these are very similar to directly exported methods. I'm confused why the legacy namespace affects the exported name, legacy namespace sounds like something that might go away one day which would also mean no more pretty exported names.
Contributor guide
Assessment
This issue has not been assessed yet.