Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check transition-property value list before warn #1385

Merged
merged 5 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 24 additions & 9 deletions lib/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,43 @@ class Transition {
return
}

let isPrefixed = false
let hasAssociatedProp = false

decl.parent.each(i => {
if (i.type !== 'decl') {
return undefined
}
if (i.prop.indexOf('transition-') !== 0) {
return undefined
}
let values = list.comma(i.value)
// check if current Rule's transition-property comma separated value list needs prefixes
if (i.prop === 'transition-property') {
values.forEach(value => {
let lookup = this.prefixes.add[value]
if (lookup && lookup.prefixes && lookup.prefixes.length > 0) {
isPrefixed = true
}
})
return undefined
}

if (list.comma(i.value).length > 1) {
decl.warn(
result,
'Replace transition-property to transition, ' +
'because Autoprefixer could not support ' +
'any cases of transition-property ' +
'and other transition-*'
)
// check if another transition-* prop in current Rule has comma separated value list
if (values.length > 1) {
ai marked this conversation as resolved.
Show resolved Hide resolved
hasAssociatedProp = true
}
return false
})

if (isPrefixed && hasAssociatedProp) {
decl.warn(
result,
'Replace transition-property to transition, ' +
'because Autoprefixer could not support ' +
'any cases of transition-property ' +
'and other transition-*'
)
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/autoprefixer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ it('prefixes transition', () => {
])
})

it('does not raise unnecessary warnings when prefixing transition', () => {
ai marked this conversation as resolved.
Show resolved Hide resolved
let input = read('transition-no-warning')
let output = read('transition-no-warning.out')
let result = postcss([prefixer('transition')]).process(input)

expect(result.css).toEqual(output)
expect(result.warnings()).toHaveLength(0)
})

it('works with broken transition', () => {
let input = 'a{transition:,,}'
let output = 'a{-webkit-transition:;-o-transition:;transition:}'
Expand Down
4 changes: 4 additions & 0 deletions test/cases/transition-no-warning.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.no-warn {
transition-property: color, opacity;
transition-duration: 1s, 2s;
}
8 changes: 8 additions & 0 deletions test/cases/transition-no-warning.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.no-warn {
-webkit-transition-property: color, opacity;
-o-transition-property: color, opacity;
transition-property: color, opacity;
-webkit-transition-duration: 1s, 2s;
-o-transition-duration: 1s, 2s;
transition-duration: 1s, 2s;
}