[OpenLayers-Dev] OpenLayers without warnings using the Closure
Compiler in VERBOSE mode
Xavier Mamano (jorix)
xavier.mamano at gmail.com
Wed Jan 12 18:12:10 EST 2011
Hi developers,
I wondered why the Closure Compiler generates many warnings in OpenLayers?
A consequence of this I have been researching how to build OpenLayers in
VERBOSE mode without generating warnings.
For obvious reasons I limited myself to lite.cfg :-)
This post is not a proposal! My intention is only explain the path that I
followed.
The solutions:
• Using jsDoc comments.
• Using very pure javascript code.
• Small adjustments
Using jsDoc comments:
Without the statements "@constructor" Closure Compiler generates warnings
when using "new CLasName"
I like Natural Docs!, and did not want to spend time to manually change a
lot of comments.
So I considered doing a translator. Hard work does NaturalDocs2JsDoc.py,
that
I proposed in http://trac.osgeo.org/openlayers/ticket/3008 #3008 .
NaturalDocs2JsDoc.py translates Natural Docs into jsDoc.
But further adjustments are necessary:
• Indicate who is "this" in some functions, e.g.
OpenLayers.Util.onImageLoadError
(I used "Scope:")
• Indicate which parameters are optional, e.g. OpenLayers.Util.toFloat,
(I used "Optional Parameters:" and have also forced "options - {Object}"
as optional)
• Indicate repetitive parameters, e.g. OpenLayers.Util.getElement
(I used {type_name ...}).
Using very pure javascript code:
I have not found a way to tell the compiler what work does OpenLayers.Class
and OpenLayers.inherit. The compiler gives warnings that classes use methods
and functions undefined.
To solve this problem I used very pure javascript, similar to that proposed
by
Eric Lemoine in
http://osgeo-org.1803224.n2.nabble.com/OpenLayers-3-type-instantiation-performance-tc5641805.html
OpenLayers-3 type instantiation performance .
The code would be:
/** @constructor */
A = function(){...}; // constructor A
A.prototype = {...}; // prototype definition
/** @constructor
@extends A */
B = function(){...}; // constructor B
B.prototype = {...}; // prototype definition
OpenLayers.Util.applyDefaults(B, A); // Inherits from: A
This has worked well and adding
"initialize: function () {CLASS_NAME.apply (this, arguments);}" the code
works
in mixed mode (lite.cfg in pure javascript and the rest with Class)
Small adjustments:
• Closure provides a warning when using parseInt without the second
parameter
and said: "if you really want to parse octal or hex based on the leader,
then
pass "undefined" as the base. "
• Functions that use "arguments" but do not declare the parameters
(as OpenLayers.Util.getElement),
Clouse requires a definition of "@param" with name matching the name of
the parameter in the function.
• Other minor details ... mostly matching types.
So far I have not been able to eliminate all warnings, now there are 9 (plus
24
warnings: not defined as Control, Popup, Geometry used in Map.js and
BaseTypes/Bounds.js)
but is a big difference when compared with the most of 1500 that are
generated
with the original code using lite.cfg (at r11029)
I believe that in a few years will seem strange to work in javascript
without a
compiler as now seems strange to work without Firebug.
Regards,
Xavier Mamano
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/OpenLayers-without-warnings-using-the-Closure-Compiler-in-VERBOSE-mode-tp5916529p5916529.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
More information about the Dev
mailing list