Skip to content

Commit 78554a3

Browse files
committed
Rename first-child and last-child to first and last
1 parent 893f5c0 commit 78554a3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test('it can generate focus-within variants', () => {
137137

138138
test('it can generate first-child variants', () => {
139139
const input = `
140-
@variants first-child {
140+
@variants first {
141141
.banana { color: yellow; }
142142
.chocolate { color: brown; }
143143
}
@@ -146,8 +146,8 @@ test('it can generate first-child variants', () => {
146146
const output = `
147147
.banana { color: yellow; }
148148
.chocolate { color: brown; }
149-
.first-child\\:banana:first-child { color: yellow; }
150-
.first-child\\:chocolate:first-child { color: brown; }
149+
.first\\:banana:first-child { color: yellow; }
150+
.first\\:chocolate:first-child { color: brown; }
151151
`
152152

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

159159
test('it can generate last-child variants', () => {
160160
const input = `
161-
@variants last-child {
161+
@variants last {
162162
.banana { color: yellow; }
163163
.chocolate { color: brown; }
164164
}
@@ -167,8 +167,8 @@ test('it can generate last-child variants', () => {
167167
const output = `
168168
.banana { color: yellow; }
169169
.chocolate { color: brown; }
170-
.last-child\\:banana:last-child { color: yellow; }
171-
.last-child\\:chocolate:last-child { color: brown; }
170+
.last\\:banana:last-child { color: yellow; }
171+
.last\\:chocolate:last-child { color: brown; }
172172
`
173173

174174
return run(input).then(result => {

src/lib/substituteVariantsAtRules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import postcss from 'postcss'
33
import selectorParser from 'postcss-selector-parser'
44
import generateVariantFunction from '../util/generateVariantFunction'
55

6-
function generatePseudoClassVariant(pseudoClass) {
6+
function generatePseudoClassVariant(pseudoClass, selectorPrefix = pseudoClass) {
77
return generateVariantFunction(({ modifySelectors, separator }) => {
88
return modifySelectors(({ selector }) => {
99
return selectorParser(selectors => {
1010
selectors.walkClasses(sel => {
11-
sel.value = `${pseudoClass}${separator}${sel.value}`
11+
sel.value = `${selectorPrefix}${separator}${sel.value}`
1212
sel.parent.insertAfter(sel, selectorParser.pseudo({ value: `:${pseudoClass}` }))
1313
})
1414
}).processSync(selector)
@@ -38,8 +38,8 @@ const defaultVariantGenerators = {
3838
active: generatePseudoClassVariant('active'),
3939
visited: generatePseudoClassVariant('visited'),
4040
disabled: generatePseudoClassVariant('disabled'),
41-
'first-child': generatePseudoClassVariant('first-child'),
42-
'last-child': generatePseudoClassVariant('last-child'),
41+
first: generatePseudoClassVariant('first-child', 'first'),
42+
last: generatePseudoClassVariant('last-child', 'last'),
4343
}
4444

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

0 commit comments

Comments
 (0)