A library written in CoffeeScript
A bunch of random observations.  I'd rethink the way you approach "classes".  I'd start with something like

classes = attr['class'] || []
classes = [classes] if typeof classes == 'string'


And then write or delete it back at the end.

Creating hashStartRe

hashStartRe = /^[.#]/
elemType = if hashStartRe.test elem then "div" else pieces.shift()


Will probably be faster than the current rewriting and calling elem.charAt(0).  It's definitely easier to read.  However, it causes problems with "pos".  (Solveable problems, but you do need to be careful.)

At this point, the big question is whether you want to allow multiple ids or ids that aren't in the front position.  If you restrict your attention to a#id.class1.class2 and don't process a.class1#id1#id2, you can simplify the for loop as well.

A final performance point, since regular expressions are so fast on modern browsers, you may want to consider using the regular expression /(.#)([^.#)+)/ to do your parsing.  But you'd need to sit down and do some proper analysis on what was faster.  My gut tells me it will be.