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
Contributor

@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.

@atscott atscott self-requested a review Feb 4, 2022
@pkozlowski-opensource pkozlowski-opensource self-requested a review Feb 4, 2022
@ngbot ngbot bot added this to the Backlog milestone Feb 4, 2022
@alxhub alxhub added target: major and removed comp: 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

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
@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 Mar 23, 2022
@alxhub alxhub marked this pull request as ready for review Mar 24, 2022
@alxhub alxhub dismissed atscott’s stale review Mar 24, 2022

Tests added!

if (errors[0].relatedInformation !== undefined) {
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n');
}
Copy link
Member

@JoostK JoostK Mar 24, 2022

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
Contributor Author

@alxhub alxhub Mar 28, 2022

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

@JoostK JoostK Mar 29, 2022

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

@JoostK JoostK Mar 24, 2022

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
Contributor Author

@alxhub alxhub Mar 28, 2022

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
alxhub added 4 commits Mar 28, 2022
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.
JoostK
JoostK approved these changes Mar 29, 2022
if (errors[0].relatedInformation !== undefined) {
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n');
}
Copy link
Member

@JoostK JoostK Mar 29, 2022

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

LGTM

@alxhub alxhub added target: minor action: merge and removed target: major labels Mar 29, 2022
@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented Mar 29, 2022

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

dylhunn added a commit that referenced this issue 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 added a commit that referenced this issue 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 added a commit that referenced this issue Mar 29, 2022
…sts (#44973)

This just helps organize the standalone tests a little bit.

PR Close #44973
dylhunn added a commit that referenced this issue 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 added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge comp: compiler target: minor
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants