Skip to content

Commit

Permalink
Fix property-method to method implementationOf links
Browse files Browse the repository at this point in the history
Resolves #2233
  • Loading branch information
Gerrit0 committed Apr 15, 2023
1 parent 64d8f47 commit 882ceff
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
### Bug Fixes

- Validation will no longer be skipped for sub packages when running with `--entryPointStrategy packages`.
- Fixed issue where removing a reflection indirectly containing an object/function type would only partially remove the reflection, #2231.
- Increased padding between sections when one navigation column is displayed, #2225.
- Correct padding for navigation elements with a displayed icon, #2229.
- Fixed `source-order` sort strategy failing to compare reflections within a file.
- Added `enum-member-source-order` specialization of the `source-order` sort strategy which only compares enum members, #2237.
- Updated highlight colors for semantic links to meet WCAG AA contrast requirements, #2228.
- Type parameters are now highlighted consistently, #2230.
- Fixed semantic coloring in type and function signatures, #2227.
- Fixed issue where removing a reflection indirectly containing an object/function type would only partially remove the reflection, #2231.
- Fixed "Implementation of X.y" links if a mixture of methods and property-methods are used, #2233.
- Fix expansion of globs if a single entry point is provided, #2235.
- Fixed broken theme toggle if the page contained a member named "theme".

Expand Down
30 changes: 20 additions & 10 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,30 @@ export class ImplementsPlugin extends ConverterComponent {
project
);

if (
interfaceMember.kindOf(ReflectionKind.FunctionOrMethod) &&
interfaceMember.signatures &&
classMember.signatures
) {
for (const [clsSig, intSig] of zip(
classMember.signatures,
interfaceMember.signatures
)) {
const intSigs =
interfaceMember.signatures ||
interfaceMember.type?.visit({
reflection: (r) => r.declaration.signatures,
});

const clsSigs =
classMember.signatures ||
classMember.type?.visit({
reflection: (r) => r.declaration.signatures,
});

if (intSigs && clsSigs) {
for (const [clsSig, intSig] of zip(clsSigs, intSigs)) {
if (clsSig.implementationOf) {
const target = intSig.parent.kindOf(
ReflectionKind.FunctionOrMethod
)
? intSig
: intSig.parent.parent!;
clsSig.implementationOf =
ReferenceType.createResolvedReference(
clsSig.implementationOf.name,
intSig,
target,
project
);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/converter2/issues/gh2233.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface Int {
prop: () => string;
prop2: () => string;
method(): string;
method2(): string;
}

export class IntImpl implements Int {
prop = () => "";
prop2() {
return "";
}
method = () => "";
method2() {
return "";
}
}
29 changes: 29 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,33 @@ describe("Issue Tests", () => {
"```ts\nlet x = `str`\n```"
);
});

it("#2233", () => {
const project = convert();
const int = query(project, "Int");
const cls = query(project, "IntImpl");

for (const name of ["prop", "prop2", "method", "method2"]) {
const intFn = int.getChildByName(name) as DeclarationReflection;
const clsFn = cls.getChildByName(name) as DeclarationReflection;
equal(
clsFn.implementationOf?.reflection?.getFullName(),
intFn.getFullName(),
`${name} method not properly linked`
);

const intTarget = intFn.signatures?.[0] || intFn;
const clsSig =
clsFn.signatures?.[0] ||
clsFn.type?.visit({
reflection: (r) => r.declaration.signatures?.[0],
});

equal(
clsSig!.implementationOf?.reflection?.getFullName(),
intTarget!.getFullName(),
`${name} signature not properly linked`
);
}
});
});

0 comments on commit 882ceff

Please sign in to comment.