diff --git a/lib/hacks/grid-end.js b/lib/hacks/grid-end.js index 8277f0c00..63f6a4225 100644 --- a/lib/hacks/grid-end.js +++ b/lib/hacks/grid-end.js @@ -1,4 +1,5 @@ let Declaration = require('../declaration') +let { isPureNumber } = require('../utils') class GridEnd extends Declaration { /** @@ -26,8 +27,12 @@ class GridEnd extends Declaration { startDecl = d }) if (startDecl) { - let value = Number(decl.value) - Number(startDecl.value) + '' - clonedDecl.value = value + if (isPureNumber(startDecl.value)) { + let value = Number(decl.value) - Number(startDecl.value) + '' + clonedDecl.value = value + } else { + return undefined + } } else { decl.warn( result, diff --git a/lib/hacks/grid-start.js b/lib/hacks/grid-start.js index 4628e88be..32cebc10d 100644 --- a/lib/hacks/grid-start.js +++ b/lib/hacks/grid-start.js @@ -6,7 +6,7 @@ class GridStart extends Declaration { */ check(decl) { let value = decl.value - return !value.includes('/') || value.includes('span') + return !value.includes('/') && !value.includes('span') } /** diff --git a/lib/utils.js b/lib/utils.js index f4e1a32cd..2309e8e2b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -76,3 +76,18 @@ module.exports.splitSelector = function (selector) { }) }) } + +/** + * Return true if a given value only contains numbers. + * @param {*} value + * @returns {boolean} + */ +module.exports.isPureNumber = function (value) { + if (typeof value === 'number') { + return true + } + if (typeof value === 'string') { + return /^[0-9]+$/.test(value) + } + return false +} diff --git a/test/cases/grid.css b/test/cases/grid.css index 68ec58175..f4818374d 100644 --- a/test/cases/grid.css +++ b/test/cases/grid.css @@ -202,3 +202,9 @@ grid-template-rows: 1fr; grid-template-columns: [content] 1fr; } + +/** https://github.com/postcss/autoprefixer/issues/1446 */ +.issue-1446 { + grid-row-start: span 3; + grid-row-end: 5; +} diff --git a/test/cases/grid.disabled.css b/test/cases/grid.disabled.css index e7071fbcf..dc3ba0488 100644 --- a/test/cases/grid.disabled.css +++ b/test/cases/grid.disabled.css @@ -208,3 +208,9 @@ grid-template-rows: 1fr; grid-template-columns: [content] 1fr; } + +/** https://github.com/postcss/autoprefixer/issues/1446 */ +.issue-1446 { + grid-row-start: span 3; + grid-row-end: 5; +} diff --git a/test/cases/grid.out.css b/test/cases/grid.out.css index 40d36dc95..03f230603 100644 --- a/test/cases/grid.out.css +++ b/test/cases/grid.out.css @@ -283,3 +283,9 @@ -ms-grid-row: 1; -ms-grid-column: 2; } + +/** https://github.com/postcss/autoprefixer/issues/1446 */ +.issue-1446 { + grid-row-start: span 3; + grid-row-end: 5; +} diff --git a/test/utils.test.js b/test/utils.test.js index e648f5505..58cbe23bd 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -111,4 +111,18 @@ test('splits complex selectors into an array', () => { ]) }) -test.run() +test('isPureNumber - number', () => { + equal(utils.isPureNumber(42), true) +}) + +test('isPureNumber - string', () => { + equal(utils.isPureNumber('42'), true) + equal(utils.isPureNumber('autoprefixer'), false) + equal(utils.isPureNumber(''), false) +}) + +test.run('isPureNumber - neither number nor string', () => { + equal(utils.isPureNumber({}), false) + equal(utils.isPureNumber(undefined), false) + equal(utils.isPureNumber(true), false) +})