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

Part 2 of Standalone Components #44973

Closed
wants to merge 6 commits into from
Closed

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Feb 4, 2022

Part 1 implemented the standalone flag in components/directives/pipes, and imports for components. In this PR, NgModules gain support for importing standalone types.

@dylhunn dylhunn added the area: compiler Issues related to `ngc`, Angular's template compiler label Feb 4, 2022
@ngbot ngbot bot added this to the Backlog milestone Feb 4, 2022
@alxhub alxhub added target: major This PR is targeted for the next major release and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Feb 4, 2022
@ngbot ngbot bot removed this from the Backlog milestone Feb 4, 2022
atscott
atscott previously requested changes Feb 7, 2022
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

As mentioned by Pawel, this could generally use more test coverage for the various diagnostics and types of standalone entities.

packages/compiler-cli/test/ngtsc/scope_spec.ts Outdated Show resolved Hide resolved
packages/compiler-cli/src/ngtsc/scope/src/util.ts Outdated Show resolved Hide resolved
packages/compiler-cli/src/ngtsc/scope/src/local.ts Outdated Show resolved Hide resolved
packages/compiler-cli/src/ngtsc/testing/src/utils.ts Outdated Show resolved Hide resolved
@alxhub alxhub added the area: compiler Issues related to `ngc`, Angular's template compiler label Feb 17, 2022
@ngbot ngbot bot added this to the Backlog milestone Feb 17, 2022
@alxhub alxhub force-pushed the ngtsc/sac/impl.2 branch 7 times, most recently from 9e0bdbb to f054987 Compare March 23, 2022 19:26
@alxhub alxhub marked this pull request as ready for review March 24, 2022 17:07
Comment on lines +5295 to +5297
if (errors[0].relatedInformation !== undefined) {
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n');
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it could use ts.flattenDiagnosticMessageText

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 don't think so, because relatedInformation is not the same as using a DiagnosticMessageChain for messageText. But I might be misunderstanding the TS APIs here?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you are correct. It could be used within the .map(info => ...) transform here to avoid an [object object] string in the case of a message chain, but we can adjust once we need it (since this is just testing code).

const dirMeta = this.fullReader.getDirectiveMetadata(decl);
const pipeMeta = this.fullReader.getPipeMetadata(decl);
if (dirMeta !== null || pipeMeta !== null) {
const isStandalone = (dirMeta?.isStandalone || pipeMeta?.isStandalone)!;
Copy link
Member

Choose a reason for hiding this comment

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

nit: a ?? would be slightly more appropriate here, also allowing to remove one ?. in favor of !.

Suggested change
const isStandalone = (dirMeta?.isStandalone || pipeMeta?.isStandalone)!;
const isStandalone = dirMeta?.isStandalone ?? pipeMeta!.isStandalone;

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 think this is too magical actually (both the original and the suggested) - I've changed it to be more explicit.

packages/compiler-cli/src/ngtsc/scope/src/util.ts Outdated Show resolved Hide resolved
packages/core/src/render3/definition.ts Outdated Show resolved Hide resolved
packages/core/src/render3/definition.ts Outdated Show resolved Hide resolved
packages/core/src/render3/definition.ts Outdated Show resolved Hide resolved
Before the `SemanticSymbol` system which now powers incremental compilation,
the compiler previously needed to track which NgModules contributed to the
scope of a component in order to recompile correctly if something changed.
This commit removes that legacy field (which had no consumers) as well as the
logic to populate it.
This commit improves the error messages generated by the compiler when NgModule
scope analysis finds structural issues within a compilation. In particular,
errors are now shown on a node within the metadata of the NgModule which
produced the error, as opposed to the node of the erroneous declaration/import/
export. For example, if an NgModule declares `declarations: [FooCmp]` and
`FooCmp` is not annotated as a directive, component, or pipe, the error is now
shown on the reference to `FooCmp` in the `declarations` array expression.
Previously, the error would have been shown on `FooCmp` itself, with a mention
in the error text of the NgModule name.

Additional error context in some cases has been moved to related information
attached to the diagnostic, which further improves the legibility of such
errors. Error text has also been adjusted to be more succinct, since more info
about the error is now delivered through context.
This commit moves the error for declaring a standalone directive/component/
pipe to the `LocalModuleScopeRegistry`. Previously the error was produced
by the `NgModuleHandler` directly.

Producing the error in the scope registry allows the scope to be marked as
poisoned when the error occurs, preventing spurious downstream errors from
surfacing.
This just helps organize the standalone tests a little bit.
This commit implements the next step of Angular's "standalone" functionality,
by allowing directives/components/pipes declared as `standalone` to be imported
into NgModules. Errors are raised when such a type is not standalone but is
included in an NgModule's imports.
This commit carries the `standalone` flag forward from a directive/pipe
into its generated directive/pipe definition, allowing the runtime to
recognize standalone entities.
Comment on lines +5295 to +5297
if (errors[0].relatedInformation !== undefined) {
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n');
}
Copy link
Member

Choose a reason for hiding this comment

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

Oh, you are correct. It could be used within the .map(info => ...) transform here to avoid an [object object] string in the case of a message chain, but we can adjust once we need it (since this is just testing code).

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

LGTM

@alxhub alxhub added target: minor This PR is targeted for the next minor release action: merge The PR is ready for merge by the caretaker and removed target: major This PR is targeted for the next major release labels Mar 29, 2022
@dylhunn
Copy link
Contributor

dylhunn commented Mar 29, 2022

This PR was merged into the repository by commit 2142ffd.

@dylhunn dylhunn closed this in f027bfb Mar 29, 2022
dylhunn pushed a commit that referenced this pull request Mar 29, 2022
…es (#44973)

This commit improves the error messages generated by the compiler when NgModule
scope analysis finds structural issues within a compilation. In particular,
errors are now shown on a node within the metadata of the NgModule which
produced the error, as opposed to the node of the erroneous declaration/import/
export. For example, if an NgModule declares `declarations: [FooCmp]` and
`FooCmp` is not annotated as a directive, component, or pipe, the error is now
shown on the reference to `FooCmp` in the `declarations` array expression.
Previously, the error would have been shown on `FooCmp` itself, with a mention
in the error text of the NgModule name.

Additional error context in some cases has been moved to related information
attached to the diagnostic, which further improves the legibility of such
errors. Error text has also been adjusted to be more succinct, since more info
about the error is now delivered through context.

PR Close #44973
dylhunn pushed a commit that referenced this pull request Mar 29, 2022
…44973)

This commit moves the error for declaring a standalone directive/component/
pipe to the `LocalModuleScopeRegistry`. Previously the error was produced
by the `NgModuleHandler` directly.

Producing the error in the scope registry allows the scope to be marked as
poisoned when the error occurs, preventing spurious downstream errors from
surfacing.

PR Close #44973
dylhunn pushed a commit that referenced this pull request Mar 29, 2022
…sts (#44973)

This just helps organize the standalone tests a little bit.

PR Close #44973
dylhunn pushed a commit that referenced this pull request Mar 29, 2022
…44973)

This commit implements the next step of Angular's "standalone" functionality,
by allowing directives/components/pipes declared as `standalone` to be imported
into NgModules. Errors are raised when such a type is not standalone but is
included in an NgModule's imports.

PR Close #44973
dylhunn pushed a commit that referenced this pull request Mar 29, 2022
This commit carries the `standalone` flag forward from a directive/pipe
into its generated directive/pipe definition, allowing the runtime to
recognize standalone entities.

PR Close #44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…ular#44973)

Before the `SemanticSymbol` system which now powers incremental compilation,
the compiler previously needed to track which NgModules contributed to the
scope of a component in order to recompile correctly if something changed.
This commit removes that legacy field (which had no consumers) as well as the
logic to populate it.

PR Close angular#44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…es (angular#44973)

This commit improves the error messages generated by the compiler when NgModule
scope analysis finds structural issues within a compilation. In particular,
errors are now shown on a node within the metadata of the NgModule which
produced the error, as opposed to the node of the erroneous declaration/import/
export. For example, if an NgModule declares `declarations: [FooCmp]` and
`FooCmp` is not annotated as a directive, component, or pipe, the error is now
shown on the reference to `FooCmp` in the `declarations` array expression.
Previously, the error would have been shown on `FooCmp` itself, with a mention
in the error text of the NgModule name.

Additional error context in some cases has been moved to related information
attached to the diagnostic, which further improves the legibility of such
errors. Error text has also been adjusted to be more succinct, since more info
about the error is now delivered through context.

PR Close angular#44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…ngular#44973)

This commit moves the error for declaring a standalone directive/component/
pipe to the `LocalModuleScopeRegistry`. Previously the error was produced
by the `NgModuleHandler` directly.

Producing the error in the scope registry allows the scope to be marked as
poisoned when the error occurs, preventing spurious downstream errors from
surfacing.

PR Close angular#44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…sts (angular#44973)

This just helps organize the standalone tests a little bit.

PR Close angular#44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…ngular#44973)

This commit implements the next step of Angular's "standalone" functionality,
by allowing directives/components/pipes declared as `standalone` to be imported
into NgModules. Errors are raised when such a type is not standalone but is
included in an NgModule's imports.

PR Close angular#44973
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…4973)

This commit carries the `standalone` flag forward from a directive/pipe
into its generated directive/pipe definition, allowing the runtime to
recognize standalone entities.

PR Close angular#44973
@angular-automatic-lock-bot
Copy link

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 Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants