Skip to content

Commit

Permalink
Rename first-child and last-child to first and last
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Jul 20, 2019
1 parent 893f5c0 commit 78554a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions __tests__/variantsAtRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test('it can generate focus-within variants', () => {

test('it can generate first-child variants', () => {
const input = `
@variants first-child {
@variants first {
.banana { color: yellow; }
.chocolate { color: brown; }
}
Expand All @@ -146,8 +146,8 @@ test('it can generate first-child variants', () => {
const output = `
.banana { color: yellow; }
.chocolate { color: brown; }
.first-child\\:banana:first-child { color: yellow; }
.first-child\\:chocolate:first-child { color: brown; }
.first\\:banana:first-child { color: yellow; }
.first\\:chocolate:first-child { color: brown; }
`

return run(input).then(result => {
Expand All @@ -158,7 +158,7 @@ test('it can generate first-child variants', () => {

test('it can generate last-child variants', () => {
const input = `
@variants last-child {
@variants last {
.banana { color: yellow; }
.chocolate { color: brown; }
}
Expand All @@ -167,8 +167,8 @@ test('it can generate last-child variants', () => {
const output = `
.banana { color: yellow; }
.chocolate { color: brown; }
.last-child\\:banana:last-child { color: yellow; }
.last-child\\:chocolate:last-child { color: brown; }
.last\\:banana:last-child { color: yellow; }
.last\\:chocolate:last-child { color: brown; }
`

return run(input).then(result => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/substituteVariantsAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import postcss from 'postcss'
import selectorParser from 'postcss-selector-parser'
import generateVariantFunction from '../util/generateVariantFunction'

function generatePseudoClassVariant(pseudoClass) {
function generatePseudoClassVariant(pseudoClass, selectorPrefix = pseudoClass) {
return generateVariantFunction(({ modifySelectors, separator }) => {
return modifySelectors(({ selector }) => {
return selectorParser(selectors => {
selectors.walkClasses(sel => {
sel.value = `${pseudoClass}${separator}${sel.value}`
sel.value = `${selectorPrefix}${separator}${sel.value}`
sel.parent.insertAfter(sel, selectorParser.pseudo({ value: `:${pseudoClass}` }))
})
}).processSync(selector)
Expand Down Expand Up @@ -38,8 +38,8 @@ const defaultVariantGenerators = {
active: generatePseudoClassVariant('active'),
visited: generatePseudoClassVariant('visited'),
disabled: generatePseudoClassVariant('disabled'),
'first-child': generatePseudoClassVariant('first-child'),
'last-child': generatePseudoClassVariant('last-child'),
first: generatePseudoClassVariant('first-child', 'first'),
last: generatePseudoClassVariant('last-child', 'last'),
}

export default function(config, { variantGenerators: pluginVariantGenerators }) {
Expand Down

0 comments on commit 78554a3

Please sign in to comment.