Skip to content

Commit 02919b7

Browse files
committed
Consider the merged symbol when documenting global symbols
Resolves #2774
1 parent 61d83f0 commit 02919b7

File tree

8 files changed

+74
-31
lines changed

8 files changed

+74
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ title: Changelog
8787
- Fixed handling of `@enum` if the type was declared before the variable, #2719.
8888
- Fixed empty top level modules page in packages mode, #2753.
8989
- TypeDoc can now link to type alias properties, #2524.
90+
- TypeDoc will now document the merged symbol type when considering globals
91+
declared inside `declare global`, #2774
9092
- Fixed an issue where properties were not properly marked optional in some
9193
cases. This primarily affected destructured parameters.
9294
- Added `yaml` to the highlight languages supported by default.
@@ -103,10 +105,6 @@ title: Changelog
103105
one package were incorrectly reported as unused when running with
104106
entryPointStrategy set to packages.
105107

106-
TODO:
107-
108-
- Figure out automation for beta releases
109-
110108
# Unreleased
111109

112110
## v0.26.11 (2024-11-01)

src/lib/converter/converter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ function getExports(
812812
exp.declarations?.some(
813813
(d) => d.getSourceFile() === node,
814814
),
815-
);
815+
)
816+
.map((s) => context.checker.getMergedSymbol(s));
816817
}
817818
}
818819
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace GH2774 {
2+
export interface Extensions {}
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace GH2774 {
2+
export interface Extensions {
3+
globalAugment: string;
4+
}
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export {};
2+
3+
declare global {
4+
namespace GH2774 {
5+
export interface Extensions {
6+
moduleAugment: string;
7+
}
8+
}
9+
}

src/test/converter2/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"checkJs": true,
66
"outDir": "dist",
77
"target": "ESNext",
8-
98
"noImplicitAny": false,
9+
// GH2774 test case needs global files
10+
"moduleDetection": "legacy",
1011

1112
"skipLibCheck": true
1213
},

src/test/issues.c2.test.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,51 @@ const base = getConverter2Base();
4242
const app = getConverter2App();
4343
const program = getConverter2Program();
4444

45-
function doConvert(entry: string) {
46-
const entryPoint = [
47-
join(base, `issues/${entry}.ts`),
48-
join(base, `issues/${entry}.d.ts`),
49-
join(base, `issues/${entry}.tsx`),
50-
join(base, `issues/${entry}.js`),
51-
join(base, "issues", entry, "index.ts"),
52-
join(base, "issues", entry, "index.js"),
53-
].find(existsSync);
54-
55-
ok(entryPoint, `No entry point found for ${entry}`);
56-
const sourceFile = program.getSourceFile(entryPoint);
57-
ok(sourceFile, `No source file found for ${entryPoint}`);
58-
59-
app.options.setValue("entryPoints", [entryPoint]);
45+
function doConvert(entries: string[]) {
46+
const entryPoints = entries
47+
.map((entry) =>
48+
[
49+
join(base, `issues/${entry}.ts`),
50+
join(base, `issues/${entry}.d.ts`),
51+
join(base, `issues/${entry}.tsx`),
52+
join(base, `issues/${entry}.js`),
53+
join(base, "issues", entry, "index.ts"),
54+
join(base, "issues", entry, "index.js"),
55+
join(base, "issues", entry),
56+
].find(existsSync),
57+
)
58+
.filter((x) => x !== undefined);
59+
60+
const files = entryPoints.map((e) => program.getSourceFile(e));
61+
for (const [index, file] of files.entries()) {
62+
ok(file, `No source file found for ${entryPoints[index]}`);
63+
}
64+
65+
app.options.setValue("entryPoints", entryPoints);
6066
clearCommentCache();
61-
return app.converter.convert([
62-
{
63-
displayName: entry,
64-
program,
65-
sourceFile,
66-
},
67-
]);
67+
return app.converter.convert(
68+
files.map((file, index) => {
69+
return {
70+
displayName: entries[index].replace(/\.[tj]sx?$/, ""),
71+
program,
72+
sourceFile: file!,
73+
};
74+
}),
75+
);
6876
}
6977

7078
describe("Issue Tests", () => {
7179
let logger: TestLogger;
72-
let convert: (name?: string) => ProjectReflection;
80+
let convert: (...entries: string[]) => ProjectReflection;
7381
let optionsSnap: { __optionSnapshot: never };
7482

7583
beforeEach(function () {
7684
app.logger = logger = new TestLogger();
7785
optionsSnap = app.options.snapshot();
7886
const issueNumber = this.currentTest?.title.match(/#(\d+)/)?.[1];
7987
ok(issueNumber, "Test name must contain an issue number.");
80-
convert = (name = `gh${issueNumber}`) => doConvert(name);
88+
convert = (...entries) =>
89+
doConvert(entries.length ? entries : [`gh${issueNumber}`]);
8190
});
8291

8392
afterEach(() => {
@@ -1885,4 +1894,18 @@ describe("Issue Tests", () => {
18851894
equal(getSigComment(project, "Callable", 0), "A");
18861895
equal(getSigComment(project, "Callable", 1), "B");
18871896
});
1897+
1898+
it("#2774 gets global symbols in a consistent manner", () => {
1899+
const project = convert(
1900+
"gh2774/gh2774.ts",
1901+
"gh2774/globalAugment.ts",
1902+
"gh2774/moduleAugment.ts",
1903+
);
1904+
1905+
const decl = query(project, "gh2774/gh2774.GH2774");
1906+
equal(
1907+
decl.children?.map((c) => c.name),
1908+
["Extensions"],
1909+
);
1910+
});
18881911
});

src/test/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export function query(
4545
refl = refl.getChildByName([parts[i]]) as SomeReflection | undefined;
4646
}
4747

48-
ok(refl instanceof DeclarationReflection, `Failed to find ${name}`);
48+
ok(
49+
refl instanceof DeclarationReflection,
50+
`Failed to find ${name}\n${project.toStringHierarchy()}`,
51+
);
4952
return refl;
5053
}
5154

0 commit comments

Comments
 (0)