tailwindcss/src/lib
Adam Wathan 007231fbfc Require plugin authors to manually escape variants
Not 100% convinced this is a net positive change, but I regret not having done things this way at the beginning.

In 0.x, we pass the `separator` and `className` values already escaped, so `:` comes through as `\:` for example, and `w-1/2` comes through as `w-1\/2`.

At first this sounds fine, less work for the plugin author right? But CSS escaping rules are kind of complicated and you have to escape characters differently depending on whether or not they are at the start of an identifier.

For example, it's totally fine for a class to contain a zero (`0` ), but it can't _start_ with a zero. For a class to start with a zero, it needs to be escaped like this: `\30 `

This means that as a general rule, trying to escape the individual segments of a class separately is a bad idea — you should escape the class as a whole so only the necessary escaping is applied. We break this rule when we pre-escape the separator and className for plugin authors who use the `modifySelectors` function.

We already require users to manually escape class names when they are using `addUtilities` or `addComponents`, so to me it feels more consistent for things to work this way and it's how they should have worked from day one.

Basically this code:

```js
function({ addVariant }) {
  addVariant('first-child', ({ modifySelectors, separator }) => {
    modifySelectors(({ className }) => {
      return `.first-child${separator}${className}:first-child`
    })
  })
},
```

...would need to be re-written like this if I merge this change:

```js
function({ addVariant, e }) {
  addVariant('first-child', ({ modifySelectors, separator }) => {
    modifySelectors(({ className }) => {
      return `.${e(`first-child${separator}${className}`)}:first-child`
    })
  })
},
```

Although I think this is the right way for this to work, I hesitate because it's a breaking change that makes any variant plugins authored for 0.x incompatible with 1.x. It's an easy fix on the plugin author's part, but it's still annoying.

I'm leaning towards merging so I don't regret this even more later when the plugin ecosystem is a lot bigger. Anyone have any thoughts?
2019-02-28 10:17:09 -05:00
..
evaluateTailwindFunctions.js Revert "Allow plugins to register new config variables" 2019-02-01 12:32:04 -05:00
registerConfigAsDependency.js Push config file dependency message instead of replacing messages array 2017-11-07 09:17:52 -05:00
substituteClassApplyAtRules.js Move prefix option to top-level in config 2019-02-01 12:32:16 -05:00
substituteResponsiveAtRules.js Finish merge of master 2019-02-07 13:58:47 -05:00
substituteScreenAtRules.js Wrap Tailwind plugins in new plugin to only unwrap config once 2018-06-26 13:44:47 -04:00
substituteTailwindAtRules.js Convert preflight to plugin 2019-02-07 15:19:54 -05:00
substituteVariantsAtRules.js Require plugin authors to manually escape variants 2019-02-28 10:17:09 -05:00