mirror of
https://github.com/hanzoai/autoprefixer.git
synced 2026-09-24 16:55:58 +00:00
Fix gradient parser
This commit is contained in:
+12
-2
@@ -55,6 +55,10 @@ class Gradient extends Value {
|
||||
continue
|
||||
}
|
||||
|
||||
if (param.length === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
let color = parser.stringify(param[0])
|
||||
if (param[1] && param[1].type === 'word') {
|
||||
pos = param[1].value
|
||||
@@ -75,7 +79,7 @@ class Gradient extends Value {
|
||||
|
||||
let div = param[param.length - 1]
|
||||
params[i] = [{ type: 'word', value: stop }]
|
||||
if (div.type === 'div' && div.value === ',') {
|
||||
if (div && div.type === 'div' && div.value === ',') {
|
||||
item = params[i].push(div)
|
||||
}
|
||||
result.push(item)
|
||||
@@ -184,6 +188,9 @@ class Gradient extends Value {
|
||||
* Replace old direction to new
|
||||
*/
|
||||
newDirection(params) {
|
||||
if (!params[0]) {
|
||||
return params
|
||||
}
|
||||
if (params[0].value === 'to') {
|
||||
return params
|
||||
}
|
||||
@@ -297,7 +304,7 @@ class Gradient extends Value {
|
||||
oldDirection(params) {
|
||||
let div = this.cloneDiv(params[0])
|
||||
|
||||
if (params[0][0].value !== 'to') {
|
||||
if (!params[0][0] || params[0][0].value !== 'to') {
|
||||
return params.unshift([
|
||||
{ type: 'word', value: Gradient.oldDirections.bottom },
|
||||
div
|
||||
@@ -328,6 +335,9 @@ class Gradient extends Value {
|
||||
if (this.name !== 'linear-gradient') {
|
||||
return false
|
||||
}
|
||||
if (nodes.length === 0) {
|
||||
return false
|
||||
}
|
||||
if (nodes[0] && nodes[0].value.includes('deg')) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -905,6 +905,24 @@ test('skips old webkit gradient for CSS variables', () => {
|
||||
equal(result.css.includes('-webkit-linear-gradient('), true)
|
||||
})
|
||||
|
||||
test('does not throw on empty or malformed gradient arguments', () => {
|
||||
let inputs = [
|
||||
'a { background-image: linear-gradient() }',
|
||||
'a { background-image: radial-gradient() }',
|
||||
'a { background-image: repeating-linear-gradient() }',
|
||||
'a { background-image: repeating-radial-gradient() }',
|
||||
'a { background-image: linear-gradient(red,) }',
|
||||
'a { background-image: linear-gradient(,red) }',
|
||||
'a { background-image: linear-gradient(red,,blue) }',
|
||||
'a { background-image: linear-gradient(to right, red,) }'
|
||||
]
|
||||
for (let input of inputs) {
|
||||
// Would throw an uncaught TypeError before the empty-argument guards
|
||||
let result = postcss([gradienter]).process(input, { from: undefined })
|
||||
type(result.css, 'string')
|
||||
}
|
||||
})
|
||||
|
||||
test('warns on old flexbox display', () => {
|
||||
let result = postcss([flexboxer]).process('a{ display: box; }')
|
||||
equal(result.css, 'a{ display: box; }')
|
||||
|
||||
Reference in New Issue
Block a user