postcss-selector-parser
postcss-selector-parser copied to clipboard
className value not escaped when set using constructor
Not sure if this is by design or not but I expected after #133 that class names would be escaped by default when creating a new className node.
const classNameA = parser.className({ value: 'hover:bg-blue' })
classNameA.toString()
// => '.hover:bg-blue'
const classNameB = parser.className()
classNameB.value = 'hover:bg-blue'
classNameB.toString()
// => '.hover\\:bg-blue'
Maybe @chriseppstein would know if this is intended or not? Seems weird to me to have to set the value through mutation in order to get the escaping behavior.
Yep, looks like a bug in API, feel free to send a PR
The part I'm not sure about is that it seems very deliberate, you can see here that the escaping code is very intentionally only run if you are setting the value outside of the constructor:
https://github.com/postcss/postcss-selector-parser/blob/master/src/selectors/className.js#L14
So would be nice to hear from @chriseppstein to better understand why it works this way.