Skip to content

Commit

Permalink
refactor(compiler-cli): rephrase an error message related to @defer
Browse files Browse the repository at this point in the history
… and local compilation

This commit updates the error message to cover cases when imported symbols have eager references inside of a file.
  • Loading branch information
AndrewKushnir committed Jan 18, 2024
1 parent e227275 commit 421630f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,12 @@ export class ComponentDecoratorHandler implements
for (const importDecl of nonRemovableImports) {
const diagnostic = makeDiagnostic(
ErrorCode.DEFERRED_DEPENDENCY_IMPORTED_EAGERLY, importDecl,
`This import contains symbols used in the \`@Component.deferredImports\` array ` +
`of the \`${node.name.getText()}\` component, but also some other symbols that ` +
`are not in any \`@Component.deferredImports\` array. This renders all these ` +
`This import contains symbols that are used both inside and outside of the ` +
`\`@Component.deferredImports\` fields in the file. This renders all these ` +
`defer imports useless as this import remains and its module is eagerly loaded. ` +
`To fix this, make sure that this import contains *only* symbols ` +
`that are used within \`@Component.deferredImports\` arrays.`);
`To fix this, make sure that all symbols from the import are *only* used within ` +
`\`@Component.deferredImports\` arrays and there are no other references to those ` +
`symbols present in this file.`);
diagnostics.push(diagnostic);
}
return {diagnostics};
Expand Down
8 changes: 3 additions & 5 deletions packages/compiler-cli/test/ngtsc/local_compilation_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1529,15 +1529,13 @@ runInEachFileSystem(() => {
// can not be removed.
expect(diags.length).toBe(2);

const components = ['AppCmpA', 'AppCmpB'];
for (let i = 0; i < components.length; i++) {
const component = components[i];
for (let i = 0; i < 2; i++) {
const {code, messageText} = diags[i];
expect(code).toBe(ngErrorCode(ErrorCode.DEFERRED_DEPENDENCY_IMPORTED_EAGERLY));
expect(messageText)
.toContain(
'This import contains symbols used in the `@Component.deferredImports` ' +
`array of the \`${component}\` component`);
'This import contains symbols that are used both inside and outside ' +
'of the `@Component.deferredImports` fields in the file.');
}
});
});
Expand Down

0 comments on commit 421630f

Please sign in to comment.