Skip to content

Commit 81ccecf

Browse files
committed
Fix #2135
1 parent 2d60647 commit 81ccecf

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
"--config",
1212
"${workspaceFolder}/.config/mocha.fast.json",
1313
"-g",
14-
"1734"
14+
"2135"
1515
],
1616
"internalConsoleOptions": "openOnSessionStart",
1717
"name": "Debug Tests",
1818
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
1919
"request": "launch",
2020
"skipFiles": ["<node_internals>/**"],
21-
"type": "pwa-node"
21+
"type": "node"
2222
},
2323
{
2424
"name": "Attach",
2525
"port": 9229,
2626
"request": "attach",
2727
"skipFiles": ["<node_internals>/**"],
28-
"type": "pwa-node",
28+
"type": "node",
2929
"sourceMaps": true
3030
}
3131
]

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- Fixed an issue where signature comments were preferred over property comments for indirectly created function-properties, #2135.
6+
37
## v0.23.23 (2022-12-18)
48

59
### Features

src/lib/converter/factories/signature.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,24 @@ export function createSignature(
4343
context.scope
4444
);
4545

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
46+
// If we are creating signatures for a variable or property and it has a comment associated with it
47+
// then we should prefer that comment over any comment on the signature. The comment plugin
4848
// will copy the comment down if this signature doesn't have one, so don't set one.
49+
let parentReflection = context.scope;
50+
if (
51+
parentReflection.kindOf(ReflectionKind.TypeLiteral) &&
52+
parentReflection.parent instanceof DeclarationReflection
53+
) {
54+
parentReflection = parentReflection.parent;
55+
}
56+
4957
if (
5058
declaration &&
51-
(!context.scope.comment ||
52-
!(context.scope.conversionFlags & ConversionFlags.VariableSource))
59+
(!parentReflection.comment ||
60+
!(
61+
parentReflection.conversionFlags &
62+
ConversionFlags.VariableOrPropertySource
63+
))
5364
) {
5465
sigRef.comment = getSignatureComment(
5566
declaration,

src/lib/converter/symbols.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ function convertProperty(
623623
symbol,
624624
exportSymbol
625625
);
626+
reflection.conversionFlags |= ConversionFlags.VariableOrPropertySource;
626627

627628
const declaration = symbol.getDeclarations()?.[0];
628629
let parameterType: ts.TypeNode | undefined;
@@ -642,7 +643,7 @@ function convertProperty(
642643
reflection.defaultValue = declaration && convertDefaultValue(declaration);
643644

644645
reflection.type = context.converter.convertType(
645-
context,
646+
context.withScope(reflection),
646647
(context.isConvertingTypeNode() ? parameterType : void 0) ??
647648
context.checker.getTypeOfSymbol(symbol)
648649
);
@@ -894,7 +895,7 @@ function convertVariableAsFunction(
894895
exportSymbol
895896
);
896897
setModifiers(symbol, accessDeclaration, reflection);
897-
reflection.conversionFlags |= ConversionFlags.VariableSource;
898+
reflection.conversionFlags |= ConversionFlags.VariableOrPropertySource;
898899
context.finalizeDeclarationReflection(reflection);
899900

900901
const reflectionContext = context.withScope(reflection);

src/lib/models/reflections/declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface DeclarationHierarchy {
3434
*/
3535
export enum ConversionFlags {
3636
None = 0,
37-
VariableSource = 1,
37+
VariableOrPropertySource = 1,
3838
}
3939

4040
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class Camera {
2+
/** One */
3+
static useCameraPermissions = createPermissionHook();
4+
}
5+
6+
/** Two */
7+
declare function createPermissionHook(): () => void;

src/test/issueTests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,4 +825,15 @@ export const issueTests: {
825825
"Foo type comment"
826826
);
827827
},
828+
829+
gh2135(project) {
830+
const hook = query(project, "Camera.useCameraPermissions");
831+
equal(hook.type?.type, "reflection" as const);
832+
equal(
833+
Comment.combineDisplayParts(
834+
hook.type.declaration.signatures![0].comment?.summary
835+
),
836+
"One"
837+
);
838+
},
828839
};

0 commit comments

Comments
 (0)