Skip to content

feat(compiler): initial skeleton for API doc extraction#51682

Closed
jelbourn wants to merge 1 commit intoangular:mainfrom
jelbourn:api-gen
Closed

feat(compiler): initial skeleton for API doc extraction#51682
jelbourn wants to merge 1 commit intoangular:mainfrom
jelbourn:api-gen

Conversation

@jelbourn
Copy link
Copy Markdown
Contributor

@jelbourn jelbourn commented Sep 6, 2023

This commit adds a barebones skeleton for extracting information to be used for extracting info that can be used for API reference generation. Subsequent PRs will expand on this with increasingly real extraction. I started with @alxhub's #51615 and very slightly polished to get to this minimal commit.

@jelbourn jelbourn added area: compiler Issues related to `ngc`, Angular's template compiler target: minor This PR is targeted for the next minor release labels Sep 6, 2023
@jelbourn jelbourn requested a review from alxhub September 6, 2023 19:15
@ngbot ngbot bot added this to the Backlog milestone Sep 6, 2023
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Sep 6, 2023
@jelbourn jelbourn requested review from atscott and removed request for alxhub September 7, 2023 20:23
Comment on lines 670 to 677
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let entries: DocEntry[] = [];
for (const sourceFile of this.inputProgram.getSourceFiles()) {
// We don't want to generate docs for `.d.ts` files.
if (sourceFile.isDeclarationFile) continue;
entries = entries.concat(docsExtractor.extract(sourceFile));
}
return entries;
const entries: DocEntry[] = [];
for (const sourceFile of this.inputProgram.getSourceFiles()) {
// We don't want to generate docs for `.d.ts` files.
if (sourceFile.isDeclarationFile) continue;
entries.push(...docsExtractor.extract(sourceFile));
}
return entries;

I'm not sure if there's a specific style in the compiler code for concat vs push, but certainly push is used a lot more. I'm feeling like this should just be push instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had mentioned in one of Paul's comments; I used concat because my understanding was that it's usually faster than destructuring. Changed it, though, since I don't feel strongly enough and any given source file is unlikely to have more than a few stop-level statements anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: push instead of concat

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets changed in one of the follow-up PRs, so I'm going to leave it for this commit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: avoid !

since the guard is outside this function, it was a bit hard to tell that we knew this wasn't null or undefined. Maybe move the guard into this helper function and change the return to DocEntry|null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a temporary line for the skeleton that pulls the simplest thing to show we're pulling a bit of data; it gets completely replaced in the next commit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should getApiDocumentation be added to the api.Program interface?

Going a bit further (maybe another PR), I'm wondering if createProgram should just return NgtscProgram and we can remove the interface altogether. The documentation at the top of NgtscProgram indicates that the interface was used to maintain compatibility with tooling that relied on a View Engine interface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'm just focused on pulling all of the data we care about for docs. Once we're at the point where we want to hook this up, we can figure out what "real" API we actually want the compiler to expose.

This commit adds a barebones skeleton for extracting information to be used for extracting info that can be used for API reference generation. Subsequent PRs will expand on this with increasingly real extraction. I started with @alxhub's angular#51615 and very slightly polished to get to this minimal commit.
jelbourn added a commit to jelbourn/angular that referenced this pull request Sep 9, 2023
Based on top of angular#51682

This expands on the skeleton previously added to extract docs info for classes, including properties, methods, and method parameters. Type information and Angular-specific info (e.g. inputs) will come in future PRs.
jelbourn added a commit to jelbourn/angular that referenced this pull request Sep 15, 2023
Based on top of angular#51682

This expands on the skeleton previously added to extract docs info for classes, including properties, methods, and method parameters. Type information and Angular-specific info (e.g. inputs) will come in future PRs.
pkozlowski-opensource pushed a commit that referenced this pull request Sep 18, 2023
Based on top of #51682

This expands on the skeleton previously added to extract docs info for classes, including properties, methods, and method parameters. Type information and Angular-specific info (e.g. inputs) will come in future PRs.

PR Close #51733
@jelbourn
Copy link
Copy Markdown
Contributor Author

Changes merged in #51733

@jelbourn jelbourn closed this Sep 18, 2023
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: compiler Issues related to `ngc`, Angular's template compiler detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants