Skip to content

Commit 344d4bf

Browse files
committed
Handle @include tags on entry point project
Resolves #2800
1 parent ed1ac7a commit 344d4bf

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ title: Changelog
44

55
## Unreleased
66

7+
### Features
8+
9+
- API: Introduced new `Converter.EVENT_CREATE_PROJECT` event which fires when a project is created by the converter, #2800.
10+
711
### Bug Fixes
812

913
- Switch from gzip to deflate for compressing assets to make output consistent across different operating systems, #2796.
14+
- `@include` and `@includeCode` now work for comments on the entry point for projects with a single entry point, #2800.
1015
- Cascaded modifier tags will no longer be copied into type literals, #2802.
1116

1217
## v0.27.3 (2024-12-04)

src/lib/converter/converter-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const ConverterEvents = {
22
BEGIN: "begin",
33
END: "end",
4+
CREATE_PROJECT: "createProject",
45
CREATE_DECLARATION: "createDeclaration",
56
CREATE_DOCUMENT: "createDocument",
67
CREATE_SIGNATURE: "createSignature",

src/lib/converter/converter.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { MergeModuleWithPlugin } from "./plugins/MergeModuleWithPlugin.js";
6767
export interface ConverterEvents {
6868
begin: [Context];
6969
end: [Context];
70+
createProject: [Context, ProjectReflection];
7071
createDeclaration: [Context, DeclarationReflection];
7172
createDocument: [undefined, DocumentReflection];
7273
createSignature: [
@@ -175,6 +176,13 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
175176
* Factory events
176177
*/
177178

179+
/**
180+
* Triggered when the converter has created a project reflection.
181+
* The listener will be given {@link Context} and a {@link Models.ProjectReflection}.
182+
* @event
183+
*/
184+
static readonly EVENT_CREATE_PROJECT = ConverterEvents.CREATE_PROJECT;
185+
178186
/**
179187
* Triggered when the converter has created a declaration reflection.
180188
* The listener will be given {@link Context} and a {@link Models.DeclarationReflection}.
@@ -459,6 +467,14 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
459467
: !!(context.scope as ProjectReflection).documents;
460468
}
461469

470+
if (createModuleReflections) {
471+
this.trigger(
472+
ConverterEvents.CREATE_PROJECT,
473+
context,
474+
context.project,
475+
);
476+
}
477+
462478
entries.forEach((e) => {
463479
context.setActiveProgram(e.entryPoint.program);
464480
e.context = this.convertExports(
@@ -499,6 +515,11 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
499515
? context.getComment(symbol, context.project.kind)
500516
: context.getFileComment(node);
501517
this.processDocumentTags(context.project, context.project);
518+
this.trigger(
519+
ConverterEvents.CREATE_PROJECT,
520+
context,
521+
context.project,
522+
);
502523
moduleContext = context;
503524
} else {
504525
const reflection = context.createDeclarationReflection(

src/lib/converter/plugins/IncludePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class IncludePlugin extends ConverterComponent {
1919
constructor(owner: Converter) {
2020
super(owner);
2121
const onCreate = this.onCreate.bind(this);
22+
owner.on(ConverterEvents.CREATE_PROJECT, onCreate);
2223
owner.on(ConverterEvents.CREATE_DOCUMENT, onCreate);
2324
owner.on(ConverterEvents.CREATE_DECLARATION, onCreate);
2425
owner.on(ConverterEvents.CREATE_PARAMETER, onCreate);

src/test/converter2/issues/gh2800.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Module docs
3+
* {@includeCode ./gh2800.ts}
4+
* @module
5+
*/
6+
export const bug = true;

src/test/issues.c2.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,20 @@ describe("Issue Tests", () => {
19431943
equal(type.type?.toString(), "any");
19441944
});
19451945

1946+
it("#2800 handles @include tags on project", () => {
1947+
const project = convert();
1948+
const includeTag = project.comment?.summary.find(
1949+
(t) => t.kind === "inline-tag",
1950+
);
1951+
equal(includeTag, undefined);
1952+
1953+
ok(
1954+
Comment.combineDisplayParts(project.comment?.summary).includes(
1955+
"const bug",
1956+
),
1957+
);
1958+
});
1959+
19461960
it("#2802 preserves @alpha tags on signature types", () => {
19471961
const project = convert();
19481962
const alpha1 = query(project, "AlphaOk");

0 commit comments

Comments
 (0)