@@ -13,7 +13,7 @@ import {ErrorCode, makeDiagnostic, makeRelatedInformation, ngErrorCode} from '..
1313import { ClassDeclaration } from '../../reflection' ;
1414import { TemplateId } from '../api' ;
1515
16- import { makeTemplateDiagnostic , TemplateSourceResolver } from './diagnostics' ;
16+ import { makeTemplateDiagnostic , TemplateDiagnostic , TemplateSourceResolver } from './diagnostics' ;
1717
1818
1919
@@ -27,7 +27,7 @@ import {makeTemplateDiagnostic, TemplateSourceResolver} from './diagnostics';
2727 * recorder for later display.
2828 */
2929export interface OutOfBandDiagnosticRecorder {
30- readonly diagnostics : ReadonlyArray < ts . Diagnostic > ;
30+ readonly diagnostics : ReadonlyArray < TemplateDiagnostic > ;
3131
3232 /**
3333 * Reports a `#ref="target"` expression in the template for which a target directive could not be
@@ -63,17 +63,18 @@ export interface OutOfBandDiagnosticRecorder {
6363 duplicateTemplateVar (
6464 templateId : TemplateId , variable : TmplAstVariable , firstDecl : TmplAstVariable ) : void ;
6565
66- requiresInlineTcb ( node : ClassDeclaration ) : void ;
66+ requiresInlineTcb ( templateId : TemplateId , node : ClassDeclaration ) : void ;
6767
68- requiresInlineTypeConstructors ( node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void ;
68+ requiresInlineTypeConstructors (
69+ templateId : TemplateId , node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void ;
6970}
7071
7172export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecorder {
72- private _diagnostics : ts . Diagnostic [ ] = [ ] ;
73+ private _diagnostics : TemplateDiagnostic [ ] = [ ] ;
7374
7475 constructor ( private resolver : TemplateSourceResolver ) { }
7576
76- get diagnostics ( ) : ReadonlyArray < ts . Diagnostic > {
77+ get diagnostics ( ) : ReadonlyArray < TemplateDiagnostic > {
7778 return this . _diagnostics ;
7879 }
7980
@@ -83,7 +84,7 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
8384
8485 const errorMsg = `No directive found with exportAs '${ value } '.` ;
8586 this . _diagnostics . push ( makeTemplateDiagnostic (
86- mapping , ref . valueSpan || ref . sourceSpan , ts . DiagnosticCategory . Error ,
87+ templateId , mapping , ref . valueSpan || ref . sourceSpan , ts . DiagnosticCategory . Error ,
8788 ngErrorCode ( ErrorCode . MISSING_REFERENCE_TARGET ) , errorMsg ) ) ;
8889 }
8990
@@ -97,8 +98,8 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
9798 `Assertion failure: no SourceLocation found for usage of pipe '${ ast . name } '.` ) ;
9899 }
99100 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 ) ) ;
102103 }
103104
104105 illegalAssignmentToTemplateVar (
@@ -113,7 +114,7 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
113114 throw new Error ( `Assertion failure: no SourceLocation found for property binding.` ) ;
114115 }
115116 this . _diagnostics . push ( makeTemplateDiagnostic (
116- mapping , sourceSpan , ts . DiagnosticCategory . Error ,
117+ templateId , mapping , sourceSpan , ts . DiagnosticCategory . Error ,
117118 ngErrorCode ( ErrorCode . WRITE_TO_READ_ONLY_VARIABLE ) , errorMsg , {
118119 text : `The variable ${ assignment . name } is declared here.` ,
119120 span : target . valueSpan || target . sourceSpan ,
@@ -132,20 +133,21 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
132133 //
133134 // TODO(alxhub): allocate to a tighter span once one is available.
134135 this . _diagnostics . push ( makeTemplateDiagnostic (
135- mapping , variable . sourceSpan , ts . DiagnosticCategory . Error ,
136+ templateId , mapping , variable . sourceSpan , ts . DiagnosticCategory . Error ,
136137 ngErrorCode ( ErrorCode . DUPLICATE_VARIABLE_DECLARATION ) , errorMsg , {
137138 text : `The variable '${ firstDecl . name } ' was first declared here.` ,
138139 span : firstDecl . sourceSpan ,
139140 } ) ) ;
140141 }
141142
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 ,
145146 `This component requires inline template type-checking, which is not supported by the current environment.` ) ) ;
146147 }
147148
148- requiresInlineTypeConstructors ( node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void {
149+ requiresInlineTypeConstructors (
150+ templateId : TemplateId , node : ClassDeclaration , directives : ClassDeclaration [ ] ) : void {
149151 let message : string ;
150152 if ( directives . length > 1 ) {
151153 message =
@@ -155,9 +157,20 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
155157 `This component uses a directive which requires an inline type constructor, which is not supported by the current environment.` ;
156158 }
157159
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 ,
160162 directives . map (
161163 dir => makeRelatedInformation ( dir . name , `Requires an inline type constructor.` ) ) ) ) ;
162164 }
163165}
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