Skip to content

Commit

Permalink
fix(compiler-cli): highlight the unresolved element in the @component.…
Browse files Browse the repository at this point in the history
…styles array for the error LOCAL_COMPILATION_UNRESOLVED_CONST (#54230)

Currently the whole array is highlighted.

PR Close #54230
  • Loading branch information
pmvald authored and thePunderWoman committed Feb 6, 2024
1 parent acc98a1 commit 6c8b094
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -500,7 +500,7 @@ export function parseDirectiveStyles(

throw new FatalDiagnosticError(
ErrorCode.LOCAL_COMPILATION_UNRESOLVED_CONST,
expression,
entry.node,
'Unresolved identifier found for @Component.styles field! Did you import this identifier from a file outside of the compilation unit? This is not allowed when Angular compiler runs in local mode. Possible solutions: 1) Move the declarations into a file within the compilation unit, 2) Inline the styles, 3) Move the styles into separate files and include it using @Component.styleUrls');
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/compiler-cli/test/ngtsc/local_compilation_spec.ts
Expand Up @@ -1228,8 +1228,10 @@ runInEachFileSystem(
import {Component} from '@angular/core';
import {ExternalString} from './some-where';
const InternalStyle = "p{color:blue}";
@Component({
styles: [ExternalString],
styles: [InternalStyle, ExternalString],
template: '',
})
Expand All @@ -1241,10 +1243,11 @@ runInEachFileSystem(

expect(errors.length).toBe(1);

const {code, messageText, relatedInformation} = errors[0];
const {code, messageText, relatedInformation, length} = errors[0];

expect(code).toBe(
ngErrorCode(ErrorCode.LOCAL_COMPILATION_UNRESOLVED_CONST));
expect(length).toBe(14),
expect(relatedInformation).toBeUndefined();

const text = ts.flattenDiagnosticMessageText(messageText, '\n');
Expand Down

0 comments on commit 6c8b094

Please sign in to comment.