Hello,I've tried to make @interface / @implements work with externs, with no luck.I searched the internet in order to understand what was wrong, but I had no luck either.Here is a simple example:---- a.js ----/** @interface */function IFace() {};IFace.prototype.init = function() {};/** @constructor */function Useful(iface) {iface.init();}---- a.js -------- b.js ----/*** @constructor* @implements {IFace}*/function Impl() {}Impl.prototype.init = function() {alert("Hi");}function start() {var ifaceImpl = new Impl();var useful = new Useful(ifaceImpl);}window['start'] = start;---- b.js ----I use the following command to compile:java -jar compiler.jar --warning_level=VERBOSE --formatting PRETTY_PRINT --compilation_level ADVANCED_OPTIMIZATIONS --js b.js --externs a.js --js_output_file compiled.js
and I obtain the following result:---- compiled.js ----function a() {}window.start = function() {new Useful(new a)};---- compiled.js ----What am I doing wrong?Regards,Danilo--
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
The compiler doesn't look at the body of functions in externs so it doesn't know the connection. Perhaps you can compile the files together and use module to keep them as separately loadable units of Code?
The problem is that "init" is not unused.I mean, I know that within a.js "init" is unused (but I also tried to specify the type of parameters of the Useful constructor and it didn't help), but it's used in b.js and, anyway, it should not be considered as "unused" since that defeats the whole concept of @interface.Also exporting "init" defeats the concept of @interface.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Generally externs provide type checking and prevent renaming. Exports prevent code removal. But did you try changing the compiler option?
I thought that saying "class A @implements class B and class B is an @interface" would prevent the compiler to optimize out methods of A that are foreseen by B as an interface.In the case of externs I would expect it "doubly" since the compiler, not knowning which use of the methods of B implemented by A is done in an extern, should not remove any of them.My expectations were unfulfilled, but it's ok: I'll try and find some way to get around those problems.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.