diff --git a/scripts/build/shims/at.js b/scripts/build/shims/at.js index adc7cd756..799238faf 100644 --- a/scripts/build/shims/at.js +++ b/scripts/build/shims/at.js @@ -10,9 +10,14 @@ const at = (isOptionalObject, object, index) => { return; } - return object.at - ? object.at(index) - : object[index < 0 ? object.length + index : index]; + // "relative indexing" is not available in Node.js v14 + // `.at` method is slower than property access on Node.js v16 and v18, see #14396 + // Only checked arrays and strings, since we haven't use `TypedArray`, and the transform only works for sources + if (Array.isArray(object) || typeof object === "string") { + return object[index < 0 ? object.length + index : index]; + } + + return object.at(index); }; export default at; diff --git a/src/common/ast-path.js b/src/common/ast-path.js index f1b86697b..41f379d1a 100644 --- a/src/common/ast-path.js +++ b/src/common/ast-path.js @@ -16,8 +16,7 @@ class AstPath { /** @type {object} */ get node() { - // eslint-disable-next-line unicorn/prefer-at -- `Array#at` is slow on Node.js v16 and v18 - return this.stack[this.stack.length - 1]; + return this.stack.at(-1); } /** @type {object | null} */