Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compiler): Allow extraction for some private symbols, like $… #55340

Closed
wants to merge 1 commit into from

Conversation

JeanMeche
Copy link
Member

…localize

$localize is privately exported but defined globaly and is part of the public API.

fixes #54388

Copy link

github-actions bot commented Apr 14, 2024

Deployed adev-preview for 886fb27 to: https://ng-dev-previews-fw--pr-angular-angular-55340-adev-prev-kl3pc92p.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just a quick proposal to rename a const.

Comment on lines 26 to 28
const allowedPrivates = new Map([
[`ɵ$localize`, '$localize'], // exported as private but available as global
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd propose renaming this Map to indicate that we are not trying to expose private symbols, it's just a mechanism by which we exported some symbols as globals:

Suggested change
const allowedPrivates = new Map([
[`ɵ$localize`, '$localize'], // exported as private but available as global
]);
const exportedAsGlobals = new Map([
[`ɵ$localize`, '$localize'], // exported as private but available as global
]);

@@ -23,6 +23,9 @@ import {extractTypeAlias} from './type_alias_extractor';

type DeclarationWithExportName = readonly[string, ts.Declaration];

const allowedPrivates = new Map([
Copy link
Member

Choose a reason for hiding this comment

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

We have some precedent for global functions in core/global. Could we do something similar instead of special-casing $localize?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what I tried first, there must be a subtle difference which makes that the symbol isn't picked up.

Copy link
Member

Choose a reason for hiding this comment

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

@jelbourn might know more about it since he was doing the docs extraction.

Copy link
Member Author

@JeanMeche JeanMeche Apr 15, 2024

Choose a reason for hiding this comment

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

fwiw, my issue is/was that TypeChecker.getExportsOfModule doesn't pick up any of the re-exported symbols on a target created similarly than core/global

Copy link
Member Author

@JeanMeche JeanMeche Apr 15, 2024

Choose a reason for hiding this comment

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

Repro here : #55345

Copy link
Member

Choose a reason for hiding this comment

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

@pkozlowski-opensource pkozlowski-opensource added the area: compiler Issues related to `ngc`, Angular's template compiler label Apr 15, 2024
@ngbot ngbot bot added this to the Backlog milestone Apr 15, 2024
…localize

$localize is privately exported but defined globaly and is part of the public API.

fixes angular#54388
@@ -23,6 +23,9 @@ import {extractTypeAlias} from './type_alias_extractor';

type DeclarationWithExportName = readonly[string, ts.Declaration];

const exportedAsGlobals = new Map([
[`ɵ$localize`, '$localize'], // exported as private but available as global
]);
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to clarify whether we want to hard-code this FW-repo specific logic into ngtsc/docs. My understanding is that the docs extraction can be a useful tool for other pipelines as well, in the future.

A more future-proof and also code-local solution would be adding special tag information to these exports. e.g. @forceApiGeneration

Copy link
Member Author

Choose a reason for hiding this comment

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

Or idealy, understand why #55345 doesn't work ?

Having forceApiGeneration would still require us to rename the symbol to remove the bared o.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that would also work. In either case, not a big fan of a map in ngtsc/docs. The JSDoc could also include the name that it should be renamed to. e.g. @forceApiGeneration $localize

Copy link
Member

Choose a reason for hiding this comment

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

It sounds like we should fix the root cause though

Copy link
Member

Choose a reason for hiding this comment

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

FWIW there are already framework-specific patterns hard-coded into the docs extraction (though not as far as hard-coding specific symbols). If we ever want to open it up to code outside the Angular team, it would be a whole project to deal with this. I do agree, though, that it's better to avoid hard-coding things if we have a reasonable, more general alternative.

Copy link
Member

Choose a reason for hiding this comment

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

Even aside from hard-coding specifics (while the current ones, as you said, are not symbol specific, except maybe Angular-ecosystem wide lifecycle hooks), keeping these "special behaviors" local to the exported declarations is cleaner and more obvious.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that if we can get #55345 to work, that would be better.

@JeanMeche JeanMeche closed this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adev: preview area: compiler Issues related to `ngc`, Angular's template compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[adev] Missing angular.dev docs page for $localize
6 participants