@@ -262,6 +262,32 @@ namespace ts {
262262 return ! nodeIsMissing ( node ) ;
263263 }
264264
265+ /**
266+ * Determine if the given comment is a triple-slash
267+ *
268+ * @return true if the comment is a triple-slash comment else false
269+ */
270+ export function isRecognizedTripleSlashComment ( text : string , commentPos : number , commentEnd : number ) {
271+ // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text
272+ // so that we don't end up computing comment string and doing match for all // comments
273+ if ( text . charCodeAt ( commentPos + 1 ) === CharacterCodes . slash &&
274+ commentPos + 2 < commentEnd &&
275+ text . charCodeAt ( commentPos + 2 ) === CharacterCodes . slash ) {
276+ const textSubStr = text . substring ( commentPos , commentEnd ) ;
277+ return textSubStr . match ( fullTripleSlashReferencePathRegEx ) ||
278+ textSubStr . match ( fullTripleSlashAMDReferencePathRegEx ) ||
279+ textSubStr . match ( fullTripleSlashReferenceTypeReferenceDirectiveRegEx ) ||
280+ textSubStr . match ( defaultLibReferenceRegEx ) ?
281+ true : false ;
282+ }
283+ return false ;
284+ }
285+
286+ export function isPinnedComment ( text : string , comment : CommentRange ) {
287+ return text . charCodeAt ( comment . pos + 1 ) === CharacterCodes . asterisk &&
288+ text . charCodeAt ( comment . pos + 2 ) === CharacterCodes . exclamation ;
289+ }
290+
265291 export function getTokenPosOfNode ( node : Node , sourceFile ?: SourceFileLike , includeJsDoc ?: boolean ) : number {
266292 // With nodes that have no width (i.e. 'Missing' nodes), we actually *don't*
267293 // want to skip trivia because this will launch us forward to the next token.
@@ -660,6 +686,7 @@ namespace ts {
660686 export let fullTripleSlashReferencePathRegEx = / ^ ( \/ \/ \/ \s * < r e f e r e n c e \s + p a t h \s * = \s * ) ( ' | " ) ( .+ ?) \2.* ?\/ > / ;
661687 export let fullTripleSlashReferenceTypeReferenceDirectiveRegEx = / ^ ( \/ \/ \/ \s * < r e f e r e n c e \s + t y p e s \s * = \s * ) ( ' | " ) ( .+ ?) \2.* ?\/ > / ;
662688 export let fullTripleSlashAMDReferencePathRegEx = / ^ ( \/ \/ \/ \s * < a m d - d e p e n d e n c y \s + p a t h \s * = \s * ) ( ' | " ) ( .+ ?) \2.* ?\/ > / ;
689+ export let defaultLibReferenceRegEx = / ^ ( \/ \/ \/ \s * < r e f e r e n c e \s + n o - d e f a u l t - l i b \s * = \s * ) ( ' | " ) ( .+ ?) \2\s * \/ > / ;
663690
664691 export function isPartOfTypeNode ( node : Node ) : boolean {
665692 if ( SyntaxKind . FirstTypeNode <= node . kind && node . kind <= SyntaxKind . LastTypeNode ) {
@@ -1846,7 +1873,7 @@ namespace ts {
18461873
18471874 export function getFileReferenceFromReferencePath ( comment : string , commentRange : CommentRange ) : ReferencePathMatchResult {
18481875 const simpleReferenceRegEx = / ^ \/ \/ \/ \s * < r e f e r e n c e \s + / gim;
1849- const isNoDefaultLibRegEx = / ^ ( \/ \/ \/ \s * < r e f e r e n c e \s + n o - d e f a u l t - l i b \s * = \s * ) ( ' | " ) ( . + ? ) \2 \s * \/ > / gim;
1876+ const isNoDefaultLibRegEx = new RegExp ( defaultLibReferenceRegEx . source , " gim" ) ;
18501877 if ( simpleReferenceRegEx . test ( comment ) ) {
18511878 if ( isNoDefaultLibRegEx . test ( comment ) ) {
18521879 return { isNoDefaultLib : true } ;
@@ -2823,7 +2850,7 @@ namespace ts {
28232850 //
28242851 // var x = 10;
28252852 if ( node . pos === 0 ) {
2826- leadingComments = filter ( getLeadingCommentRanges ( text , node . pos ) , isPinnedComment ) ;
2853+ leadingComments = filter ( getLeadingCommentRanges ( text , node . pos ) , isPinnedCommentLocal ) ;
28272854 }
28282855 }
28292856 else {
@@ -2869,9 +2896,8 @@ namespace ts {
28692896
28702897 return currentDetachedCommentInfo ;
28712898
2872- function isPinnedComment ( comment : CommentRange ) {
2873- return text . charCodeAt ( comment . pos + 1 ) === CharacterCodes . asterisk &&
2874- text . charCodeAt ( comment . pos + 2 ) === CharacterCodes . exclamation ;
2899+ function isPinnedCommentLocal ( comment : CommentRange ) {
2900+ return isPinnedComment ( text , comment ) ;
28752901 }
28762902
28772903 }
0 commit comments