@@ -35,6 +35,7 @@ var contains = require( '@stdlib/assert/contains' );
35
35
var replace = require ( '@stdlib/string/replace' ) ;
36
36
var endsWith = require ( '@stdlib/string/ends-with' ) ;
37
37
var trim = require ( '@stdlib/string/trim' ) ;
38
+ var escapeRegExpString = require ( '@stdlib/utils/escape-regexp-string' ) ;
38
39
var objectKeys = require ( '@stdlib/utils/keys' ) ;
39
40
var compareValues = require ( '@stdlib/_tools/doctest/compare-values' ) ;
40
41
var createAnnotationValue = require ( '@stdlib/_tools/doctest/create-annotation-value' ) ;
@@ -49,27 +50,15 @@ var debug = logger( 'tsdoc-doctest' );
49
50
var RE_TSDOC = / \/ \* \* [ \s \S ] + ?\* \/ / g;
50
51
var RE_EXAMPLE = / @ e x a m p l e \s * ( [ \s \S ] * ?) (? = \n \s * @ \w | \* \/ | $ ) / g;
51
52
var RE_NEWLINE = / \r ? \n / g;
52
- var RE_ANNOTATION = / (?: \n | ^ ) (?: v a r | l e t | c o n s t ) ? ? ( [ a - z A - Z 0 - 9 . _ ] + ) ? = [ ^ ; ] * ; \n \/ \/ ? ( r e t u r n s | ( [ A - Z a - z ] [ A - Z a - z _ 0 - 9 ] * ) ? ? = > | t h r o w s ) ? ( [ \s \S ] * ?) ( \n | $ ) / g;
53
+ var RE_ANNOTATION = / (?: \n | ^ ) (?: v a r | l e t | c o n s t ) ? ? ( [ a - z A - Z 0 - 9 . _ ] + ) ? = [ ^ ; ] * ; \n \/ \/ ? ( r e t u r n s | ( [ A - Z a - z ] [ A - Z a - z _ 0 - 9 ] * ) ? ? = > | t h r o w s ) ? ( [ \s \S ] * ?) (? = \n | $ ) / g;
53
54
var RE_COMMENT_PREFIX = / ^ \s * \* \s ? / gm;
54
- var RE_SPECIAL_CHARS = / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g;
55
55
var regexCache = { } ;
56
56
var lineCountCache = { } ;
57
57
var rule ;
58
58
59
59
60
60
// FUNCTIONS //
61
61
62
- /**
63
- * Escapes special regex characters in a string.
64
- *
65
- * @private
66
- * @param {string } str - string to escape
67
- * @returns {string } escaped string
68
- */
69
- function escapeRegex ( str ) {
70
- return replace ( str , RE_SPECIAL_CHARS , '\\$&' ) ;
71
- }
72
-
73
62
/**
74
63
* Gets or creates a cached regex for finding return annotations.
75
64
*
@@ -83,7 +72,7 @@ function getAnnotationRegex( annotationType, value ) {
83
72
var pattern ;
84
73
var key ;
85
74
86
- escapedValue = escapeRegex ( value ) ;
75
+ escapedValue = escapeRegExpString ( value ) ;
87
76
key = [ annotationType , escapedValue ] . join ( '::' ) ;
88
77
89
78
if ( ! regexCache [ key ] ) {
@@ -336,7 +325,7 @@ function processExampleCode( code, commentIdx, comments, scope, report, opts, so
336
325
337
326
// Find annotation part in the match (after "// "):
338
327
annotationStart = arr [ 0 ] . indexOf ( '// ' ) + 3 ;
339
- annotationEnd = arr [ 0 ] . length - arr [ 5 ] . length ;
328
+ annotationEnd = arr [ 0 ] . length ;
340
329
loc . range = [
341
330
commentStartIdx + codeIdx + annotationStart ,
342
331
commentStartIdx + codeIdx + annotationEnd
0 commit comments