Skip to content

Commit 590f735

Browse files
committed
fix(@ngtools/webpack): diagnose typescript warnings as warnings
Previously, we were reporting all diagnostics as errors. Now only Typescript errors will be reported as real errors to webpack. Messages and warnings will be warnings. Fixes #5623
1 parent ff891ea commit 590f735

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/@ngtools/webpack/src/plugin.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ export class AotPlugin implements Tapable {
361361

362362
const original = consumer.originalPositionFor({ line, column: character });
363363
return {
364-
line: original.line,
365-
character: original.column,
364+
line: typeof original.line == 'number' ? original.line : line,
365+
character: typeof original.column == 'number' ? original.column : character,
366366
fileName: original.source || fileName
367367
};
368368
} catch (e) {
@@ -390,19 +390,25 @@ export class AotPlugin implements Tapable {
390390
);
391391

392392
if (diagnostics.length > 0) {
393-
const message = diagnostics
394-
.map(diagnostic => {
395-
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
396-
397-
const sourceText = diagnostic.file.getFullText();
398-
let {line, character, fileName} = this._translateSourceMap(sourceText,
399-
diagnostic.file.fileName, position);
400-
401-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
402-
return `${fileName} (${line + 1},${character + 1}): ${message}`;
403-
})
404-
.join('\n');
405-
this._compilation.errors.push(message);
393+
diagnostics.forEach(diagnostic => {
394+
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
395+
396+
const sourceText = diagnostic.file.getFullText();
397+
let {line, character, fileName} = this._translateSourceMap(sourceText,
398+
diagnostic.file.fileName, position);
399+
400+
const messageText = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
401+
const message = `${fileName} (${line + 1},${character + 1}): ${messageText}`;
402+
403+
switch (diagnostic.category) {
404+
case ts.DiagnosticCategory.Error:
405+
this._compilation.errors.push(message);
406+
break;
407+
408+
default:
409+
this._compilation.warnings.push(message);
410+
}
411+
});
406412
}
407413
}
408414

0 commit comments

Comments
 (0)