Skip to content

Commit cd764a3

Browse files
crisbetoalxhub
authored andcommitted
fix(compiler-cli): error in unused standalone imports diagnostic (#59064)
Fixes a null pointer error in the unused standalone imports diagnostic. It was caused by an inconsistency in TypeScript's built-in types. Fixes #58872. PR Close #59064
1 parent ffae7df commit cd764a3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/compiler-cli/src/ngtsc/validation/src/rules/unused_standalone_imports_rule.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ export class UnusedStandaloneImportsRule implements SourceFileValidatorRule {
172172
if (ts.isVariableStatement(current)) {
173173
return !!current.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
174174
}
175-
current = current.parent;
175+
176+
// `Node.parent` can be undefined, but the TS types don't reflect it.
177+
// Coerce to null so the value is consitent with the type.
178+
current = current.parent ?? null;
176179
}
177180

178181
// Otherwise the reference likely comes from an imported

0 commit comments

Comments
 (0)