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
Conversation
As mentioned by Pawel, this could generally use more test coverage for the various diagnostics and types of standalone entities.
9e0bdbb
to
f054987
Compare
if (errors[0].relatedInformation !== undefined) { | ||
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n'); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)!; |
There was a problem hiding this comment.
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 !
.
const isStandalone = (dirMeta?.isStandalone || pipeMeta?.isStandalone)!; | |
const isStandalone = dirMeta?.isStandalone ?? pipeMeta!.isStandalone; |
There was a problem hiding this comment.
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.
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.
if (errors[0].relatedInformation !== undefined) { | ||
messageText += errors[0].relatedInformation.map(info => info.messageText).join('\n'); | ||
} |
There was a problem hiding this comment.
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).
This PR was merged into the repository by commit 2142ffd. |
…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
…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
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
Part 1 implemented the
standalone
flag in components/directives/pipes, andimports
for components. In this PR, NgModules gain support for importing standalone types.