File tree Expand file tree Collapse file tree 7 files changed +73
-3
lines changed Expand file tree Collapse file tree 7 files changed +73
-3
lines changed Original file line number Diff line number Diff line change 5
5
- TypeDoc will now treat ` @typedef {import("foo").Bar<Z>} Baz ` type declarations which forward type parameters to the imported
6
6
symbol as re-exports of that symbol, #2044 .
7
7
8
+ ### Bug Fixes
9
+
10
+ - TypeDoc will now prefer comments on variable declarations over signature comments, #2042 .
11
+
8
12
## v0.23.14 (2022-09-03)
9
13
10
14
### Features
Original file line number Diff line number Diff line change 1
1
import * as ts from "typescript" ;
2
2
import * as assert from "assert" ;
3
3
import {
4
+ ConversionFlags ,
4
5
DeclarationReflection ,
5
6
IntrinsicType ,
6
7
ParameterReflection ,
@@ -41,7 +42,15 @@ export function createSignature(
41
42
kind ,
42
43
context . scope
43
44
) ;
44
- if ( declaration ) {
45
+
46
+ // If we are creating signatures for a variable and the variable has a comment associated with it
47
+ // then we should prefer that variable's comment over any comment on the signature. The comment plugin
48
+ // will copy the comment down if this signature doesn't have one, so don't set one.
49
+ if (
50
+ declaration &&
51
+ ( ! context . scope . comment ||
52
+ ! ( context . scope . conversionFlags & ConversionFlags . VariableSource ) )
53
+ ) {
45
54
sigRef . comment = getSignatureComment (
46
55
declaration ,
47
56
context . converter . config ,
Original file line number Diff line number Diff line change 8
8
Reflection ,
9
9
ReflectionFlag ,
10
10
ReflectionKind ,
11
+ ConversionFlags ,
11
12
} from "../models" ;
12
13
import {
13
14
getEnumFlags ,
@@ -894,7 +895,7 @@ function convertVariableAsFunction(
894
895
exportSymbol
895
896
) ;
896
897
setModifiers ( symbol , accessDeclaration , reflection ) ;
897
-
898
+ reflection . conversionFlags |= ConversionFlags . VariableSource ;
898
899
context . finalizeDeclarationReflection ( reflection ) ;
899
900
900
901
const reflectionContext = context . withScope ( reflection ) ;
Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ export interface DeclarationHierarchy {
29
29
isTarget ?: boolean ;
30
30
}
31
31
32
+ /**
33
+ * @internal
34
+ */
35
+ export enum ConversionFlags {
36
+ None = 0 ,
37
+ VariableSource = 1 ,
38
+ }
39
+
32
40
/**
33
41
* A reflection that represents a single declaration emitted by the TypeScript compiler.
34
42
*
@@ -140,6 +148,12 @@ export class DeclarationReflection extends ContainerReflection {
140
148
*/
141
149
version ?: string ;
142
150
151
+ /**
152
+ * Flags for information about a reflection which is needed solely during conversion.
153
+ * @internal
154
+ */
155
+ conversionFlags = ConversionFlags . None ;
156
+
143
157
override hasGetterOrSetter ( ) : boolean {
144
158
return ! ! this . getSignature || ! ! this . setSignature ;
145
159
}
Original file line number Diff line number Diff line change 6
6
} from "./abstract" ;
7
7
export type { TraverseCallback } from "./abstract" ;
8
8
export { ContainerReflection } from "./container" ;
9
- export { DeclarationReflection } from "./declaration" ;
9
+ export { DeclarationReflection , ConversionFlags } from "./declaration" ;
10
10
export type { DeclarationHierarchy } from "./declaration" ;
11
11
export { ReflectionKind } from "./kind" ;
12
12
export { ParameterReflection } from "./parameter" ;
Original file line number Diff line number Diff line change
1
+ function factory ( ) {
2
+ /** inner docs */
3
+ function fn ( ) { }
4
+ return fn ;
5
+ }
6
+
7
+ export const built = factory ( ) ;
8
+
9
+ /** outer docs */
10
+ export const built2 = factory ( ) ;
11
+
12
+ const obj = {
13
+ /** inner docs */
14
+ fn ( x : unknown ) { } ,
15
+ } ;
16
+
17
+ export const fn = obj . fn ;
18
+
19
+ /**
20
+ * outer docs
21
+ * @param x param-docs
22
+ */
23
+ export const fn2 = obj . fn ;
Original file line number Diff line number Diff line change @@ -768,6 +768,25 @@ export const issueTests: {
768
768
equal ( AnotherCtor . type . declaration . signatures ?. length , 1 ) ;
769
769
} ,
770
770
771
+ gh2042 ( project ) {
772
+ for ( const [ name , docs ] of [
773
+ [ "built" , "inner docs" ] ,
774
+ [ "built2" , "outer docs" ] ,
775
+ [ "fn" , "inner docs" ] ,
776
+ [ "fn2" , "outer docs" ] ,
777
+ ] ) {
778
+ const refl = query ( project , name ) ;
779
+ ok ( refl . signatures ?. [ 0 ] ) ;
780
+ equal (
781
+ Comment . combineDisplayParts (
782
+ refl . signatures [ 0 ] . comment ?. summary
783
+ ) ,
784
+ docs ,
785
+ name
786
+ ) ;
787
+ }
788
+ } ,
789
+
771
790
gh2044 ( project ) {
772
791
for ( const [ name , ref ] of [
773
792
[ "Foo" , false ] ,
You can’t perform that action at this time.
0 commit comments