@@ -20,6 +20,7 @@ import {
20
20
*/
21
21
export class TypescriptDocsParser {
22
22
private readonly atTokenPlaceholder = '__EscapedAtToken__' ;
23
+ private readonly commentBlockEndTokenPlaceholder = '__EscapedCommentBlockEndToken__'
23
24
24
25
/**
25
26
* Parses the TypeScript files given by the filePaths array and returns the
@@ -29,7 +30,7 @@ export class TypescriptDocsParser {
29
30
const sourceFiles = filePaths . map ( filePath => {
30
31
return ts . createSourceFile (
31
32
filePath ,
32
- this . replaceEscapedAtTokens ( fs . readFileSync ( filePath ) . toString ( ) ) ,
33
+ this . replaceEscapedTokens ( fs . readFileSync ( filePath ) . toString ( ) ) ,
33
34
ts . ScriptTarget . ES2015 ,
34
35
true ,
35
36
) ;
@@ -288,7 +289,7 @@ export class TypescriptDocsParser {
288
289
const memberInfo : MemberInfo = {
289
290
fullText,
290
291
name,
291
- description : this . restoreAtTokens ( description ) ,
292
+ description : this . restoreTokens ( description ) ,
292
293
type,
293
294
modifiers,
294
295
since,
@@ -383,7 +384,7 @@ export class TypescriptDocsParser {
383
384
description : comment => ( description += comment ) ,
384
385
example : comment => ( description += this . formatExampleCode ( comment ) ) ,
385
386
} ) ;
386
- return this . restoreAtTokens ( description ) ;
387
+ return this . restoreTokens ( description ) ;
387
388
}
388
389
389
390
/**
@@ -446,20 +447,23 @@ export class TypescriptDocsParser {
446
447
447
448
/**
448
449
* TypeScript from v3.5.1 interprets all '@' tokens in a tag comment as a new tag. This is a problem e.g.
449
- * when a plugin includes in it's description some text like "install the @vendure/some-plugin package". Here,
450
+ * when a plugin includes in its description some text like "install the @vendure/some-plugin package". Here,
450
451
* TypeScript will interpret "@vendure" as a JSDoc tag and remove it and all remaining text from the comment.
451
452
*
452
453
* The solution is to replace all escaped @ tokens ("\@") with a replacer string so that TypeScript treats them
453
454
* as regular comment text, and then once it has parsed the statement, we replace them with the "@" character.
455
+ *
456
+ * Similarly, '/*' is interpreted as end of a comment block. However, it can be useful to specify a globstar
457
+ * pattern in descriptions and therefore it is supported as long as the leading '/' is escaped ("\/").
454
458
*/
455
- private replaceEscapedAtTokens ( content : string ) : string {
456
- return content . replace ( / \\ @ / g, this . atTokenPlaceholder ) ;
459
+ private replaceEscapedTokens ( content : string ) : string {
460
+ return content . replace ( / \\ @ / g, this . atTokenPlaceholder ) . replace ( / \\ \/ \* / g , this . commentBlockEndTokenPlaceholder ) ;
457
461
}
458
462
459
463
/**
460
- * Restores "@" tokens which were replaced by the replaceEscapedAtTokens () method.
464
+ * Restores "@" and "/*" tokens which were replaced by the replaceEscapedTokens () method.
461
465
*/
462
- private restoreAtTokens ( content : string ) : string {
463
- return content . replace ( new RegExp ( this . atTokenPlaceholder , 'g' ) , '@' ) ;
466
+ private restoreTokens ( content : string ) : string {
467
+ return content . replace ( new RegExp ( this . atTokenPlaceholder , 'g' ) , '@' ) . replace ( new RegExp ( this . commentBlockEndTokenPlaceholder , 'g' ) , '/*' ) ;
464
468
}
465
469
}
0 commit comments