Skip to content

Commit

Permalink
Fix #2135
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jan 2, 2023
1 parent 2d60647 commit 81ccecf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"--config",
"${workspaceFolder}/.config/mocha.fast.json",
"-g",
"1734"
"2135"
],
"internalConsoleOptions": "openOnSessionStart",
"name": "Debug Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
"type": "node"
},
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node",
"type": "node",
"sourceMaps": true
}
]
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Fixed an issue where signature comments were preferred over property comments for indirectly created function-properties, #2135.

## v0.23.23 (2022-12-18)

### Features
Expand Down
19 changes: 15 additions & 4 deletions src/lib/converter/factories/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ export function createSignature(
context.scope
);

// If we are creating signatures for a variable and the variable has a comment associated with it
// then we should prefer that variable's comment over any comment on the signature. The comment plugin
// If we are creating signatures for a variable or property and it has a comment associated with it
// then we should prefer that comment over any comment on the signature. The comment plugin
// will copy the comment down if this signature doesn't have one, so don't set one.
let parentReflection = context.scope;
if (
parentReflection.kindOf(ReflectionKind.TypeLiteral) &&
parentReflection.parent instanceof DeclarationReflection
) {
parentReflection = parentReflection.parent;
}

if (
declaration &&
(!context.scope.comment ||
!(context.scope.conversionFlags & ConversionFlags.VariableSource))
(!parentReflection.comment ||
!(
parentReflection.conversionFlags &
ConversionFlags.VariableOrPropertySource
))
) {
sigRef.comment = getSignatureComment(
declaration,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ function convertProperty(
symbol,
exportSymbol
);
reflection.conversionFlags |= ConversionFlags.VariableOrPropertySource;

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

reflection.type = context.converter.convertType(
context,
context.withScope(reflection),
(context.isConvertingTypeNode() ? parameterType : void 0) ??
context.checker.getTypeOfSymbol(symbol)
);
Expand Down Expand Up @@ -894,7 +895,7 @@ function convertVariableAsFunction(
exportSymbol
);
setModifiers(symbol, accessDeclaration, reflection);
reflection.conversionFlags |= ConversionFlags.VariableSource;
reflection.conversionFlags |= ConversionFlags.VariableOrPropertySource;
context.finalizeDeclarationReflection(reflection);

const reflectionContext = context.withScope(reflection);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/reflections/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface DeclarationHierarchy {
*/
export enum ConversionFlags {
None = 0,
VariableSource = 1,
VariableOrPropertySource = 1,
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter2/issues/gh2135.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Camera {
/** One */
static useCameraPermissions = createPermissionHook();
}

/** Two */
declare function createPermissionHook(): () => void;
11 changes: 11 additions & 0 deletions src/test/issueTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,4 +825,15 @@ export const issueTests: {
"Foo type comment"
);
},

gh2135(project) {
const hook = query(project, "Camera.useCameraPermissions");
equal(hook.type?.type, "reflection" as const);
equal(
Comment.combineDisplayParts(
hook.type.declaration.signatures![0].comment?.summary
),
"One"
);
},
};

0 comments on commit 81ccecf

Please sign in to comment.