Skip to content

Commit 5b59cfb

Browse files
authored
Merge pull request #33056 from amcasey/TripleSlashRestrictions
Make triple-slash comment classification more restrictive
2 parents ec39d41 + e3690c3 commit 5b59cfb

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/services/classifier.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ namespace ts {
771771
return false;
772772
}
773773

774+
// Limiting classification to exactly the elements and attributes
775+
// defined in `ts.commentPragmas` would be excessive, but we can avoid
776+
// some obvious false positives (e.g. in XML-like doc comments) by
777+
// checking the element name.
778+
if (!match[3] || !(match[3] in commentPragmas)) {
779+
return false;
780+
}
781+
774782
let pos = start;
775783

776784
pushCommentRange(pos, match[1].length); // ///
@@ -779,10 +787,6 @@ namespace ts {
779787
pushClassification(pos, match[2].length, ClassificationType.punctuation); // <
780788
pos += match[2].length;
781789

782-
if (!match[3]) {
783-
return true;
784-
}
785-
786790
pushClassification(pos, match[3].length, ClassificationType.jsxSelfClosingTagName); // element name
787791
pos += match[3].length;
788792

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// /// <summary>Text</summary>
4+
5+
var c = classification;
6+
verify.syntacticClassificationsAre(
7+
c.comment("/// <summary>Text</summary>"));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// /// <reference>Text</reference>
4+
5+
var c = classification;
6+
verify.syntacticClassificationsAre(
7+
c.comment("/// <reference>Text</reference>"));

tests/cases/fourslash/syntacticClassificationsTripleSlash4.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
var c = classification;
66
verify.syntacticClassificationsAre(
7-
c.comment("/// "),
8-
c.punctuation("<"));
7+
c.comment("/// <")); // Don't classify until we recognize the element name

0 commit comments

Comments
 (0)