@@ -13,7 +13,7 @@ import {ErrorCode, makeDiagnostic, makeRelatedInformation, ngErrorCode} from '..
13
13
import { ClassDeclaration } from '../../reflection' ;
14
14
import { TemplateId } from '../api' ;
15
15
16
- import { makeTemplateDiagnostic , TemplateSourceResolver } from './diagnostics' ;
16
+ import { makeTemplateDiagnostic , TemplateDiagnostic , TemplateSourceResolver } from './diagnostics' ;
17
17
18
18
19
19
@@ -27,7 +27,7 @@ import {makeTemplateDiagnostic, TemplateSourceResolver} from './diagnostics';
27
27
* recorder for later display.
28
28
*/
29
29
export interface OutOfBandDiagnosticRecorder {
30
- readonly diagnostics : ReadonlyArray < ts . Diagnostic > ;
30
+ readonly diagnostics : ReadonlyArray < TemplateDiagnostic > ;
31
31
32
32
/**
33
33
* Reports a `#ref="target"` expression in the template for which a target directive could not be
@@ -63,17 +63,18 @@ export interface OutOfBandDiagnosticRecorder {
63
63
duplicateTemplateVar (
64
64
templateId : TemplateId , variable : TmplAstVariable , firstDecl : TmplAstVariable ) : void ;
65
65
66
- requiresInlineTcb ( node : ClassDeclaration ) : void ;
66
+ requiresInlineTcb ( templateId : TemplateId , node : ClassDeclaration ) : void ;
67
67
68
- requiresInlineTypeConstructors ( node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void ;
68
+ requiresInlineTypeConstructors (
69
+ templateId : TemplateId , node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void ;
69
70
}
70
71
71
72
export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecorder {
72
- private _diagnostics : ts . Diagnostic [ ] = [ ] ;
73
+ private _diagnostics : TemplateDiagnostic [ ] = [ ] ;
73
74
74
75
constructor ( private resolver : TemplateSourceResolver ) { }
75
76
76
- get diagnostics ( ) : ReadonlyArray < ts . Diagnostic > {
77
+ get diagnostics ( ) : ReadonlyArray < TemplateDiagnostic > {
77
78
return this . _diagnostics ;
78
79
}
79
80
@@ -83,7 +84,7 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
83
84
84
85
const errorMsg = `No directive found with exportAs '${ value } '.` ;
85
86
this . _diagnostics . push ( makeTemplateDiagnostic (
86
- mapping , ref . valueSpan || ref . sourceSpan , ts . DiagnosticCategory . Error ,
87
+ templateId , mapping , ref . valueSpan || ref . sourceSpan , ts . DiagnosticCategory . Error ,
87
88
ngErrorCode ( ErrorCode . MISSING_REFERENCE_TARGET ) , errorMsg ) ) ;
88
89
}
89
90
@@ -97,8 +98,8 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
97
98
`Assertion failure: no SourceLocation found for usage of pipe '${ ast . name } '.` ) ;
98
99
}
99
100
this . _diagnostics . push ( makeTemplateDiagnostic (
100
- mapping , sourceSpan , ts . DiagnosticCategory . Error , ngErrorCode ( ErrorCode . MISSING_PIPE ) ,
101
- errorMsg ) ) ;
101
+ templateId , mapping , sourceSpan , ts . DiagnosticCategory . Error ,
102
+ ngErrorCode ( ErrorCode . MISSING_PIPE ) , errorMsg ) ) ;
102
103
}
103
104
104
105
illegalAssignmentToTemplateVar (
@@ -113,7 +114,7 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
113
114
throw new Error ( `Assertion failure: no SourceLocation found for property binding.` ) ;
114
115
}
115
116
this . _diagnostics . push ( makeTemplateDiagnostic (
116
- mapping , sourceSpan , ts . DiagnosticCategory . Error ,
117
+ templateId , mapping , sourceSpan , ts . DiagnosticCategory . Error ,
117
118
ngErrorCode ( ErrorCode . WRITE_TO_READ_ONLY_VARIABLE ) , errorMsg , {
118
119
text : `The variable ${ assignment . name } is declared here.` ,
119
120
span : target . valueSpan || target . sourceSpan ,
@@ -132,20 +133,21 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
132
133
//
133
134
// TODO(alxhub): allocate to a tighter span once one is available.
134
135
this . _diagnostics . push ( makeTemplateDiagnostic (
135
- mapping , variable . sourceSpan , ts . DiagnosticCategory . Error ,
136
+ templateId , mapping , variable . sourceSpan , ts . DiagnosticCategory . Error ,
136
137
ngErrorCode ( ErrorCode . DUPLICATE_VARIABLE_DECLARATION ) , errorMsg , {
137
138
text : `The variable '${ firstDecl . name } ' was first declared here.` ,
138
139
span : firstDecl . sourceSpan ,
139
140
} ) ) ;
140
141
}
141
142
142
- requiresInlineTcb ( node : ClassDeclaration ) : void {
143
- this . _diagnostics . push ( makeDiagnostic (
144
- ErrorCode . INLINE_TCB_REQUIRED , node . name ,
143
+ requiresInlineTcb ( templateId : TemplateId , node : ClassDeclaration ) : void {
144
+ this . _diagnostics . push ( makeInlineDiagnostic (
145
+ templateId , ErrorCode . INLINE_TCB_REQUIRED , node . name ,
145
146
`This component requires inline template type-checking, which is not supported by the current environment.` ) ) ;
146
147
}
147
148
148
- requiresInlineTypeConstructors ( node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void {
149
+ requiresInlineTypeConstructors (
150
+ templateId : TemplateId , node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void {
149
151
let message : string ;
150
152
if ( directives . length > 1 ) {
151
153
message =
@@ -155,9 +157,20 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
155
157
`This component uses a directive which requires an inline type constructor, which is not supported by the current environment.` ;
156
158
}
157
159
158
- this . _diagnostics . push ( makeDiagnostic (
159
- ErrorCode . INLINE_TYPE_CTOR_REQUIRED , node . name , message ,
160
+ this . _diagnostics . push ( makeInlineDiagnostic (
161
+ templateId , ErrorCode . INLINE_TYPE_CTOR_REQUIRED , node . name , message ,
160
162
directives . map (
161
163
dir => makeRelatedInformation ( dir . name , `Requires an inline type constructor.` ) ) ) ) ;
162
164
}
163
165
}
166
+
167
+ function makeInlineDiagnostic (
168
+ templateId : TemplateId , code : ErrorCode . INLINE_TCB_REQUIRED | ErrorCode . INLINE_TYPE_CTOR_REQUIRED ,
169
+ node : ts . Node , messageText : string | ts . DiagnosticMessageChain ,
170
+ relatedInformation ?: ts . DiagnosticRelatedInformation [ ] ) : TemplateDiagnostic {
171
+ return {
172
+ ...makeDiagnostic ( code , node , messageText , relatedInformation ) ,
173
+ componentFile : node . getSourceFile ( ) ,
174
+ templateId,
175
+ } ;
176
+ }
0 commit comments