Skip to content

Commit

Permalink
Add ponyfill for String.prototype.matchAll
Browse files Browse the repository at this point in the history
Fixes #38
  • Loading branch information
niklashigi committed Feb 3, 2021
1 parent 6aa25ce commit 46b683f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tasks/smali/parse-head.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import matchAll from '../../utils/match-all'

const CLASS_PATTERN = /\.class(?<keywords>.+)? L(?<name>[^\s]+);/
const IMPLEMENTS_PATTERN = /\.implements L(?<name>[^\s]+);/g

Expand Down Expand Up @@ -25,7 +27,7 @@ export default function parseSmaliHead(contents: string): SmaliHead {

return {
name,
implements: Array.from(contents.matchAll(IMPLEMENTS_PATTERN)).map(
implements: Array.from(matchAll(contents, IMPLEMENTS_PATTERN)).map(
match => match.groups!.name,
),
isInterface: keywords?.trim().split(' ').includes('interface') ?? false,
Expand Down
17 changes: 17 additions & 0 deletions src/utils/match-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* [Ponyfill](https://ponyfill.com/) for `String.prototype.matchAll`
* that can be removed once support for Node.js 10 is dropped.
*/
export default function matchAll(
input: string,
pattern: RegExp,
): RegExpMatchArray[] {
const matches = []

let currentMatch = null
while ((currentMatch = pattern.exec(input))) {
matches.push(currentMatch)
}

return matches
}

0 comments on commit 46b683f

Please sign in to comment.