rsnext/test/lib/flat-map-polyfill.js
JJ Kasper 01b7c576b4 Breakup CSS test suite (#9715)
* Breakup CSS test suite

* De-dupe next.config.js for css-fixtures
2019-12-11 18:39:09 -05:00

37 lines
959 B
JavaScript

if (!Array.prototype.flat) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, 'flat', {
configurable: true,
value: function flat() {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0])
return depth
? Array.prototype.reduce.call(
this,
function(acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1))
} else {
acc.push(cur)
}
return acc
},
[]
)
: Array.prototype.slice.call(this)
},
writable: true,
})
}
if (!Array.prototype.flatMap) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, 'flatMap', {
configurable: true,
value: function flatMap() {
return Array.prototype.map.apply(this, arguments).flat()
},
writable: true,
})
}