@@ -10,7 +10,6 @@ import {
10
10
DomElementSchemaRegistry ,
11
11
ParseSourceSpan ,
12
12
SchemaMetadata ,
13
- TmplAstElement ,
14
13
TmplAstHostElement ,
15
14
} from '@angular/compiler' ;
16
15
import ts from 'typescript' ;
@@ -43,16 +42,17 @@ export interface DomSchemaChecker {
43
42
/**
44
43
* Check a non-Angular element and record any diagnostics about it.
45
44
*
46
- * @param id the template ID, suitable for resolution with a `TcbSourceResolver`.
47
- * @param element the element node in question.
48
- * @param schemas any active schemas for the template, which might affect the validity of the
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
49
* element.
50
- * @param hostIsStandalone boolean indicating whether the element's host is a standalone
51
- * component.
50
+ * @param hostIsStandalone Indicates whether the element's host is a standalone component.
52
51
*/
53
52
checkElement (
54
- id : string ,
55
- element : TmplAstElement ,
53
+ id : TypeCheckId ,
54
+ tagName : string ,
55
+ sourceSpanForDiagnostics : ParseSourceSpan ,
56
56
schemas : SchemaMetadata [ ] ,
57
57
hostIsStandalone : boolean ,
58
58
) : void ;
@@ -61,7 +61,7 @@ export interface DomSchemaChecker {
61
61
* Check a property binding on an element and record any diagnostics about it.
62
62
*
63
63
* @param id the type check ID, suitable for resolution with a `TcbSourceResolver`.
64
- * @param element the element node in question .
64
+ * @param tagName tag name of the element .
65
65
* @param name the name of the property being checked.
66
66
* @param span the source span of the binding. This is redundant with `element.attributes` but is
67
67
* passed separately to avoid having to look up the particular property name.
@@ -70,7 +70,7 @@ export interface DomSchemaChecker {
70
70
*/
71
71
checkTemplateElementProperty (
72
72
id : string ,
73
- element : TmplAstElement ,
73
+ tagName : string ,
74
74
name : string ,
75
75
span : ParseSourceSpan ,
76
76
schemas : SchemaMetadata [ ] ,
@@ -110,14 +110,15 @@ export class RegistryDomSchemaChecker implements DomSchemaChecker {
110
110
111
111
checkElement (
112
112
id : TypeCheckId ,
113
- element : TmplAstElement ,
113
+ tagName : string ,
114
+ sourceSpanForDiagnostics : ParseSourceSpan ,
114
115
schemas : SchemaMetadata [ ] ,
115
116
hostIsStandalone : boolean ,
116
117
) : void {
117
118
// HTML elements inside an SVG `foreignObject` are declared in the `xhtml` namespace.
118
119
// We need to strip it before handing it over to the registry because all HTML tag names
119
120
// in the registry are without a namespace.
120
- const name = element . name . replace ( REMOVE_XHTML_REGEX , '' ) ;
121
+ const name = tagName . replace ( REMOVE_XHTML_REGEX , '' ) ;
121
122
122
123
if ( ! REGISTRY . hasElement ( name , schemas ) ) {
123
124
const mapping = this . resolver . getTemplateSourceMapping ( id ) ;
@@ -138,7 +139,7 @@ export class RegistryDomSchemaChecker implements DomSchemaChecker {
138
139
const diag = makeTemplateDiagnostic (
139
140
id ,
140
141
mapping ,
141
- element . startSourceSpan ,
142
+ sourceSpanForDiagnostics ,
142
143
ts . DiagnosticCategory . Error ,
143
144
ngErrorCode ( ErrorCode . SCHEMA_INVALID_ELEMENT ) ,
144
145
errorMsg ,
@@ -149,32 +150,32 @@ export class RegistryDomSchemaChecker implements DomSchemaChecker {
149
150
150
151
checkTemplateElementProperty (
151
152
id : TypeCheckId ,
152
- element : TmplAstElement ,
153
+ tagName : string ,
153
154
name : string ,
154
155
span : ParseSourceSpan ,
155
156
schemas : SchemaMetadata [ ] ,
156
157
hostIsStandalone : boolean ,
157
158
) : void {
158
- if ( ! REGISTRY . hasProperty ( element . name , name , schemas ) ) {
159
+ if ( ! REGISTRY . hasProperty ( tagName , name , schemas ) ) {
159
160
const mapping = this . resolver . getTemplateSourceMapping ( id ) ;
160
161
161
162
const decorator = hostIsStandalone ? '@Component' : '@NgModule' ;
162
163
const schemas = `'${ decorator } .schemas'` ;
163
- let errorMsg = `Can't bind to '${ name } ' since it isn't a known property of '${ element . name } '.` ;
164
- if ( element . name . startsWith ( 'ng-' ) ) {
164
+ let errorMsg = `Can't bind to '${ name } ' since it isn't a known property of '${ tagName } '.` ;
165
+ if ( tagName . startsWith ( 'ng-' ) ) {
165
166
errorMsg +=
166
167
`\n1. If '${ name } ' is an Angular directive, then add 'CommonModule' to the '${ decorator } .imports' of this component.` +
167
168
`\n2. To allow any property add 'NO_ERRORS_SCHEMA' to the ${ schemas } of this component.` ;
168
- } else if ( element . name . indexOf ( '-' ) > - 1 ) {
169
+ } else if ( tagName . indexOf ( '-' ) > - 1 ) {
169
170
errorMsg +=
170
171
`\n1. If '${
171
- element . name
172
+ tagName
172
173
} ' is an Angular component and it has '${ name } ' input, then verify that it is ${
173
174
hostIsStandalone
174
175
? "included in the '@Component.imports' of this component"
175
176
: 'part of this module'
176
177
} .` +
177
- `\n2. If '${ element . name } ' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${ schemas } of this component to suppress this message.` +
178
+ `\n2. If '${ tagName } ' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${ schemas } of this component to suppress this message.` +
178
179
`\n3. To allow any property add 'NO_ERRORS_SCHEMA' to the ${ schemas } of this component.` ;
179
180
}
180
181
0 commit comments