fb55/CSSwhat — pull request #6 by moos (2014-10-01 09:06:20+00:00)
Title: Return normalized selector strings

Hi -- I have a use case (using cheerio) where I need to know *which* subselector A or B in [a,b,c] = $('A,B') the set of matched elements [a,b,c] matches. Something akin to jQuery('A,B').selector property (but matched to each element a,b,c, ... not the whole set).

Functions like CSSselect.is() or Sizzle.matchesSelector() could rematch an element to a query, but not to a subselector. Hence this work.

All the tests pass as before :) And I've added assertions for the returned selector strings for all tests. The returned selectors should match the input selector in most cases by splitting the input on the comma. For some tests that have comma inside attributes I've added overrides.

Ultimately I like to be able to say, $('A,B') and templatize the result with, e.g., "Title {{matched by A}} -- Company {{matched by B}}". For complex and overlapping A & B, this is just not trivial without knowing which selector an element was matched to.

Please review and comment. See the readme for an example usage. This is completely backward compatible. There is a related change to CSSSelect which I will submit if this is accepted.