Skip to content

Commit 9749285

Browse files
committed
Switched to using super-regex for matching.
1 parent 1112b9a commit 9749285

File tree

3 files changed

+138
-8
lines changed

3 files changed

+138
-8
lines changed

package-lock.json

Lines changed: 121 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/doxdox-parser-custom/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
1010
},
1111
"dependencies": {
12-
"comment-parser": "1.3.1"
12+
"comment-parser": "1.3.1",
13+
"super-regex": "0.2.0"
1314
},
1415
"peerDependencies": {
1516
"doxdox-core": "4.0.0-preview.16"

packages/doxdox-parser-custom/src/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { File, Method, multiLinePatternMatch, slugify } from 'doxdox-core';
66

77
import { parse as commentParse } from 'comment-parser';
88

9+
import { firstMatch, matches } from 'super-regex';
10+
11+
const REGEX_TIMEOUT = 1000;
12+
913
const JSDOC_PATTERN = /[ \t]*\/\*\*\s*\n?([^*]*(\*[^/])?)*\*\//g;
1014

1115
const IDENTIFIER_PATTERNS = [
@@ -36,8 +40,9 @@ export const parseString = async (
3640
path: string,
3741
content: string
3842
): Promise<File> => {
39-
const comments =
40-
content.match(JSDOC_PATTERN) || ([] as unknown as string[]);
43+
const comments = Array.from(
44+
matches(JSDOC_PATTERN, content, { timeout: REGEX_TIMEOUT })
45+
).map(({ match }) => match);
4146

4247
const methods = comments.map(comment => ({
4348
rawComment: comment,
@@ -71,10 +76,14 @@ export const parseString = async (
7176
const [firstLine] = method.code.trim().split(/\r?\n/);
7277

7378
for (let i = 0; i < IDENTIFIER_PATTERNS.length; i += 1) {
74-
const matches = firstLine.trim().match(IDENTIFIER_PATTERNS[i]);
75-
76-
if (matches) {
77-
method.name = matches[1];
79+
const results = firstMatch(
80+
IDENTIFIER_PATTERNS[i],
81+
firstLine.trim(),
82+
{ timeout: REGEX_TIMEOUT }
83+
);
84+
85+
if (results) {
86+
method.name = results.groups[0];
7887

7988
break;
8089
}

0 commit comments

Comments
 (0)