Skip to content

Commit 2d14373

Browse files
committed
Rewrote all regular expressions.
1 parent 1340835 commit 2d14373

File tree

2 files changed

+87
-50
lines changed

2 files changed

+87
-50
lines changed

packages/doxdox-parser-custom/src/__snapshots__/index.test.ts.snap

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ exports[`custom parser parse amd-module 1`] = `
106106
"returns": [],
107107
"slug": "test-mocks-amd-module-js-shirt",
108108
},
109-
{
110-
"description": "The class's \`size\` property.",
111-
"fullName": "size()",
112-
"name": "size",
113-
"params": [],
114-
"private": false,
115-
"returns": [],
116-
"slug": "test-mocks-amd-module-js-size",
117-
},
118109
{
119110
"description": "Size.",
120111
"fullName": "size()",
@@ -150,6 +141,15 @@ exports[`custom parser parse amd-module 1`] = `
150141
"returns": [],
151142
"slug": "test-mocks-amd-module-js-tag",
152143
},
144+
{
145+
"description": "The class's \`size\` property.",
146+
"fullName": "this.size()",
147+
"name": "this.size",
148+
"params": [],
149+
"private": false,
150+
"returns": [],
151+
"slug": "test-mocks-amd-module-js-this-size",
152+
},
153153
{
154154
"description": "Create a new Turtleneck.",
155155
"fullName": "Turtleneck(size)",
@@ -355,39 +355,31 @@ exports[`custom parser parse commonjs-module 1`] = `
355355
"slug": "test-mocks-commonjs-module-js-blend",
356356
},
357357
{
358-
"description": "Create a new Book.",
359-
"fullName": "Book(title)",
360-
"name": "Book",
361-
"params": [
362-
{
363-
"description": "- The title of the book.",
364-
"name": "title",
365-
"types": [
366-
"string",
367-
],
368-
},
369-
],
358+
"description": "Create a color mixer.",
359+
"fullName": "ColorMixer()",
360+
"name": "ColorMixer",
361+
"params": [],
370362
"private": false,
371363
"returns": [],
372-
"slug": "test-mocks-commonjs-module-js-book",
364+
"slug": "test-mocks-commonjs-module-js-colormixer",
373365
},
374366
{
375367
"description": "Button the shirt.",
376-
"fullName": "button()",
377-
"name": "button",
368+
"fullName": "exports.button()",
369+
"name": "exports.button",
378370
"params": [],
379371
"private": false,
380372
"returns": [],
381-
"slug": "test-mocks-commonjs-module-js-button",
373+
"slug": "test-mocks-commonjs-module-js-exports-button",
382374
},
383375
{
384-
"description": "Color mixer.",
385-
"fullName": "module.exports()",
386-
"name": "module.exports",
376+
"description": "Wash the shirt.",
377+
"fullName": "exports.wash()",
378+
"name": "exports.wash",
387379
"params": [],
388380
"private": false,
389381
"returns": [],
390-
"slug": "test-mocks-commonjs-module-js-module-exports",
382+
"slug": "test-mocks-commonjs-module-js-exports-wash",
391383
},
392384
{
393385
"description": "Color mixer.",
@@ -417,7 +409,7 @@ exports[`custom parser parse commonjs-module 1`] = `
417409
"slug": "test-mocks-commonjs-module-js-module-exports",
418410
},
419411
{
420-
"description": "Create a color mixer.",
412+
"description": "Color mixer.",
421413
"fullName": "module.exports()",
422414
"name": "module.exports",
423415
"params": [],
@@ -434,14 +426,31 @@ exports[`custom parser parse commonjs-module 1`] = `
434426
"returns": [],
435427
"slug": "test-mocks-commonjs-module-js-module-exports",
436428
},
429+
{
430+
"description": "Create a new Book.",
431+
"fullName": "this.Book(title)",
432+
"name": "this.Book",
433+
"params": [
434+
{
435+
"description": "- The title of the book.",
436+
"name": "title",
437+
"types": [
438+
"string",
439+
],
440+
},
441+
],
442+
"private": false,
443+
"returns": [],
444+
"slug": "test-mocks-commonjs-module-js-this-book",
445+
},
437446
{
438447
"description": "The title of the book.",
439-
"fullName": "title()",
440-
"name": "title",
448+
"fullName": "this.title()",
449+
"name": "this.title",
441450
"params": [],
442451
"private": false,
443452
"returns": [],
444-
"slug": "test-mocks-commonjs-module-js-title",
453+
"slug": "test-mocks-commonjs-module-js-this-title",
445454
},
446455
],
447456
"path": "./test/mocks/commonjs-module.js",
@@ -513,6 +522,15 @@ exports[`custom parser parse es2015-classes 1`] = `
513522
"returns": [],
514523
"slug": "test-mocks-es-classes-js-constructor",
515524
},
525+
{
526+
"description": "Class representing a dot.",
527+
"fullName": "Dot()",
528+
"name": "Dot",
529+
"params": [],
530+
"private": false,
531+
"returns": [],
532+
"slug": "test-mocks-es-classes-js-dot",
533+
},
516534
{
517535
"description": "Get the dot's width.",
518536
"fullName": "getWidth()",
@@ -582,15 +600,6 @@ exports[`custom parser parse es2015-classes 1`] = `
582600
"returns": [],
583601
"slug": "test-mocks-es-classes-js-point",
584602
},
585-
{
586-
"description": "Class representing a dot.",
587-
"fullName": "s()",
588-
"name": "s",
589-
"params": [],
590-
"private": false,
591-
"returns": [],
592-
"slug": "test-mocks-es-classes-js-s",
593-
},
594603
],
595604
"path": "./test/mocks/es2015-classes.js",
596605
}
@@ -756,6 +765,38 @@ exports[`custom parser parse example jsdoc headers (declaration methods) 1`] = `
756765
exports[`custom parser parse example jsdoc headers (function methods) 1`] = `
757766
{
758767
"methods": [
768+
{
769+
"description": "Finds file in path. console.log(await findFileInPath('./', 'package.json')); console.log(await findFileInPath('../', 'package.json')); console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));",
770+
"fullName": "findFileInPath(input, fileName)",
771+
"name": "findFileInPath",
772+
"params": [
773+
{
774+
"description": "Directory to check for file.",
775+
"name": "input",
776+
"types": [
777+
"string",
778+
],
779+
},
780+
{
781+
"description": "File name to check for.",
782+
"name": "fileName",
783+
"types": [
784+
"string",
785+
],
786+
},
787+
],
788+
"private": false,
789+
"returns": [
790+
{
791+
"description": "Path to package.json file.",
792+
"name": null,
793+
"types": [
794+
"Promise<string | null>",
795+
],
796+
},
797+
],
798+
"slug": "test-mocks-function-js-findfileinpath",
799+
},
759800
{
760801
"description": "Get the current working directory.",
761802
"fullName": "getCurrentWorkingDirectory()",

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ const REGEX_TIMEOUT = 1000;
1313
const JSDOC_PATTERN = /(^|[ \t]+)\/\*\*\s*\n?(?:[^*]*(?:\*[^/])?)*\*\//gms;
1414

1515
const IDENTIFIER_PATTERNS = [
16-
/^([a-z0-9_]+):/i,
17-
/^(?:static\s+)?([a-z0-9_]+)\s*\(/i,
18-
/^(?:export\s+)?(?:var|let|const)\s+([a-z0-9_]+)\s*=/i,
19-
/^(?:this|exports)\.([a-z0-9_]+)\s*=/i,
20-
/^(?:export\s+)?function\s+([a-z0-9_]+)\s*\(/i,
21-
/^class\s+([a-z0-9_]+)\s*{/i,
22-
/^((?:[a-z0-9_.]+)(\.prototype)?\.(?:[a-z0-9_]+))/i,
23-
/^[a-z0-9_]+\s*as\s*([a-z0-9_]+)/i
16+
/(?:class|function|var|let|const)[ ]+([a-z0-9_]+)[ ]*(?:[={(])?/i,
17+
/((?:[a-z0-9_.]+)(\.prototype)?\.(?:[a-z0-9_]+))/i,
18+
/[a-z0-9_]+[ ]*as[ ]*([a-z0-9_]+)/i,
19+
/([a-z0-9_]+)[ ]*[(:]/i
2420
];
2521

2622
const parser = async (cwd: string, path: string): Promise<File> => {

0 commit comments

Comments
 (0)