How to force classes to be included in the renaming map?

147 views
Skip to first unread message

Tom Payne

unread,
Jan 4, 2012, 12:20:02 PM1/4/12
to closure-style...@googlegroups.com
Hi,

Is there a way to force classes to be *included* in the renaming map?

Effectively, I'm looking for the opposite of the
--excluded_classes_from_renaming option :-)

I'm using the full Closure suite (compiler, templates, library,
linter, stylesheets) and I use goog.dom.getElementByClass to my
elements, for example:
var dialogDiv = /** @type {Element} */
soy.renderAsFragment(myapp.templates.dialog);
var okDiv = goog.dom.getElementByClass(goog.getCssName('ok_button'),
dialogDiv);
The soy template, of course, uses {css ok_button} to ensure that
renames are handled.

The problem is that if a class's style turns out to be empty then
Closure Stylesheets does not include it in the generated CSS (which is
logical), or in the renaming map. The code still works, but class
names are which have empty styles end up not being renamed, and the
generated JavaScript ends up being larger than necessary.

Is there a way to force either all classes, or certain classes that I
specify, to be included in the renaming map? Or maybe I'm using the
wrong approach here...

Many thanks,
Tom

Ian Flanigan

unread,
Jan 4, 2012, 1:04:36 PM1/4/12
to closure-style...@googlegroups.com
Is the problem that the renaming map won't contain entries for:

.foo {}

Or is the problem that the .foo class doesn't appear in the CSS?

Ian

Tom Payne

unread,
Jan 5, 2012, 7:04:45 AM1/5/12
to closure-style...@googlegroups.com
Hi Ian,

The first one. The renaming map doesn't contain entries for .foo {}.

I believe it is correct that .foo should not appear in the CSS.

Cheers,
Tom

Ian Flanigan

unread,
Jan 5, 2012, 7:51:18 AM1/5/12
to closure-style...@googlegroups.com
Yes, as you can see here:


the renaming happens at the very end. It would be possible, though, to split the renaming into two passes: one that runs on the input to gather the class names and the other that runs near the end to actually do the renaming. If you get this to work, let me know.

Ian

Tom Payne

unread,
Jan 5, 2012, 11:01:17 AM1/5/12
to closure-style...@googlegroups.com
On 5 January 2012 13:51, Ian Flanigan <fl...@google.com> wrote:
> If you get this to work, let me know.

That's code for "send me a patch" right? :-)

My Java skills are pretty rusty, but I'll have a play.

Regards,
Tom

Tom Payne

unread,
Jan 6, 2012, 5:33:54 AM1/6/12
to closure-style...@googlegroups.com
OK, here are a couple of git-formatted patches that seem to work. You
can apply them with
git am *.patch

I've split it into two:

The first adds the infrastructure for the command line argument and an
appropriate member variable to JobDescription. This is (I hope)
relatively uncontroversial.

The second patches in the implementation. As the actual renaming map
is a private member variable of the CssClassRenaming class, and is
therefore not visible outside the class, this is done by adding the
requested classes to the renaming map at the end of
CssClassRenaming.runPass(). This might reasonably considered to be a
hack. But it works :-)

Regards,
Tom

0001-Add-included-classes-in-renaming-flag-skeleton.patch
0002-Add-included-classes-in-renaming-map-functionality.patch

Tom Payne

unread,
Jan 6, 2012, 5:37:51 PM1/6/12
to closure-style...@googlegroups.com
Attached is a very minor patch that cleans up
CssClassRenaming.runPass() a bit, specifically by moving a test that
should be outside the loop, outside the loop.

No functional change, but it has been bugging me all day :-)

Regards,
Tom

0003-Move-if-statement-outside-for-loop.patch
Reply all
Reply to author
Forward
0 new messages