diff --git a/packages/eslint-plugin-next/src/rules/no-unwanted-polyfillio.ts b/packages/eslint-plugin-next/src/rules/no-unwanted-polyfillio.ts index b1ac5f2780d4..8732a730f381 100644 --- a/packages/eslint-plugin-next/src/rules/no-unwanted-polyfillio.ts +++ b/packages/eslint-plugin-next/src/rules/no-unwanted-polyfillio.ts @@ -3,6 +3,7 @@ import { defineRule } from '../utils/define-rule' // Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/master/packages/next-polyfill-nomodule/src/index.js const NEXT_POLYFILLED_FEATURES = [ 'Array.prototype.@@iterator', + 'Array.prototype.at', 'Array.prototype.copyWithin', 'Array.prototype.fill', 'Array.prototype.find', diff --git a/packages/next-polyfill-module/src/index.js b/packages/next-polyfill-module/src/index.js index bdb8268e9311..fa8f4c904ce5 100644 --- a/packages/next-polyfill-module/src/index.js +++ b/packages/next-polyfill-module/src/index.js @@ -118,3 +118,26 @@ if (!Object.fromEntries) { }, {}) } } + +/** + * Available in: + * Internet Explorer: never + * Edge: 92 + * Firefox: 90 + * Chrome: 92 + * Safari: 15.4 + * + * https://caniuse.com/mdn-javascript_builtins_array_at + */ +// Modified from TC39 at proposal polyfill: https://github.com/tc39/proposal-relative-indexing-method#polyfill +if (!Array.prototype.at) { + Array.prototype.at = function at(n) { + let i = Math.trunc(n) || 0 + + if (i < 0) i += this.length + + if (i < 0 || i >= this.length) return undefined + + return this[i] + } +} diff --git a/packages/next-polyfill-nomodule/src/index.js b/packages/next-polyfill-nomodule/src/index.js index 740973850bfb..67401e7b60c8 100644 --- a/packages/next-polyfill-nomodule/src/index.js +++ b/packages/next-polyfill-nomodule/src/index.js @@ -1,5 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ // Keep in sync with eslint no-unwanted-polyfillio rule: https://github.com/vercel/next.js/blob/master/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js +import 'core-js/features/array/at' import 'core-js/features/array/copy-within' import 'core-js/features/array/fill' import 'core-js/features/array/find'