From e8812bc04e09addcec67d5d6a337145be79ca556 Mon Sep 17 00:00:00 2001 From: JoostK Date: Wed, 8 Dec 2021 19:45:59 +0100 Subject: [PATCH] refactor(compiler): cleanup unsafe usage of `null` value for ng-content selector (#44411) This commit improves the null-safety of the ng-content selector and updates a comment that turned out to be slightly inaccurate. Closes #38407 PR Close #44411 --- packages/compiler/src/render3/view/api.ts | 2 +- packages/compiler/src/template_parser/template_preparser.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/render3/view/api.ts b/packages/compiler/src/render3/view/api.ts index c12ec91acf2..5618e2e7455 100644 --- a/packages/compiler/src/render3/view/api.ts +++ b/packages/compiler/src/render3/view/api.ts @@ -177,7 +177,7 @@ export interface R3ComponentMetadata extends R3DirectiveMetadata { nodes: t.Node[]; /** - * Any ng-content selectors extracted from the template. Contains `null` when an ng-content + * Any ng-content selectors extracted from the template. Contains `*` when an ng-content * element without selector is present. */ ngContentSelectors: string[]; diff --git a/packages/compiler/src/template_parser/template_preparser.ts b/packages/compiler/src/template_parser/template_preparser.ts index 8e9f8696814..8f10d7b6366 100644 --- a/packages/compiler/src/template_parser/template_preparser.ts +++ b/packages/compiler/src/template_parser/template_preparser.ts @@ -20,7 +20,7 @@ const NG_NON_BINDABLE_ATTR = 'ngNonBindable'; const NG_PROJECT_AS = 'ngProjectAs'; export function preparseElement(ast: html.Element): PreparsedElement { - let selectAttr: string = null!; + let selectAttr: string|null = null; let hrefAttr: string = null!; let relAttr: string = null!; let nonBindable = false; @@ -71,7 +71,7 @@ export class PreparsedElement { } -function normalizeNgContentSelect(selectAttr: string): string { +function normalizeNgContentSelect(selectAttr: string|null): string { if (selectAttr === null || selectAttr.length === 0) { return '*'; }