Skip to content

Commit 45753a6

Browse files
author
Peter Bengtsson
authored
Remove polyfill for Array.prototype.at (#45513)
1 parent 333b76e commit 45753a6

File tree

1 file changed

+0
-36
lines changed

1 file changed

+0
-36
lines changed

src/content-render/unified/wrap-procedural-images.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
import { visitParents } from 'unist-util-visit-parents'
22

3-
// This is the first file that uses Array.prototype.at, so we polyfill it here.
4-
// It first appeared in Node 16.6 which is quite old now. But we have this
5-
// code because at least two staff contributors were caught by this as
6-
// they had old versions of Node.
7-
// Node 16 has ends getting maintance fixes on 2023-09-11. By then
8-
// we can't justify this hack anymore. But for now, it minimizes the
9-
// friction for any contributor (staff or open source) that might not
10-
// have made the upgrade yet.
11-
if (!Array.prototype.at) {
12-
console.warn('POLYFILLING Array.prototype.at.')
13-
console.warn('Please consider upgrading your version of Node.')
14-
// eslint-disable-next-line no-extend-native
15-
Object.defineProperty(Array.prototype, 'at', {
16-
value: function (index) {
17-
// Convert the index to a positive integer
18-
const length = this.length >>> 0
19-
let relativeIndex = index >> 0
20-
21-
// Handle negative indices
22-
if (relativeIndex < 0) {
23-
relativeIndex += length
24-
}
25-
26-
// Check if the index is within the valid range
27-
if (relativeIndex >= 0 && relativeIndex < length) {
28-
return this[relativeIndex]
29-
}
30-
31-
// Return undefined if the index is out of range
32-
return undefined
33-
},
34-
configurable: true,
35-
writable: true,
36-
})
37-
}
38-
393
/**
404
* Where it can mutate the AST to swap from:
415
*

0 commit comments

Comments
 (0)