Commit graph

113 commits

Author SHA1 Message Date
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
Adam Wathan
5e935c10f7 Remove dependency on cssesc
Makes it easier to guarantee that our escape behavior stays in line with postcss-selector-parser if their internal implementation ever changes.
2019-02-27 16:40:19 -05:00
Adam Wathan
2f79cab8fa Switch from css.escape to cssesc
This is what postcss-selector-parser uses internally, best to rely on the same escaping logic everywhere.
2019-02-27 13:53:28 -05:00
Adam Wathan
b8f1078229 Use postcss-selector-parser class escape handling 2019-02-27 13:43:26 -05:00
Adam Wathan
db7f1e6728 Merge branch 'master' into next 2019-02-22 10:05:31 -05:00
Adam Wathan
10aa36533f Pass postcss to plugins explicitly 2019-02-22 09:50:36 -05:00
Adam Wathan
4754d225af Remove need for without function 2019-02-14 07:47:32 -05:00
Adam Wathan
d95d28eec8 Fix code style 2019-02-13 14:25:37 -05:00
Adam Wathan
2342d72c5e Use existing parameter 2019-02-13 14:22:45 -05:00
Adam Wathan
8ff2b59096 Add first class support for extending the default theme 2019-02-13 13:07:41 -05:00
Adam Wathan
76c40e4394 Fix style 2019-02-07 15:13:17 -05:00
Adam Wathan
1d0b4cd31c Test plugins can add base styles with object syntax 2019-02-07 14:05:00 -05:00
Adam Wathan
04e1274e86 Rename mergeConfig to resolveConfig
Accept configs to resolve as an array to allow reuse when only resolving from a single config, update processTailwindFeatures to use resolveConfig even when no config is provided, update defaultTheme to self-reference colors.
2019-02-05 20:36:54 -05:00
Adam Wathan
40413690a2 Add support for lazy values in theme 2019-02-05 20:18:19 -05:00
Adam Wathan
4afb9e45e6 Test core plugins fall back to a default config 2019-02-05 10:58:56 -05:00
Adam Wathan
c84b188626 Fix code style 2019-02-05 10:54:35 -05:00
Adam Wathan
ed20e59ba1 Test that setting a plugin to false in corePlugins disables it 2019-02-05 10:41:33 -05:00
Adam Wathan
083ab97e12 Fix code style 2019-02-01 12:32:50 -05:00
Adam Wathan
ffdc2b01c5 Intelligently deep merge user's config 2019-02-01 12:32:50 -05:00
Adam Wathan
f10f1825ef Remove special "modules" merge behavior
Modules key no longer actually exists in the config so this is pointless.
2019-02-01 12:32:50 -05:00
Adam Wathan
326f35a72a Remove options key from config 2019-02-01 12:32:50 -05:00
Adam Wathan
e8d16fcdb5 Move separator to top level config option 2019-02-01 12:32:50 -05:00
Adam Wathan
1a46f6b47d Move important to top level option 2019-02-01 12:32:50 -05:00
Adam Wathan
664f923312 Move prefix option to top-level in config 2019-02-01 12:32:16 -05:00
Adam Wathan
ffae87148d Revert "Allow plugins to register new config variables" 2019-02-01 12:32:04 -05:00
Adam Wathan
5ea8bbe798 Allow plugins to register new config variables 2019-02-01 12:32:04 -05:00
Adam Wathan
057b4ea767 More dead code discovered and deleted 2019-01-14 15:43:12 -05:00
Adam Wathan
b948c25499 Delete possibly last remnants of dead code 2019-01-14 15:43:12 -05:00
Adam Wathan
fe1b30b2d2 Remove prefixTree, update relevant tests 2019-01-14 15:43:12 -05:00
Adam Wathan
ca524ef7c2 Remove more dead code 2019-01-14 15:43:12 -05:00
Adam Wathan
6352843cde Port zIndex module to default plugin 2019-01-14 15:43:12 -05:00
Adam Wathan
146b984617 Accept plugins as separate processPlugins arg 2019-01-14 15:43:12 -05:00
Adam Wathan
cc9c91a60a Delete unused variant modules 2019-01-14 15:39:51 -05:00
Adam Wathan
2b5358d92a Update prefixSelector for latest selector parser 2019-01-14 14:45:01 -05:00
Adam Wathan
e1d276468b Get tests passing with updated dependencies
Latest postcss-selector-parser tries to be more intelligent about handling escape sequences for you. This is awesome! But our original code was handling escaping ourselves, so this change gets the tests passing for now, with the intent to stop doing escaping ourselves in the near future and instead rely on postcss-selector-parser to handle it for us, since I'm positive their implementation is significantly more robust.
2019-01-14 14:45:01 -05:00
Adam Wathan
76691a563d Allow modules: [...variants] syntax to bulk apply variants 2018-11-01 21:33:42 -04:00
Adam Wathan
655963a100 Apply all first-class variants using modules: all 2018-11-01 20:30:48 -04:00
SpiltCoffee
38ac38cf99 Fixed linting error 2018-09-15 13:07:29 +10:00
SpiltCoffee
002a4ba90d Changed Variant Generation to apply per selector in a ruleset (fixes #530) 2018-09-15 11:38:58 +10:00
Adam Wathan
1a9b87f085 Fix style 2018-07-12 11:02:13 -04:00
Adam Wathan
80baf4aa17 Pass generated utilities around as array instead of root
When you do something like container.before(someRoot), PostCSS actually *mutates* someRoot, leaving it empty and moving its contents before the container. container.before(arrayOfNodes) on the other hand does no weird mutation.

This PR makes sure generatedUtilities is an array of nodes instead of a PostCSS container to avoid this unexpected mutation. It makes it a bit more work to walk those nodes if they need to be transformed, but I think it's worth the trade-off. Can always write a helper function around that if the boilerplate starts to feel repetitive.
2018-07-11 19:14:33 -04:00
Adam Wathan
cfe492220c Refactor duplication 2018-07-11 11:45:45 -04:00
Adam Wathan
f974b8df03 Add support for writing variant plugins with raw PostCSS API 2018-06-26 13:44:47 -04:00
Adam Wathan
64cda2f44b Refactor duplication to use generateVariantFunction 2018-06-26 13:44:47 -04:00
Adam Wathan
d77bc055ee Support for basic variant generator plugins
Allows you to write a plugin that registers a new variant but only
allows you to modify the selector (like what our built-in generators
do.)

Next steps are to support variants that wrap rules with at-rules
(like @supports for example), variants that can modify properties
(as opposed to just selectors), and to give variant plugin authors
control over how responsive variants interact with their own variants.
2018-06-26 13:44:47 -04:00
Adam Wathan
9eca69ad83 Refactor process plugins to return an object 2018-06-26 13:44:47 -04:00
Adam Wathan
8333d46cae Add variant prefix to last class in a selector, not the first 2018-06-20 12:21:14 -04:00
Adam Wathan
1de2a24eb3 Switch to more robust existing CSS escaping library 2018-06-04 09:14:38 -04:00
Adam Wathan
8e8f47c58d Respect user prefix by default when creating component classes 2018-03-07 09:37:01 -05:00
Adam Wathan
7d589dd542 Fix style + kill unused code 2018-03-07 09:37:01 -05:00