Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ You can use these plugin options to control some of Autoprefixer’s features.

- `grid: "autoplace"` will enable `-ms-` prefixes for Grid Layout including some
[limited autoplacement support](#grid-autoplacement-support-in-ie).
- `supports: false` will disable `@supports` parameters prefixing.
- `supports: false` will disable `@supports` parameters prefixing
and leave declarations inside `@supports` blocks untouched.
- `flexbox: false` will disable flexbox properties prefixing.
Or `flexbox: "no-2009"` will add prefixes only for final and IE
versions of specification.
Expand Down Expand Up @@ -553,7 +554,8 @@ Available options are:
- `remove` (boolean): should Autoprefixer [remove outdated] prefixes.
Default is `true`.
- `supports` (boolean): should Autoprefixer add prefixes for `@supports`
parameters. Default is `true`.
parameters and for declarations inside `@supports` blocks.
Default is `true`.
- `flexbox` (boolean|string): should Autoprefixer add prefixes for flexbox
properties. With `"no-2009"` value Autoprefixer will add prefixes only
for final and IE 10 versions of specification. Default is `true`.
Expand Down
23 changes: 23 additions & 0 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ function insideGrid(decl) {
})
}

function insideSupports(node) {
let parent = node.parent
while (parent) {
if (parent.type === 'atrule' && parent.name === 'supports') {
return true
}
parent = parent.parent
}
return false
}

class Processor {
constructor(prefixes) {
this.prefixes = prefixes
Expand Down Expand Up @@ -336,6 +347,14 @@ class Processor {
}
}

// With `supports: false` Autoprefixer leaves `@supports` blocks
// alone: declarations inside them are only applied by browsers
// which already pass the feature query, so prefixes there
// would never be used.
if (this.prefixes.options.supports === false && insideSupports(decl)) {
return undefined
}

let prefixer

if (decl.prop === 'transition' || decl.prop === 'transition-property') {
Expand Down Expand Up @@ -394,6 +413,10 @@ class Processor {
return css.walkDecls(decl => {
if (this.disabledValue(decl, result)) return

if (this.prefixes.options.supports === false && insideSupports(decl)) {
return
}

let unprefixed = this.prefixes.unprefixed(decl.prop)
let list = this.prefixes.values('add', unprefixed)
if (Array.isArray(list)) {
Expand Down
84 changes: 84 additions & 0 deletions test/autoprefixer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,90 @@ test('has option to disable @supports support', () => {
equal(result.css, css)
})

test('does not prefix declarations inside @supports with supports: false', () => {
let css =
'@supports (position: sticky) {\n' +
' .a {\n' +
' position: sticky;\n' +
' user-select: none;\n' +
' }\n' +
'}'
let instance = autoprefixer({
overrideBrowserslist: ['Safari 8', 'Chrome 30'],
supports: false
})
let result = postcss([instance]).process(css)
equal(result.css, css)
})

test('does not prefix declarations in nested @supports with supports: false', () => {
let css =
'@media screen {\n' +
' @supports (position: sticky) {\n' +
' .a {\n' +
' position: sticky;\n' +
' }\n' +
' }\n' +
'}'
let instance = autoprefixer({
overrideBrowserslist: ['Safari 8', 'Chrome 30'],
supports: false
})
let result = postcss([instance]).process(css)
equal(result.css, css)
})

test('prefixes declarations inside @supports by default', () => {
let css =
'@supports (position: sticky) {\n' +
' .a {\n' +
' position: sticky;\n' +
' }\n' +
'}'
let instance = autoprefixer({
overrideBrowserslist: ['Safari 8', 'Chrome 30']
})
let result = postcss([instance]).process(css)
equal(
result.css,
'@supports (position: sticky) {\n' +
' .a {\n' +
' position: -webkit-sticky;\n' +
' position: sticky;\n' +
' }\n' +
'}'
)
})

test('prefixes declarations outside @supports with supports: false', () => {
let css =
'.a {\n' +
' position: sticky;\n' +
'}\n' +
'@supports (position: sticky) {\n' +
' .b {\n' +
' position: sticky;\n' +
' }\n' +
'}'
let instance = autoprefixer({
overrideBrowserslist: ['Safari 8', 'Chrome 30'],
supports: false
})
let result = postcss([instance]).process(css)
equal(
result.css,
'.a {\n' +
' position: -webkit-sticky;\n' +
' position: sticky;\n' +
'}\n' +
'@supports (position: sticky) {\n' +
' .b {\n' +
' position: sticky;\n' +
' }\n' +
'}'
)
})

test('has disabled grid options by default', () => {
let ap = autoprefixer({ overrideBrowserslist: ['Edge 12', 'IE 10'] })
let input = read('grid')
Expand Down