postcss-selector-parser icon indicating copy to clipboard operation
postcss-selector-parser copied to clipboard

className value not escaped when set using constructor

Open adamwathan opened this issue 6 years ago • 2 comments

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.

adamwathan avatar Feb 27 '19 20:02 adamwathan

Yep, looks like a bug in API, feel free to send a PR

alexander-akait avatar Mar 04 '19 08:03 alexander-akait

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.

adamwathan avatar Mar 04 '19 12:03 adamwathan