@@ -93,7 +93,14 @@ export const loadTypeScriptDiagnostics = (tsDiagnostics: readonly Diagnostic[])
93
93
return diagnostics ;
94
94
} ;
95
95
96
- export const loadTypeScriptDiagnostic = ( tsDiagnostic : Diagnostic ) => {
96
+ /**
97
+ * Convert a TypeScript diagnostic object into our internal, Stencil-specific
98
+ * diagnostic format
99
+ *
100
+ * @param tsDiagnostic a TypeScript diagnostic message record
101
+ * @returns a Stencil diagnostic, suitable for showing an error to the user
102
+ */
103
+ export const loadTypeScriptDiagnostic = ( tsDiagnostic : Diagnostic ) : d . Diagnostic => {
97
104
const d : d . Diagnostic = {
98
105
level : 'warn' ,
99
106
type : 'typescript' ,
@@ -164,15 +171,27 @@ export const loadTypeScriptDiagnostic = (tsDiagnostic: Diagnostic) => {
164
171
return d ;
165
172
} ;
166
173
167
- const flattenDiagnosticMessageText = ( tsDiagnostic : Diagnostic , diag : string | DiagnosticMessageChain | undefined ) => {
174
+ /**
175
+ * Flatten a TypeScript diagnostic object into a string which can be easily
176
+ * included in a Stencil diagnostic record.
177
+ *
178
+ * @param tsDiagnostic a TypeScript diagnostic record
179
+ * @param diag a {@link DiagnosticMessageChain} or a string with further info
180
+ * @returns a string with the relevant error message
181
+ */
182
+ const flattenDiagnosticMessageText = (
183
+ tsDiagnostic : Diagnostic ,
184
+ diag : string | DiagnosticMessageChain | undefined
185
+ ) : string => {
168
186
if ( typeof diag === 'string' ) {
169
187
return diag ;
170
188
} else if ( diag === undefined ) {
171
189
return '' ;
172
190
}
173
191
174
192
const ignoreCodes : number [ ] = [ ] ;
175
- const isStencilConfig = tsDiagnostic . file . fileName . includes ( 'stencil.config' ) ;
193
+ // `tsDiagnostic.file` can be `undefined`, so we need to be a little careful here
194
+ const isStencilConfig = ( tsDiagnostic . file ?. fileName ?? '' ) . includes ( 'stencil.config' ) ;
176
195
if ( isStencilConfig ) {
177
196
ignoreCodes . push ( 2322 ) ;
178
197
}
0 commit comments