Closing the compiler throws renaming warning with names
The following code example generates a compiler warning for advanced optimization: JSC_UNSAFE_NAMESPACE: incomplete alias generated for NS namespace. If I remove @ enum's comment it gives no warning.
var NS = {};
/**
* @enum {string}
*/
NS.type = {
FOO : 'bar'
};
NS.foobar = function(){ alert(NS.type.FOO); };
window['NS'] = NS;
window['NS']['foobar'] = NS.foobar;
Export only works function, not namespace:
window['NS_foobar'] = NS.foobar;
What am I doing wrong? Is there a way to get around this? I'd rather not include the Closure library if possible.
+2
source to share
1 answer
The compiler expects to collapse the enum value into separate variables:
NS.type.FOO becomes NS $ type $ FOO. The "NS" that you exported will not contain what was expected.
I suspect you want something like this:
window['NS'] = {}; // an external namespace object.
window['NS']['foobar'] = NS.foobar; // add 'foobar' to the external namespace.
+2
source to share