Skip to content

Commit cc146bc

Browse files
resources: use named groups in RegExp (#2840)
1 parent 6e8ca04 commit cc146bc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

resources/build-npm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ function buildPackageJSON() {
5959
delete packageJSON.engines_on_npm;
6060

6161
const { version } = packageJSON;
62-
const versionMatch = /^\d+\.\d+\.\d+-?(.*)?$/.exec(version);
62+
const versionMatch = /^\d+\.\d+\.\d+-?(?<preReleaseTag>.*)?$/.exec(version);
6363
if (!versionMatch) {
6464
throw new Error('Version does not match semver spec: ' + version);
6565
}
6666

67-
const [, preReleaseTag] = versionMatch;
67+
const { preReleaseTag } = versionMatch.groups;
6868

6969
if (preReleaseTag != null) {
7070
const [tag] = preReleaseTag.split('.');

resources/gen-changelog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') {
4747
process.exit(1);
4848
}
4949

50-
const repoURLMatch = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec(
50+
const repoURLMatch = /https:\/\/github.com\/(?<githubOrg>[^/]+)\/(?<githubRepo>[^/]+).git/.exec(
5151
packageJSON.repository.url,
5252
);
5353
if (repoURLMatch == null) {
5454
console.error('Cannot extract organization and repo name from repo URL!');
5555
process.exit(1);
5656
}
57-
const [, githubOrg, githubRepo] = repoURLMatch;
57+
const { githubOrg, githubRepo } = repoURLMatch.groups;
5858

5959
getChangeLog()
6060
.then((changelog) => process.stdout.write(changelog))
@@ -275,9 +275,9 @@ function commitsInfoToPRs(commits) {
275275
(pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
276276
);
277277
if (associatedPRs.length === 0) {
278-
const match = / \(#([0-9]+)\)$/m.exec(commit.message);
278+
const match = / \(#(?<prNumber>[0-9]+)\)$/m.exec(commit.message);
279279
if (match) {
280-
prs[parseInt(match[1], 10)] = true;
280+
prs[parseInt(match.groups.prNumber, 10)] = true;
281281
continue;
282282
}
283283
throw new Error(

0 commit comments

Comments
 (0)