Skip to content
Open
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
30 changes: 25 additions & 5 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const OLD_RADIAL = /(^|[^-])radial-gradient\(\s*\d+(\w*|%)\s+\d+(\w*|%)\s*,/i
const IGNORE_NEXT = /(!\s*)?autoprefixer:\s*ignore\s+next(?!\s+warning)/i
const GRID_REGEX = /(!\s*)?autoprefixer\s*grid:\s*(on|off|(no-)?autoplace)/i

function isGridTemplate(i) {
return i.prop === 'grid-template' || i.prop === 'grid-template-areas'
}

const SIZES = [
'width',
'height',
Expand All @@ -25,9 +29,22 @@ const SIZES = [
]

function hasGridTemplate(decl) {
return decl.parent.some(
i => i.prop === 'grid-template' || i.prop === 'grid-template-areas'
)
return decl.parent.some(isGridTemplate)
}

function hasGridTemplateInMedia(decl) {
let found = false
decl.parent.root().walkAtRules('media', media => {
media.walkRules(rule => {
if (rule.selector === decl.parent.selector && rule.some(isGridTemplate)) {
found = true
return false
}
return undefined
})
return found ? false : undefined
})
return found
}

function hasRowsAndColumns(decl) {
Expand Down Expand Up @@ -201,10 +218,12 @@ class Processor {
return undefined
} else if (decl.prop === 'grid-gap') {
let status = this.gridStatus(decl, result)
let hasTemplate = hasGridTemplate(decl)
if (
status === 'autoplace' &&
!hasRowsAndColumns(decl) &&
!hasGridTemplate(decl)
!hasTemplate &&
!hasGridTemplateInMedia(decl)
) {
warn(
result,
Expand All @@ -216,7 +235,8 @@ class Processor {
)
} else if (
(status === true || status === 'no-autoplace') &&
!hasGridTemplate(decl)
!hasTemplate &&
!hasGridTemplateInMedia(decl)
) {
warn(
result,
Expand Down
28 changes: 28 additions & 0 deletions test/autoprefixer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,34 @@ test('supports grid autoplacement', () => {
)
})

test('does not warn about grid-gap with templates in media queries', () => {
let input = `.grid {
display: grid;
grid-gap: 30px;
}
@media (min-width: 601px) {
.grid {
grid-template: "a b" auto / 1fr 1fr;
}
}
@media (max-width: 600px) {
.grid {
grid-template: "a" auto "b" auto / 1fr;
}
}
.a { grid-area: a; }
.b { grid-area: b; }`

for (let grid of [true, 'autoplace']) {
let instance = autoprefixer({
grid,
overrideBrowserslist: ['ie 11']
})
let result = postcss([instance]).process(input)
equal(result.warnings().length, 0)
}
})

test('shows Grid warnings only for IE', () => {
let input = 'a { grid-template-rows: repeat(auto-fit, 1px) }'
let instance = autoprefixer({
Expand Down