@@ -15,91 +15,19 @@ import {
1515import ts from 'typescript' ;
1616
1717import { ErrorCode , ngErrorCode } from '../../diagnostics' ;
18- import { TemplateDiagnostic , TypeCheckId } from '../api' ;
18+ import { DomSchemaChecker , TemplateDiagnostic , TypeCheckId } from '../api' ;
1919import { makeTemplateDiagnostic } from '../diagnostics' ;
2020
2121import { TypeCheckSourceResolver } from './tcb_util' ;
2222
2323export const REGISTRY = new DomElementSchemaRegistry ( ) ;
2424const REMOVE_XHTML_REGEX = / ^ : x h t m l : / ;
2525
26- /**
27- * Checks every non-Angular element/property processed in a template and potentially produces
28- * `ts.Diagnostic`s related to improper usage.
29- *
30- * A `DomSchemaChecker`'s job is to check DOM nodes and their attributes written used in templates
31- * and produce `ts.Diagnostic`s if the nodes don't conform to the DOM specification. It acts as a
32- * collector for these diagnostics, and can be queried later to retrieve the list of any that have
33- * been generated.
34- */
35- export interface DomSchemaChecker {
36- /**
37- * Get the `ts.Diagnostic`s that have been generated via `checkElement` and `checkProperty` calls
38- * thus far.
39- */
40- readonly diagnostics : ReadonlyArray < TemplateDiagnostic > ;
41-
42- /**
43- * Check a non-Angular element and record any diagnostics about it.
44- *
45- * @param id Template ID, suitable for resolution with a `TcbSourceResolver`.
46- * @param tagName Tag name of the element in question
47- * @param sourceSpanForDiagnostics Span that should be used when reporting diagnostics.
48- * @param schemas Any active schemas for the template, which might affect the validity of the
49- * element.
50- * @param hostIsStandalone Indicates whether the element's host is a standalone component.
51- */
52- checkElement (
53- id : TypeCheckId ,
54- tagName : string ,
55- sourceSpanForDiagnostics : ParseSourceSpan ,
56- schemas : SchemaMetadata [ ] ,
57- hostIsStandalone : boolean ,
58- ) : void ;
59-
60- /**
61- * Check a property binding on an element and record any diagnostics about it.
62- *
63- * @param id the type check ID, suitable for resolution with a `TcbSourceResolver`.
64- * @param tagName tag name of the element.
65- * @param name the name of the property being checked.
66- * @param span the source span of the binding. This is redundant with `element.attributes` but is
67- * passed separately to avoid having to look up the particular property name.
68- * @param schemas any active schemas for the template, which might affect the validity of the
69- * property.
70- */
71- checkTemplateElementProperty (
72- id : string ,
73- tagName : string ,
74- name : string ,
75- span : ParseSourceSpan ,
76- schemas : SchemaMetadata [ ] ,
77- hostIsStandalone : boolean ,
78- ) : void ;
79-
80- /**
81- * Check a property binding on a host element and record any diagnostics about it.
82- * @param id the type check ID, suitable for resolution with a `TcbSourceResolver`.
83- * @param element the element node in question.
84- * @param name the name of the property being checked.
85- * @param span the source span of the binding.
86- * @param schemas any active schemas for the template, which might affect the validity of the
87- * property.
88- */
89- checkHostElementProperty (
90- id : string ,
91- element : TmplAstHostElement ,
92- name : string ,
93- span : ParseSourceSpan ,
94- schemas : SchemaMetadata [ ] ,
95- ) : void ;
96- }
97-
9826/**
9927 * Checks non-Angular elements and properties against the `DomElementSchemaRegistry`, a schema
10028 * maintained by the Angular team via extraction from a browser IDL.
10129 */
102- export class RegistryDomSchemaChecker implements DomSchemaChecker {
30+ export class RegistryDomSchemaChecker implements DomSchemaChecker < TemplateDiagnostic > {
10331 private _diagnostics : TemplateDiagnostic [ ] = [ ] ;
10432
10533 get diagnostics ( ) : ReadonlyArray < TemplateDiagnostic > {
0 commit comments