Skip to content

Commit

Permalink
Refactor for no-extra-lookaround-assertions (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Aug 15, 2023
1 parent 0aa9b8f commit 11ba3dc
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions lib/rules/no-extra-lookaround-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export default createRule("no-extra-lookaround-assertions", {
assertion: LookaroundAssertion,
) {
for (const alternative of assertion.alternatives) {
const nested = at(
alternative.elements,
const nested = alternative.elements.at(
assertion.kind === "lookahead"
? // The last positive lookahead assertion within
// a lookahead assertion is the same without the assertion.
Expand Down Expand Up @@ -99,19 +98,3 @@ export default createRule("no-extra-lookaround-assertions", {
})
},
})

// TODO After dropping support for Node < v16.6.0 we can use native `.at()`.
/**
* `.at()` polyfill
* see https://github.com/tc39/proposal-relative-indexing-method#polyfill
*/
function at<T>(array: T[], n: number) {
// ToInteger() abstract op
let num = Math.trunc(n) || 0
// Allow negative indexing from the end
if (num < 0) num += array.length
// OOB access is guaranteed to return undefined
if (num < 0 || num >= array.length) return undefined
// Otherwise, this is just normal property access
return array[num]
}

0 comments on commit 11ba3dc

Please sign in to comment.