http://closuretools.blogspot.com/2011/01/property-by-any-other-name-part-3.html
"Using Type Analysis for Better Renaming"
Using my imagination I kind of hoped that it would, as the compiler
doesn't rename strings... Now, the object names aren't strings per se,
but I told the compiler that the keys in this object are strings
(static).
Then again, it's question where this is an internal or external
reference, and I guess that makes more sense, even though I was hoping
that the type annotation would accomplish the same thing here.
But the question remains then, how do I best handle "dynamic data"
then?
What I'm dealing with here is a JSON response, coming of the server.
I'd like to refrain from having to quote and wrap access in brackets.
like "this["SomeProperty"]" because authoring the scripts, that's
quickly going to become somewhat of a pain (I think it's a bit too
verbose).
I've been contemplating just, not compiling these scripts to steer
away from the problem entirely but I was really hoping that it would
be a nice in between, where I could leverage some of the type system
imposed by the closure compiler without sacrificing the dynamic
aspect, kind a like an opt-in/opt-out situation.
Like this, dude /** @param {data} data */ dynamic data object, don't
touch, you don't understand what this is and you'll break my code if
you start renaming things.
The compiler could do something like this:
var a = data.reallyLongAndAnnoyingDataSlot...
// now "a" can be used as a synonym if the property is used in a lot
of places
That imposes some restrictions on what a data object can be (read-only
JSON in this case), and how you may use it, but I really like it in
principle. Now I understand that there's nothing like this in the
compiler today, as I'm asking for something very specific to tailor to
my own needs but how would you handle these situation today? Surely
the quote and brackets approach can't be all there is...
One last thing, is "Super Advanced Mode" stable? or might I end up
with a result that's broken because these feature is incomplete in
some way?
--
j:pn
\\no comment
FWIW, I've grown to like this option - it enforces a nice place for the
JSON API to be defined and documented between the back and fontends.
I only wish that third party APIs (especially Google ones) would expose
more externs for their json structures / javascript APIs. I'm certain
they exist already, but they're not separated and made publicly
available.
Tim