Skip to content

Commit cb758a6

Browse files
committed
Introduce a new ExcerptKind.NonstandardText so that recognized JSDoc expressions don't get syntax highlighted in bright red
1 parent a1418be commit cb758a6

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

tsdoc/src/__tests__/__snapshots__/ParsingBasics.test.ts.snap

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ Object {
16531653
"nodeExcerpt": " ",
16541654
},
16551655
Object {
1656-
"kind": "Excerpt: ErrorText",
1656+
"kind": "Excerpt: NonstandardText",
16571657
"nodeExcerpt": "{type} ",
16581658
},
16591659
Object {
@@ -1719,7 +1719,7 @@ Object {
17191719
"nodeExcerpt": " ",
17201720
},
17211721
Object {
1722-
"kind": "Excerpt: ErrorText",
1722+
"kind": "Excerpt: NonstandardText",
17231723
"nodeExcerpt": "{{}} ",
17241724
},
17251725
Object {
@@ -1785,7 +1785,7 @@ Object {
17851785
"nodeExcerpt": " ",
17861786
},
17871787
Object {
1788-
"kind": "Excerpt: ErrorText",
1788+
"kind": "Excerpt: NonstandardText",
17891789
"nodeExcerpt": "{[q]{[q]} ",
17901790
},
17911791
Object {
@@ -1851,7 +1851,7 @@ Object {
18511851
"nodeExcerpt": " ",
18521852
},
18531853
Object {
1854-
"kind": "Excerpt: ErrorText",
1854+
"kind": "Excerpt: NonstandardText",
18551855
"nodeExcerpt": "{[q][b][q][q]} ",
18561856
},
18571857
Object {
@@ -1925,7 +1925,7 @@ Object {
19251925
"nodeExcerpt": " ",
19261926
},
19271927
Object {
1928-
"kind": "Excerpt: ErrorText",
1928+
"kind": "Excerpt: NonstandardText",
19291929
"nodeExcerpt": "{type} ",
19301930
},
19311931
Object {
@@ -1991,7 +1991,7 @@ Object {
19911991
"nodeExcerpt": " ",
19921992
},
19931993
Object {
1994-
"kind": "Excerpt: ErrorText",
1994+
"kind": "Excerpt: NonstandardText",
19951995
"nodeExcerpt": "{{}} ",
19961996
},
19971997
Object {
@@ -2057,7 +2057,7 @@ Object {
20572057
"nodeExcerpt": " ",
20582058
},
20592059
Object {
2060-
"kind": "Excerpt: ErrorText",
2060+
"kind": "Excerpt: NonstandardText",
20612061
"nodeExcerpt": "{[q]{[q]} ",
20622062
},
20632063
Object {
@@ -2131,7 +2131,7 @@ Object {
21312131
"nodeExcerpt": " ",
21322132
},
21332133
Object {
2134-
"kind": "Excerpt: ErrorText",
2134+
"kind": "Excerpt: NonstandardText",
21352135
"nodeExcerpt": "{type} ",
21362136
},
21372137
Object {
@@ -2197,7 +2197,7 @@ Object {
21972197
"nodeExcerpt": " ",
21982198
},
21992199
Object {
2200-
"kind": "Excerpt: ErrorText",
2200+
"kind": "Excerpt: NonstandardText",
22012201
"nodeExcerpt": "{{}} ",
22022202
},
22032203
Object {
@@ -2263,7 +2263,7 @@ Object {
22632263
"nodeExcerpt": " ",
22642264
},
22652265
Object {
2266-
"kind": "Excerpt: ErrorText",
2266+
"kind": "Excerpt: NonstandardText",
22672267
"nodeExcerpt": "{[q]{[q]} ",
22682268
},
22692269
Object {
@@ -2313,15 +2313,15 @@ Object {
23132313
"nodeExcerpt": " ",
23142314
},
23152315
Object {
2316-
"kind": "Excerpt: ErrorText",
2316+
"kind": "Excerpt: NonstandardText",
23172317
"nodeExcerpt": "[",
23182318
},
23192319
Object {
23202320
"kind": "Excerpt: ParamBlock_ParameterName",
23212321
"nodeExcerpt": "k",
23222322
},
23232323
Object {
2324-
"kind": "Excerpt: ErrorText",
2324+
"kind": "Excerpt: NonstandardText",
23252325
"nodeExcerpt": "]",
23262326
},
23272327
Object {
@@ -2383,15 +2383,15 @@ Object {
23832383
"nodeExcerpt": " ",
23842384
},
23852385
Object {
2386-
"kind": "Excerpt: ErrorText",
2386+
"kind": "Excerpt: NonstandardText",
23872387
"nodeExcerpt": "[",
23882388
},
23892389
Object {
23902390
"kind": "Excerpt: ParamBlock_ParameterName",
23912391
"nodeExcerpt": "l",
23922392
},
23932393
Object {
2394-
"kind": "Excerpt: ErrorText",
2394+
"kind": "Excerpt: NonstandardText",
23952395
"nodeExcerpt": "=]",
23962396
},
23972397
Object {
@@ -2453,15 +2453,15 @@ Object {
24532453
"nodeExcerpt": " ",
24542454
},
24552455
Object {
2456-
"kind": "Excerpt: ErrorText",
2456+
"kind": "Excerpt: NonstandardText",
24572457
"nodeExcerpt": "[",
24582458
},
24592459
Object {
24602460
"kind": "Excerpt: ParamBlock_ParameterName",
24612461
"nodeExcerpt": "m",
24622462
},
24632463
Object {
2464-
"kind": "Excerpt: ErrorText",
2464+
"kind": "Excerpt: NonstandardText",
24652465
"nodeExcerpt": "=[]]",
24662466
},
24672467
Object {
@@ -2523,15 +2523,15 @@ Object {
25232523
"nodeExcerpt": " ",
25242524
},
25252525
Object {
2526-
"kind": "Excerpt: ErrorText",
2526+
"kind": "Excerpt: NonstandardText",
25272527
"nodeExcerpt": "[",
25282528
},
25292529
Object {
25302530
"kind": "Excerpt: ParamBlock_ParameterName",
25312531
"nodeExcerpt": "n",
25322532
},
25332533
Object {
2534-
"kind": "Excerpt: ErrorText",
2534+
"kind": "Excerpt: NonstandardText",
25352535
"nodeExcerpt": "=[q][[q]]",
25362536
},
25372537
Object {
@@ -2593,15 +2593,15 @@ Object {
25932593
"nodeExcerpt": " ",
25942594
},
25952595
Object {
2596-
"kind": "Excerpt: ErrorText",
2596+
"kind": "Excerpt: NonstandardText",
25972597
"nodeExcerpt": "[",
25982598
},
25992599
Object {
26002600
"kind": "Excerpt: ParamBlock_ParameterName",
26012601
"nodeExcerpt": "o",
26022602
},
26032603
Object {
2604-
"kind": "Excerpt: ErrorText",
2604+
"kind": "Excerpt: NonstandardText",
26052605
"nodeExcerpt": "=[q][b][q][q]]",
26062606
},
26072607
Object {
@@ -2741,7 +2741,7 @@ Object {
27412741
"nodeExcerpt": " ",
27422742
},
27432743
Object {
2744-
"kind": "Excerpt: ErrorText",
2744+
"kind": "Excerpt: NonstandardText",
27452745
"nodeExcerpt": "[",
27462746
},
27472747
Object {

tsdoc/src/nodes/DocExcerpt.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ export const enum ExcerptKind {
2020
DeclarationReference_ImportPath = 'DeclarationReference_ImportPath',
2121
DeclarationReference_ImportHash = 'DeclarationReference_ImportHash',
2222

23+
/**
24+
* Input characters that were reported as an error and do not appear to be part of a valid expression.
25+
* A syntax highlighter might display them with an error color (e.g. red).
26+
*/
2327
ErrorText = 'ErrorText',
2428

29+
/**
30+
* Input characters that do not conform to the TSDoc specification, but were recognized by the parser, for example
31+
* as a known JSDoc pattern. A syntax highlighter should not display them with an error color (e.g. red)
32+
* because the error reporting may be suppressed for "lax" parsing of legacy source code.
33+
*/
34+
NonstandardText = 'NonstandardText',
35+
2536
EscapedText = 'EscapedText',
2637

2738
FencedCode_OpeningFence = 'FencedCode_OpeningFence',

tsdoc/src/nodes/DocParamBlock.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export class DocParamBlock extends DocBlock {
8080
if (parameters.unsupportedJsdocTypeBeforeParameterNameExcerpt) {
8181
this._unsupportedJsdocTypeBeforeParameterNameExcerpt = new DocExcerpt({
8282
configuration: this.configuration,
83-
excerptKind: ExcerptKind.ErrorText,
83+
excerptKind: ExcerptKind.NonstandardText,
8484
content: parameters.unsupportedJsdocTypeBeforeParameterNameExcerpt
8585
});
8686
}
8787

8888
if (parameters.unsupportedJsdocOptionalNameOpenBracketExcerpt) {
8989
this._unsupportedJsdocOptionalNameOpenBracketExcerpt = new DocExcerpt({
9090
configuration: this.configuration,
91-
excerptKind: ExcerptKind.ErrorText,
91+
excerptKind: ExcerptKind.NonstandardText,
9292
content: parameters.unsupportedJsdocOptionalNameOpenBracketExcerpt
9393
});
9494
}
@@ -102,7 +102,7 @@ export class DocParamBlock extends DocBlock {
102102
if (parameters.unsupportedJsdocOptionalNameRestExcerpt) {
103103
this._unsupportedJsdocOptionalNameRestExcerpt = new DocExcerpt({
104104
configuration: this.configuration,
105-
excerptKind: ExcerptKind.ErrorText,
105+
excerptKind: ExcerptKind.NonstandardText,
106106
content: parameters.unsupportedJsdocOptionalNameRestExcerpt
107107
});
108108
}
@@ -118,7 +118,7 @@ export class DocParamBlock extends DocBlock {
118118
if (parameters.unsupportedJsdocTypeAfterParameterNameExcerpt) {
119119
this._unsupportedJsdocTypeAfterParameterNameExcerpt = new DocExcerpt({
120120
configuration: this.configuration,
121-
excerptKind: ExcerptKind.ErrorText,
121+
excerptKind: ExcerptKind.NonstandardText,
122122
content: parameters.unsupportedJsdocTypeAfterParameterNameExcerpt
123123
});
124124
}
@@ -142,7 +142,7 @@ export class DocParamBlock extends DocBlock {
142142
if (parameters.unsupportedJsdocTypeAfterHyphenExcerpt) {
143143
this._unsupportedJsdocTypeAfterHyphenExcerpt = new DocExcerpt({
144144
configuration: this.configuration,
145-
excerptKind: ExcerptKind.ErrorText,
145+
excerptKind: ExcerptKind.NonstandardText,
146146
content: parameters.unsupportedJsdocTypeAfterHyphenExcerpt
147147
});
148148
}

0 commit comments

Comments
 (0)