|
1 | 1 | import { visitParents } from 'unist-util-visit-parents'
|
2 | 2 |
|
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 |
| - |
39 | 3 | /**
|
40 | 4 | * Where it can mutate the AST to swap from:
|
41 | 5 | *
|
|
0 commit comments