Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8749,6 +8749,35 @@ suppress
expect(diags.length).toBe(0);
});

it('should not report a directive used on an ng-template inside an SVG as unused', () => {
env.write(
'test.ts',
`
import {Component, Directive, Input} from '@angular/core';

@Directive({selector: '[ngTemplateOutlet]'})
export class NgTemplateOutlet {
@Input() ngTemplateOutlet: unknown;
}

@Component({
template: \`
<ng-template #foo>foo</ng-template>

<svg>
<ng-template [ngTemplateOutlet]="foo"></ng-template>
</svg>
\`,
imports: [NgTemplateOutlet]
})
export class MyComp {}
`,
);

const diags = env.driveDiagnostics();
expect(diags.length).toBe(0);
});

it('should report when all imports in an import array are not used', () => {
env.write(
'test.ts',
Expand Down
7 changes: 5 additions & 2 deletions packages/compiler/src/render3/view/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {InputFlags} from '../../core';
import {BindingType} from '../../expression_parser/ast';
import {splitNsName} from '../../ml_parser/tags';
import {isNgTemplate, splitNsName} from '../../ml_parser/tags';
import * as o from '../../output/output_ast';
import {CssSelector} from '../../directive_matching';
import * as t from '../r3_ast';
Expand Down Expand Up @@ -201,7 +201,10 @@ export function createCssSelectorFromNode(node: t.Element | t.Template): CssSele
function getAttrsForDirectiveMatching(elOrTpl: t.Element | t.Template): {[name: string]: string} {
const attributesMap: {[name: string]: string} = {};

if (elOrTpl instanceof t.Template && elOrTpl.tagName !== 'ng-template') {
if (
elOrTpl instanceof t.Template &&
(elOrTpl.tagName === null || !isNgTemplate(elOrTpl.tagName))
) {
elOrTpl.templateAttrs.forEach((a) => (attributesMap[a.name] = ''));
} else {
elOrTpl.attributes.forEach((a) => {
Expand Down
Loading