Skip to content

feat(compiler): expand class api doc extraction#51685

Closed
jelbourn wants to merge 2 commits intoangular:mainfrom
jelbourn:more-api-gen
Closed

feat(compiler): expand class api doc extraction#51685
jelbourn wants to merge 2 commits intoangular:mainfrom
jelbourn:more-api-gen

Conversation

@jelbourn
Copy link
Copy Markdown
Contributor

@jelbourn jelbourn commented Sep 6, 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.

cc @devversion in case you're interested

@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 23:57
@ngbot ngbot bot modified the milestone: Backlog Sep 6, 2023
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Sep 6, 2023
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NIt: Could also use .push

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.

My understanding is that concat is faster than push with destructuring, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure that performance matters here, and I'm also not sure if this is true anymore.

Feel to just leave as is. This is a nit (but you used push in other places)

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.

Out of curiosity, is there a trusted source for the perf comparison? The best I could find myself was just running a benchmark https://www.measurethat.net/Benchmarks/Show/13985/0/concat-two-arrays-push-vs-destructuring

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One thing I'd like to start conversation on: In Dgeni our TypeScript extraction was ultimately only "documenting" symbols that were exported from the package entry-point. e.g. @angular/core/index.

Are we always analyzing everything, or should we rather traverse based on the entry-point and e.g. discover/extract referenced members?

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'm going to worry about filtering down the set of APIs we either extract or document later in the process; for now I'm focusing on extracting all of the information we need for docs. But yeah, it's reasonable to use an entry-point rather than all files in the program.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I know this is still TODO, but I think we could use the compiler type for ClassDeclaration, or maybe even the reflector. That way we wouldn't need the non-null assert. See TypeScriptReflectionHost.

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've already done this in a follow-up commit, so I'll leave it as-is for this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there really the concept of an optional member? seems like this information is not useful for documentation? and technically it just means that something can be undefined. This can also be expressed using an explicit type. e.g.

bla: string|undefined;

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That makes sense. Might be worth adding a comment for this. nly thinking about this in the context of "describing the member in a local sense".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the above checks, I'd recommend using ts.isMethodDeclaration etc to avoid the casts

Copy link
Copy Markdown
Contributor Author

@jelbourn jelbourn Sep 7, 2023

Choose a reason for hiding this comment

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

Oh, I meant to use my own utility method here and forgot to follow through, but also hadn't realized isMethodDeclaration and isPropertyDeclaration existed, so I've replaced them all with these.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just an early question based on our discussions: Do we plan on using the metadata from the existing ngtsc decorator handlers, or will we just have our own simpler extraction here that we co-maintain in @angular/compiler-cli?

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.

Yeah, this will reuse the existing metadata reader

Copy link
Copy Markdown
Contributor Author

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Comments addressed

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.

My understanding is that concat is faster than push with destructuring, no?

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.

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'm going to worry about filtering down the set of APIs we either extract or document later in the process; for now I'm focusing on extracting all of the information we need for docs. But yeah, it's reasonable to use an entry-point rather than all files in the program.

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've already done this in a follow-up commit, so I'll leave it as-is for this one.

Copy link
Copy Markdown
Contributor Author

@jelbourn jelbourn Sep 7, 2023

Choose a reason for hiding this comment

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

Oh, I meant to use my own utility method here and forgot to follow through, but also hadn't realized isMethodDeclaration and isPropertyDeclaration existed, so I've replaced them all with these.

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.

Yeah, this will reuse the existing metadata reader

Comment on lines 10 to 22
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.

Any reason for these to be string enums?

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.

They'll need to be serialized to json, and this makes them both stable and human-readable

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: I feel like the enums should be UpperCamelCase (though the internal TS style guide says CONSTANT_CASE)

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.

Ack, I'll change this in a follow-up commit since doing it here will be merge conflict city

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.
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 9, 2023
Based on top of angular#51685

This expands on the extraction with information for directives, including inputs and outputs. As part of this change, I've refactored the extraction code related to class and to directives into their own extractor classes to more cleanly separate extraction logic based on type of statement.
jelbourn added a commit to jelbourn/angular that referenced this pull request Sep 15, 2023
Based on top of angular#51685

This expands on the extraction with information for directives, including inputs and outputs. As part of this change, I've refactored the extraction code related to class and to directives into their own extractor classes to more cleanly separate extraction logic based on type of statement.
pkozlowski-opensource pushed a commit that referenced this pull request Sep 18, 2023
Based on top of #51685

This expands on the extraction with information for directives, including inputs and outputs. As part of this change, I've refactored the extraction code related to class and to directives into their own extractor classes to more cleanly separate extraction logic based on type of statement.

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.

3 participants